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 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
;
17 * Formatting test cases for the {@link StorageUnits} class.
19 @SuppressWarnings({ CompilerWarnings
.NLS
, CompilerWarnings
.STATIC_METHOD
})
20 public class StorageUnitsFormattingTest
{
23 * Tests the README example
26 public void shouldFormatReadmeExample() {
28 final long numberOfBytes
= 1_000_000_000_000_000L
;
31 final String formatted
= StorageUnits
.formatAsTerabyte(numberOfBytes
, "#0.#####");
34 Assert
.assertEquals("1000 TB", formatted
);
38 * Tests formatting a {@link Long} formatted as Byte.
41 public void shouldFormatNumberAsBytes() {
44 final Long numberOfBytes
= Nullsafe
.asLong(123456L);
47 final String formatted
= StorageUnits
.formatAsByte(numberOfBytes
);
50 Assert
.assertEquals("123456 B", formatted
);
54 * Tests formatting a primitive long formatted as Byte.
57 public void shouldFormatPrimitiveLongAsBytes() {
59 final long numberOfBytes
= 123456L;
62 final String formatted
= StorageUnits
.formatAsByte(numberOfBytes
);
65 Assert
.assertEquals("123456 B", formatted
);