2 * This file is part of storage-units. It is subject to the license terms in the LICENSE file found in the top-level
3 * directory of this distribution and at http://creativecommons.org/publicdomain/zero/1.0/. No part of storage-units,
4 * including this file, may be copied, modified, propagated, or distributed except according to the terms contained
7 package wtf
.metio
.storageunits
.eclipselink
;
9 import java
.math
.BigInteger
;
10 import java
.util
.stream
.Stream
;
11 import org
.eclipse
.persistence
.internal
.helper
.DatabaseField
;
12 import org
.eclipse
.persistence
.mappings
.DatabaseMapping
;
13 import org
.junit
.jupiter
.api
.Assertions
;
14 import org
.junit
.jupiter
.api
.DynamicTest
;
15 import org
.junit
.jupiter
.api
.TestFactory
;
16 import org
.mockito
.BDDMockito
;
17 import org
.mockito
.Mockito
;
18 import wtf
.metio
.storageunits
.model
.StorageUnits
;
20 class StorageUnitConverterTest
{
22 private Stream
<AbstractStorageUnitConverter
> converters() {
23 return Stream
.of(new BinaryStorageUnitConverter(), new DecimalStorageUnitConverter());
27 Stream
<DynamicTest
> shouldNotBeMutable() {
29 .map(converter
-> DynamicTest
.dynamicTest("should not be mutable",
30 () -> Assertions
.assertFalse(converter
.isMutable())));
34 Stream
<DynamicTest
> shouldConvertUnitToBigInteger() {
36 .map(converter
-> converter
.convertObjectValueToDataValue(StorageUnits
.kilobyte(1), null))
37 .map(dataValue
-> DynamicTest
.dynamicTest("should convert storage unit to big integer",
38 () -> Assertions
.assertEquals(BigInteger
.valueOf(1000L), dataValue
)));
42 Stream
<DynamicTest
> shouldConvertBigIntegerToUnit() {
44 .map(converter
-> converter
.convertDataValueToObjectValue(BigInteger
.valueOf(2000L), null))
45 .map(objectValue
-> DynamicTest
.dynamicTest("should convert big integer to storage unit",
46 () -> Assertions
.assertEquals(StorageUnits
.kilobyte(2), objectValue
)));
50 Stream
<DynamicTest
> shouldInitializeAsBigInt() {
52 .map(converter
-> DynamicTest
.dynamicTest("should initialize as big integer",
54 final var mapping
= Mockito
.mock(DatabaseMapping
.class);
55 final var field
= new DatabaseField();
56 BDDMockito
.given(mapping
.getField()).willReturn(field
);
58 converter
.initialize(mapping
, null);
60 Assertions
.assertEquals(java
.sql
.Types
.BIGINT
, field
.getSqlType());