This repository was archived by the owner on Jun 7, 2023. It is now read-only.
File tree 2 files changed +20
-6
lines changed
2 files changed +20
-6
lines changed Original file line number Diff line number Diff line change 1
1
package jota .utils ;
2
2
3
+ import jota .error .ArgumentException ;
4
+
3
5
/**
4
6
* This class allows to convert between ASCII and tryte encoded strings.
5
7
*
@@ -67,12 +69,13 @@ public static String asciiToTrytes(String inputString) {
67
69
* 2 Trytes == 1 Byte
68
70
* @param inputTrytes the trytes we want to convert
69
71
* @return an ASCII string or null when the inputTrytes are uneven
72
+ * @throws ArgumentException When the trytes in the string are an odd number
70
73
*/
71
- public static String trytesToAscii (String inputTrytes ) {
74
+ public static String trytesToAscii (String inputTrytes ) throws ArgumentException {
72
75
73
76
// If input length is odd, return null
74
77
if (inputTrytes .length () % 2 != 0 )
75
- return null ;
78
+ throw new ArgumentException ( "Odd amount of trytes supplied" ) ;
76
79
77
80
StringBuilder string = new StringBuilder ();
78
81
Original file line number Diff line number Diff line change 1
1
package jota ;
2
2
3
+ import jota .error .ArgumentException ;
3
4
import jota .utils .TrytesConverter ;
4
5
import org .apache .commons .lang3 .RandomStringUtils ;
5
6
import org .junit .Test ;
@@ -20,14 +21,24 @@ public void shouldConvertStringToTrytes() {
20
21
21
22
@ Test
22
23
public void shouldConvertTrytesToString () {
23
- assertEquals (TrytesConverter .trytesToAscii ("IC" ), "Z" );
24
- assertEquals (TrytesConverter .trytesToAscii ("TBYBCCKBEATBYBCCKB" ), "JOTA JOTA" );
24
+ try {
25
+ assertEquals (TrytesConverter .trytesToAscii ("IC" ), "Z" );
26
+ assertEquals (TrytesConverter .trytesToAscii ("TBYBCCKBEATBYBCCKB" ), "JOTA JOTA" );
27
+ } catch (ArgumentException e ) {
28
+ e .printStackTrace ();
29
+ }
25
30
}
26
31
27
32
@ Test
28
33
public void shouldConvertBackAndForth () {
29
34
String str = RandomStringUtils .randomAlphabetic (1000 ).toUpperCase ();
30
- String back = TrytesConverter .trytesToAscii (TrytesConverter .asciiToTrytes (str ));
31
- assertTrue (str .equals (back ));
35
+ String back ;
36
+ try {
37
+ back = TrytesConverter .trytesToAscii (TrytesConverter .asciiToTrytes (str ));
38
+ assertTrue (str .equals (back ));
39
+ } catch (ArgumentException e ) {
40
+ e .printStackTrace ();
41
+ }
42
+
32
43
}
33
44
}
You can’t perform that action at this time.
0 commit comments