Skip to content

Commit

Permalink
Fixes loklak#1580: Add Unit Test for UTF8.java file
Browse files Browse the repository at this point in the history
  • Loading branch information
sakshee-19 committed Sep 18, 2018
1 parent e36c442 commit ec1b626
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions test/org/loklak/tools/UTF8Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.loklak.tools;

import org.loklak.tools.UTF8;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
/**
* These unit-tests test org.loklak.tools.UTF8.java
*/
public class UTF8Test{

@Test
public void testGetBytes(){
UTF8 utf8 = new UTF8();
String str = "loklak-server";
byte [] returnVal = utf8.getBytes(str);
String s = "";
for(int i=0; i<returnVal.length; ++i){
s += String.valueOf(returnVal[i]);
}
assertEquals("1081111071089710745115101114118101114", s);
}

@Test
public void testGetBytes2() {
StringBuilder str = new StringBuilder("loklak-server");
UTF8 utf8 = new UTF8();
byte[] returnVal = utf8.getBytes(str);
String s = "";
for(int i=0; i<returnVal.length; ++i){
s += String.valueOf(returnVal[i]);
}
assertEquals("1081111071089710745115101114118101114", s);
}

@Test
public void testBytestoString() {
UTF8 utf8 = new UTF8();
byte[] param = "loklak-server".getBytes();
String returnVal = utf8.String(param);
assertEquals("loklak-server", returnVal);
}

@Test
public void testBytestoString2() {
UTF8 utf8 = new UTF8();
byte[] param = "loklak-server".getBytes();
int offset = 0;
int length = param.length;
String returnVal = utf8.String(param, offset, length);
assertEquals("loklak-server", returnVal);
}
}

0 comments on commit ec1b626

Please sign in to comment.