fix #23
[storage-units.git] / src / test / java / de / xn__ho_hia / utils / storage_unit / StorageUnitsFormattingTest.java
blob34c100e9781d6c21bb8317bd6745f69e706b532f
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 org.eclipse.jdt.annotation.NonNull;
10 import org.junit.Assert;
11 import org.junit.Test;
13 import de.xn__ho_hia.quality.null_analysis.Nullsafe;
14 import de.xn__ho_hia.quality.suppression.CompilerWarnings;
16 /**
17 * Formatting test cases for the {@link StorageUnits} class.
19 @SuppressWarnings({ CompilerWarnings.NLS, CompilerWarnings.STATIC_METHOD })
20 public class StorageUnitsFormattingTest {
22 /**
23 * Tests the README example
25 @Test
26 public void shouldFormatReadmeExample() {
27 // given
28 final long numberOfBytes = 1_000_000_000_000_000L;
30 // when
31 final String formatted = StorageUnits.formatAsTerabyte(numberOfBytes, "#0.#####");
33 // then
34 Assert.assertEquals("1000 TB", formatted);
37 /**
38 * Tests formatting a {@link Long} formatted as Byte.
40 @Test
41 public void shouldFormatNumberAsBytes() {
42 // given
43 @NonNull
44 final Long numberOfBytes = Nullsafe.asLong(123456L);
46 // when
47 final String formatted = StorageUnits.formatAsByte(numberOfBytes);
49 // then
50 Assert.assertEquals("123456 B", formatted);
53 /**
54 * Tests formatting a primitive long formatted as Byte.
56 @Test
57 public void shouldFormatPrimitiveLongAsBytes() {
58 // given
59 final long numberOfBytes = 123456L;
61 // when
62 final String formatted = StorageUnits.formatAsByte(numberOfBytes);
64 // then
65 Assert.assertEquals("123456 B", formatted);