update to latest parent & fix null issues
[storage-units.git] / src / test / java / de / xn__ho_hia / utils / storage_unit / StorageUnitsBigBinaryTest.java
bloba854f4913ee3f167b0ccb5c61beb3f464cf779be
1 /*
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
5 * in the LICENSE file.
6 */
7 package de.xn__ho_hia.utils.storage_unit;
9 import java.math.BigInteger;
11 import org.junit.Assert;
12 import org.junit.experimental.theories.DataPoints;
13 import org.junit.experimental.theories.Theories;
14 import org.junit.experimental.theories.Theory;
15 import org.junit.runner.RunWith;
17 import de.xn__ho_hia.quality.null_analysis.Nullsafe;
19 /**
23 @RunWith(Theories.class)
24 public class StorageUnitsBigBinaryTest {
26 private static final BigInteger MULTIPLIER = NullsafeMath.asBigInteger(1024);
28 /**
31 @DataPoints
32 public static Object[][] INPUT_RESULTS = {
33 { BigInteger.ONE, Kibibyte.class },
34 { MULTIPLIER, Kibibyte.class },
35 { MULTIPLIER.pow(2), Mebibyte.class },
36 { MULTIPLIER.pow(3), Gibibyte.class },
37 { MULTIPLIER.pow(4), Tebibyte.class },
38 { MULTIPLIER.pow(5), Pebibyte.class },
39 { MULTIPLIER.pow(6), Exbibyte.class },
40 { MULTIPLIER.pow(7), Zebibyte.class },
41 { MULTIPLIER.pow(8), Yobibyte.class },
42 { MULTIPLIER.pow(9), Yobibyte.class },
45 /**
46 * @param input
47 * The number of bytes to wrap + the expected return class.
49 @SuppressWarnings({ "nls", "static-method", "unchecked" })
50 @Theory
51 public void shouldCreateCorrectBinaryUnit(final Object[] input) {
52 // Given
53 final BigInteger bytes = (BigInteger) input[0];
54 final Class<? extends StorageUnit<?>> expectedClass = (Class<? extends StorageUnit<?>>) input[1];
56 // When
57 final StorageUnit<?> unit = StorageUnits.binaryValueOf(Nullsafe.nonNull(bytes));
59 // Then
60 Assert.assertEquals(
61 bytes + " should result in " + expectedClass.getSimpleName() + " but got "
62 + unit.getClass().getSimpleName(),
63 expectedClass, unit.getClass());