forked from loklak/loklak_server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request loklak#1627 from sakshee-19/development
Fixes loklak#1580: Add Unit Test for UTF8.java file
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |