format & docs
[storage-units.git] / storage-units-jackson / src / test / java / wtf / metio / storageunits / jackson / JacksonSerializationTest.java
blob72858b033c98bb3885382f0f0684d010c49ae881
1 /*
2 * SPDX-FileCopyrightText: The Storage-Units Authors
3 * SPDX-License-Identifier: 0BSD
4 */
5 package wtf.metio.storageunits.jackson;
7 import com.fasterxml.jackson.core.JsonProcessingException;
8 import com.fasterxml.jackson.databind.ObjectMapper;
9 import org.junit.jupiter.api.Assertions;
10 import org.junit.jupiter.api.BeforeEach;
11 import org.junit.jupiter.api.Test;
12 import wtf.metio.storageunits.model.StorageUnit;
13 import wtf.metio.storageunits.model.StorageUnits;
15 class JacksonSerializationTest {
17 private ObjectMapper mapper;
19 @BeforeEach
20 void setUp() {
21 mapper = new ObjectMapper();
22 mapper.registerModule(new StorageUnitModule());
25 @Test
26 void shouldSerializeStorageUnit() throws JsonProcessingException {
27 // given
28 final StorageUnit<?> unit = StorageUnits.kibibyte(1L);
30 // when
31 final String output = mapper.writeValueAsString(unit);
33 // then
34 Assertions.assertEquals("1024", output);
37 @Test
38 void shouldSerializeNonStorageUnit() throws JsonProcessingException {
39 // given
40 final String input = "abc";
42 // when
43 final String output = mapper.writeValueAsString(input);
45 // then
46 Assertions.assertEquals("\"abc\"", output);