fix #23
[storage-units.git] / src / test / java / de / xn__ho_hia / utils / storage_unit / StorageUnitsSmallMetricTest.java
blob93e38d701d36676da6beb3d583b324b92acb5900
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 static de.xn__ho_hia.utils.storage_unit.TestUtils.logIncorrectCreation;
10 import static de.xn__ho_hia.utils.storage_unit.TestUtils.pow;
12 import java.util.ArrayList;
13 import java.util.List;
15 import org.jooq.lambda.tuple.Tuple2;
16 import org.junit.Assert;
17 import org.junit.experimental.theories.DataPoints;
18 import org.junit.experimental.theories.FromDataPoints;
19 import org.junit.experimental.theories.Theories;
20 import org.junit.experimental.theories.Theory;
21 import org.junit.runner.RunWith;
23 import de.xn__ho_hia.quality.suppression.CompilerWarnings;
25 /**
26 * Test cases for the {@link StorageUnits} class that check the behavior of small metric based units.
28 @RunWith(Theories.class)
29 public class StorageUnitsSmallMetricTest {
31 private static final Long MULTIPLIER = Long.valueOf(1000);
33 /**
34 * @return inputs and expected result types.
36 @DataPoints("inputs")
37 public static List<Tuple2<Long, Class<? extends StorageUnit<?>>>> inputs() {
38 final List<Tuple2<Long, Class<? extends StorageUnit<?>>>> inputs = new ArrayList<>();
40 inputs.add(new Tuple2<>(Long.valueOf(1L), Byte.class));
41 inputs.add(new Tuple2<>(MULTIPLIER, Kilobyte.class));
42 inputs.add(new Tuple2<>(pow(MULTIPLIER, 2), Megabyte.class));
43 inputs.add(new Tuple2<>(pow(MULTIPLIER, 3), Gigabyte.class));
44 inputs.add(new Tuple2<>(pow(MULTIPLIER, 4), Terabyte.class));
45 inputs.add(new Tuple2<>(pow(MULTIPLIER, 5), Petabyte.class));
46 inputs.add(new Tuple2<>(pow(MULTIPLIER, 6), Exabyte.class));
48 return inputs;
51 /**
52 * @param input
53 * The number of bytes to wrap + the expected return class.
55 @Theory
56 @SuppressWarnings(CompilerWarnings.STATIC_METHOD)
57 public void shouldCreateCorrectUnit(
58 @FromDataPoints("inputs") final Tuple2<Long, Class<? extends StorageUnit<?>>> input) {
59 // given
60 final long bytes = input.v1.longValue();
61 final Class<? extends StorageUnit<?>> expectedClass = input.v2;
63 // when
64 final StorageUnit<?> unit = StorageUnits.metricValueOf(bytes);
65 final Class<?> unitClass = unit.getClass();
67 // then
68 Assert.assertEquals(logIncorrectCreation(bytes, expectedClass, unitClass), expectedClass, unitClass);