1 package org.testng.internal; 2 3 import java.util.List; 4 5 import org.testng.annotations.Test; 6 7 import static java.util.Arrays.asList; 8 import static java.util.Collections.emptyList; 9 import static org.testng.Assert.assertEquals; 10 import static org.testng.internal.Utils.join; 11 12 /** 13 * Unit tests for {@link Utils}. 14 * 15 * @author Tomas Pollak 16 */ 17 public class UtilsTest { 18 private static final char INVALID_CHAR = 0xFFFE; 19 private static final char REPLACEMENT_CHAR = 0xFFFD; 20 21 @Test escapeUnicode()22 public void escapeUnicode() { 23 assertEquals(Utils.escapeUnicode("test"), "test"); 24 assertEquals(Utils.escapeUnicode(String.valueOf(INVALID_CHAR)), 25 String.valueOf(REPLACEMENT_CHAR)); 26 27 } 28 29 @Test createEmptyStringWhenJoiningEmptyListWithJoin()30 public void createEmptyStringWhenJoiningEmptyListWithJoin() throws Exception { 31 List<String> emptyList = emptyList(); 32 assertEquals("", join(emptyList, ",")); 33 } 34 35 @Test joinTwoStringsWithJoinStrings()36 public void joinTwoStringsWithJoinStrings() throws Exception { 37 List<String> twoStrings = asList("one", "two"); 38 assertEquals("one,two", Utils.join(twoStrings, ",")); 39 } 40 41 @Test createEmptyStringWhenJoiningEmptyListWithJoinStrings()42 public void createEmptyStringWhenJoiningEmptyListWithJoinStrings() throws Exception { 43 List<String> emptyList = emptyList(); 44 assertEquals("", Utils.join(emptyList, ",")); 45 } 46 } 47