Improve code coverage for aaf cadi modules
[aaf/cadi.git] / core / src / test / java / org / onap / aaf / cadi / test / JU_Hash.java
index 92dd297..f79564d 100644 (file)
@@ -57,4 +57,59 @@ public class JU_Hash {
                }\r
        }\r
 \r
+       @Test\r
+       public void test1() throws CadiException {\r
+               String init = "m8234337@csp.att.com:kumquat8rie@#Tomatos3";\r
+               String hashed = Hash.toHex(init.getBytes());\r
+               System.out.println(hashed);\r
+               byte[] ba = Hash.fromHex(hashed);\r
+               String recon = new String(ba);\r
+               System.out.println(recon);\r
+               Assert.assertEquals(init, recon);\r
+               \r
+               init =hashed.substring(1);\r
+               try {\r
+                       hashed = Hash.fromHex(init).toString();\r
+                       Assert.fail("Should have thrown Exception");\r
+               } catch (CadiException e) {\r
+                       \r
+               }\r
+               \r
+               init = hashed.replace('1', '~');\r
+               try {\r
+                       hashed = Hash.fromHex(init).toString();\r
+                       Assert.fail("Should have thrown Exception");\r
+               } catch (CadiException e) {\r
+                       \r
+               }\r
+       }\r
+\r
+       \r
+       @Test\r
+       public void test2() throws CadiException {\r
+               String init = "m823475@csp.att.com:kumquat8rie@#Tomatos3";\r
+               String hashed = Hash.toHex(init.getBytes());\r
+               System.out.println(hashed);\r
+               byte[] ba = Hash.fromHex(hashed);\r
+               String recon = new String(ba);\r
+               System.out.println(recon);\r
+               Assert.assertEquals(init, recon);\r
+               \r
+               init =hashed.substring(1);\r
+               try {\r
+                       hashed = Hash.fromHex(init).toString();\r
+                       Assert.fail("Should have thrown Exception");\r
+               } catch (CadiException e) {\r
+                       \r
+               }\r
+               \r
+               init = hashed.replace('1', '~');\r
+               try {\r
+                       hashed = Hash.fromHex(init).toString();\r
+                       Assert.fail("Should have thrown Exception");\r
+               } catch (CadiException e) {\r
+                       \r
+               }\r
+       }\r
+\r
 }\r