From 7ed8a95a1c23142109a3f2cfcc95f34869aee01c Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Sat, 15 Dec 2018 13:38:40 +0000 Subject: [PATCH] test for the digest utility module --- .../net/ktnx/mobileledger/DigestUnitTest.java | 76 +++++++++++++++++++ .../ktnx/mobileledger/ExampleUnitTest.java | 34 --------- 2 files changed, 76 insertions(+), 34 deletions(-) create mode 100644 app/src/test/java/net/ktnx/mobileledger/DigestUnitTest.java delete mode 100644 app/src/test/java/net/ktnx/mobileledger/ExampleUnitTest.java diff --git a/app/src/test/java/net/ktnx/mobileledger/DigestUnitTest.java b/app/src/test/java/net/ktnx/mobileledger/DigestUnitTest.java new file mode 100644 index 00000000..4c0dc15f --- /dev/null +++ b/app/src/test/java/net/ktnx/mobileledger/DigestUnitTest.java @@ -0,0 +1,76 @@ +/* + * Copyright © 2018 Damyan Ivanov. + * This file is part of Mobile-Ledger. + * Mobile-Ledger is free software: you can distribute it and/or modify it + * under the term of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your opinion), any later version. + * + * Mobile-Ledger is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License terms for details. + * + * You should have received a copy of the GNU General Public License + * along with Mobile-Ledger. If not, see . + */ + +package net.ktnx.mobileledger; + +import net.ktnx.mobileledger.utils.Digest; + +import org.junit.Test; + +import static junit.framework.TestCase.assertEquals; + +/** + * Example local unit test, which will execute on the development machine (host). + * + * @see Testing documentation + */ +public class DigestUnitTest { + @Test + public void digestToHexString_isCorrect() { + assertEquals('0', Digest.hexDigitFor(0)); + assertEquals('1', Digest.hexDigitFor(1)); + assertEquals('2', Digest.hexDigitFor(2)); + assertEquals('3', Digest.hexDigitFor(3)); + assertEquals('4', Digest.hexDigitFor(4)); + assertEquals('5', Digest.hexDigitFor(5)); + assertEquals('6', Digest.hexDigitFor(6)); + assertEquals('7', Digest.hexDigitFor(7)); + assertEquals('8', Digest.hexDigitFor(8)); + assertEquals('9', Digest.hexDigitFor(9)); + assertEquals('a', Digest.hexDigitFor(10)); + assertEquals('b', Digest.hexDigitFor(11)); + assertEquals('c', Digest.hexDigitFor(12)); + assertEquals('d', Digest.hexDigitFor(13)); + assertEquals('e', Digest.hexDigitFor(14)); + assertEquals('f', Digest.hexDigitFor(15)); + } + @Test + public void hexDigitsFor_isCorrect() { + assertEquals("00", String.valueOf(Digest.hexDigitsFor(0))); + assertEquals("10", String.valueOf(Digest.hexDigitsFor(16))); + assertEquals("ff", String.valueOf(Digest.hexDigitsFor(255))); + assertEquals("a0", String.valueOf(Digest.hexDigitsFor(160))); + assertEquals("10", String.valueOf(Digest.hexDigitsFor((byte) 16))); + assertEquals("ff", String.valueOf(Digest.hexDigitsFor((byte) -1))); + } + @Test(expected = ArithmeticException.class) + public void digestToHexString_throwsOnNegative() { + Digest.hexDigitFor(-1); + } + @Test(expected = ArithmeticException.class) + public void digestToHexString_throwsOnGreaterThan15() { + Digest.hexDigitFor(16); + } + @Test(expected = ArithmeticException.class) + public void hexDigitsFor_throwsOnNegative() { + final char[] chars = Digest.hexDigitsFor(-5); + } + @Test(expected = ArithmeticException.class) + public void hexDigitsFor_throwsOnGreatherThan255() { + final char[] chars = Digest.hexDigitsFor(256); + } +} \ No newline at end of file diff --git a/app/src/test/java/net/ktnx/mobileledger/ExampleUnitTest.java b/app/src/test/java/net/ktnx/mobileledger/ExampleUnitTest.java deleted file mode 100644 index 2f133c04..00000000 --- a/app/src/test/java/net/ktnx/mobileledger/ExampleUnitTest.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright © 2018 Damyan Ivanov. - * This file is part of Mobile-Ledger. - * Mobile-Ledger is free software: you can distribute it and/or modify it - * under the term of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your opinion), any later version. - * - * Mobile-Ledger is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License terms for details. - * - * You should have received a copy of the GNU General Public License - * along with Mobile-Ledger. If not, see . - */ - -package net.ktnx.mobileledger; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -/** - * Example local unit test, which will execute on the development machine (host). - * - * @see Testing documentation - */ -public class ExampleUnitTest { - @Test - public void addition_isCorrect() { - assertEquals(4, 2 + 2); - } -} \ No newline at end of file -- 2.39.2