From 12faed24973e7d1828a9b97ad2c9e291aa6cce14 Mon Sep 17 00:00:00 2001 From: Darren Royle Date: Mon, 5 Aug 2019 11:21:00 +0100 Subject: [PATCH] Additional tests for CovertKit * byte2FitMemoryString * memorySize2Byte * string2OutputStream These tests were written using Diffblue Cover. --- .../java/com/blade/kit/ConvertKitTest.java | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/src/test/java/com/blade/kit/ConvertKitTest.java b/src/test/java/com/blade/kit/ConvertKitTest.java index 43075c4eb..41a491e7d 100644 --- a/src/test/java/com/blade/kit/ConvertKitTest.java +++ b/src/test/java/com/blade/kit/ConvertKitTest.java @@ -6,6 +6,7 @@ import static junit.framework.TestCase.assertTrue; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; /** * @author biezhi @@ -74,6 +75,46 @@ public void byte2FitMemorySize() throws Exception { ); } + @Test + public void byte2FitMemoryStringLessThanZero() { + assertEquals( + "shouldn\'t be less than zero!", + ConvertKit.byte2FitMemoryString(-1024) + ); + } + + @Test + public void byte2FitMemoryStringGB() { + assertEquals( + "1 GB", + ConvertKit.byte2FitMemoryString(1024 * 1024 * 1024) + ); + } + + @Test + public void byte2FitMemoryStringMB() { + assertEquals( + "1 MB", + ConvertKit.byte2FitMemoryString(1024 * 1024) + ); + } + + @Test + public void byte2FitMemoryStringKB() { + assertEquals( + "1 KB", + ConvertKit.byte2FitMemoryString(1024) + ); + } + + @Test + public void byte2FitMemoryStringB() { + assertEquals( + "1 B", + ConvertKit.byte2FitMemoryString(1) + ); + } + @Test public void bytes2Bits_bits2Bytes() throws Exception { assertEquals( @@ -106,4 +147,34 @@ public void inputStream2String_string2InputStream() throws Exception { ); } + @Test + public void memorySize2ByteInputNegativeZeroOutputNegative() { + assertEquals( + -1L, + ConvertKit.memorySize2Byte(-9_223_372_036_854_775_807L, 0) + ); + } + + @Test + public void memorySize2ByteInputZeroOutputZero() { + assertEquals( + 0L, + ConvertKit.memorySize2Byte(0L, 0) + ); + } + + @Test + public void string2OutputStreamInputQuestionsReturnNull() { + assertNull( + ConvertKit.string2OutputStream("\u0000\u0000\u0000???????????????????", "") + ); + } + + @Test + public void string2OutputStreamInputUnicodeReturnNewline() { + assertNull( + ConvertKit.string2OutputStream("\u0000\u0000", "\n") + ); + } + }