test fixes

This commit is contained in:
eugenp
2016-11-03 12:47:43 +02:00
parent d0d62b53c2
commit 8628a63d95
3 changed files with 19 additions and 8 deletions

View File

@@ -1,10 +1,13 @@
package com.baeldung.hexToAscii;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
public class HexToAscii {
@Test
public static void whenHexToAscii() {
String asciiString = "http://www.baeldung.com/jackson-serialize-dates";
String hexEquivalent = "687474703a2f2f7777772e6261656c64756e672e636f6d2f6a61636b736f6e2d73657269616c697a652d6461746573";
@@ -13,15 +16,15 @@ public class HexToAscii {
@Test
public static void whenAsciiToHex() {
String asciiString = "http://www.baeldung.com/jackson-serialize-dates";
String hexEquivalent = "687474703a2f2f7777772e6261656c64756e672e636f6d2f6a61636b736f6e2d73657269616c697a652d6461746573";
assertEquals(hexEquivalent, asciiToHex(asciiString));
}
private static String asciiToHex(String asciiStr) {
//
private static String asciiToHex(String asciiStr) {
char[] chars = asciiStr.toCharArray();
StringBuilder hex = new StringBuilder();
for (char ch : chars) {
@@ -31,8 +34,7 @@ public class HexToAscii {
return hex.toString();
}
private static String hexToASCII(String hexStr) {
private static String hexToAscii(String hexStr) {
StringBuilder output = new StringBuilder("");
for (int i = 0; i < hexStr.length(); i += 2) {
String str = hexStr.substring(i, i + 2);
@@ -40,4 +42,5 @@ public class HexToAscii {
}
return output.toString();
}
}