format & docs
[storage-units.git] / storage-units-jackson / src / test / java / wtf / metio / storageunits / jackson / PreferredUnitTypeTest.java
blobe9224004c62c25f7e02806839f37cddf4768d107
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.databind.JsonDeserializer;
8 import org.junit.jupiter.api.Assertions;
9 import org.junit.jupiter.api.Test;
10 import wtf.metio.storageunits.jackson.StorageUnitModule.PreferredUnitType;
12 import java.util.function.Supplier;
14 class PreferredUnitTypeTest {
16 @Test
17 void shouldSupportBinaryUnitsFromString() {
18 // given
19 final String type = "BINARY";
21 // when
22 final PreferredUnitType unitType = StorageUnitModule.PreferredUnitType.valueOf(type);
24 // then
25 Assertions.assertNotNull(unitType);
28 @Test
29 void shouldSupportBinaryUnits() {
30 // given
31 final PreferredUnitType type = StorageUnitModule.PreferredUnitType.BINARY;
33 // when
34 final Supplier<JsonDeserializer<?>> deserializer = type.deserializer;
36 // then
37 Assertions.assertNotNull(deserializer.get());
38 Assertions.assertTrue(BinaryStorageUnitDeserializer.class.isAssignableFrom(deserializer.get().getClass()));
41 @Test
42 void shouldSupportDecimalUnitsFromString() {
43 // given
44 final String type = "DECIMAL";
46 // when
47 final PreferredUnitType unitType = StorageUnitModule.PreferredUnitType.valueOf(type);
49 // then
50 Assertions.assertNotNull(unitType);
53 @Test
54 void shouldSupportDecimalUnits() {
55 // given
56 final PreferredUnitType type = StorageUnitModule.PreferredUnitType.DECIMAL;
58 // when
59 final Supplier<JsonDeserializer<?>> deserializer = type.deserializer;
61 // then
62 Assertions.assertNotNull(deserializer.get());
63 Assertions.assertTrue(DecimalStorageUnitDeserializer.class.isAssignableFrom(deserializer.get().getClass()));