Added tests for common utilities CollectionUtil & HtmlUtils.
These tests were written using Diffblue Cover.
This commit is contained in:
parent
4cd617bc42
commit
3c0e8022a9
2 changed files with 60 additions and 0 deletions
|
@ -0,0 +1,43 @@
|
|||
package org.keycloak.common.util;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.keycloak.common.util.CollectionUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class CollectionUtilTest {
|
||||
|
||||
@Test
|
||||
public void joinInputNoneOutputEmpty() {
|
||||
final ArrayList<String> strings = new ArrayList<String>();
|
||||
final String retval = CollectionUtil.join(strings, ",");
|
||||
Assert.assertEquals("", retval);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void joinInput2SeparatorNull() {
|
||||
final ArrayList<String> strings = new ArrayList<String>();
|
||||
strings.add("foo");
|
||||
strings.add("bar");
|
||||
final String retval = CollectionUtil.join(strings, null);
|
||||
Assert.assertEquals("foonullbar", retval);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void joinInput1SeparatorNotNull() {
|
||||
final ArrayList<String> strings = new ArrayList<String>();
|
||||
strings.add("foo");
|
||||
final String retval = CollectionUtil.join(strings, ",");
|
||||
Assert.assertEquals("foo", retval);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void joinInput2SeparatorNotNull() {
|
||||
final ArrayList<String> strings = new ArrayList<String>();
|
||||
strings.add("foo");
|
||||
strings.add("bar");
|
||||
final String retval = CollectionUtil.join(strings, ",");
|
||||
Assert.assertEquals("foo,bar", retval);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
package org.keycloak.common.util;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.keycloak.common.util.HtmlUtils;
|
||||
|
||||
public class HtmlUtilsTest {
|
||||
|
||||
@Test
|
||||
public void escapeAttribute() {
|
||||
Assert.assertEquals(HtmlUtils.escapeAttribute("1<2"), "1<2");
|
||||
Assert.assertEquals(HtmlUtils.escapeAttribute("2<3&&3>2"), "2<3&&3>2");
|
||||
Assert.assertEquals(HtmlUtils.escapeAttribute("test"), "test");
|
||||
Assert.assertEquals(HtmlUtils.escapeAttribute("\'test\'"), "'test'");
|
||||
Assert.assertEquals(HtmlUtils.escapeAttribute("\"test\""), ""test"");
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue