Added tests for common utilities CollectionUtil & HtmlUtils.

These tests were written using Diffblue Cover.
This commit is contained in:
Freddy Tuxworth 2019-01-23 18:15:15 +00:00 committed by Stian Thorgersen
parent 4cd617bc42
commit 3c0e8022a9
2 changed files with 60 additions and 0 deletions

View file

@ -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);
}
}

View file

@ -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&lt;2");
Assert.assertEquals(HtmlUtils.escapeAttribute("2<3&&3>2"), "2&lt;3&amp;&amp;3&gt;2");
Assert.assertEquals(HtmlUtils.escapeAttribute("test"), "test");
Assert.assertEquals(HtmlUtils.escapeAttribute("\'test\'"), "&apos;test&apos;");
Assert.assertEquals(HtmlUtils.escapeAttribute("\"test\""), "&quot;test&quot;");
}
}