2 * SPDX-FileCopyrightText: The Storage-Units Authors
3 * SPDX-License-Identifier: 0BSD
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
;
21 mapper
= new ObjectMapper();
22 mapper
.registerModule(new StorageUnitModule());
26 void shouldSerializeStorageUnit() throws JsonProcessingException
{
28 final StorageUnit
<?
> unit
= StorageUnits
.kibibyte(1L);
31 final String output
= mapper
.writeValueAsString(unit
);
34 Assertions
.assertEquals("1024", output
);
38 void shouldSerializeNonStorageUnit() throws JsonProcessingException
{
40 final String input
= "abc";
43 final String output
= mapper
.writeValueAsString(input
);
46 Assertions
.assertEquals("\"abc\"", output
);