KEYCLOAK-11986 Fix minor warnings in tests from module common

This commit is contained in:
Andrei Arlou 2019-11-09 01:20:05 +03:00 committed by Stian Thorgersen
parent 38b48c6dd3
commit 5a41e5f8f1
4 changed files with 14 additions and 17 deletions

View file

@ -2,7 +2,6 @@ package org.keycloak.common.util;
import org.junit.Assert;
import org.junit.Test;
import org.keycloak.common.util.CollectionUtil;
import java.util.ArrayList;
@ -10,14 +9,14 @@ public class CollectionUtilTest {
@Test
public void joinInputNoneOutputEmpty() {
final ArrayList<String> strings = new ArrayList<String>();
final ArrayList<String> strings = new ArrayList<>();
final String retval = CollectionUtil.join(strings, ",");
Assert.assertEquals("", retval);
}
@Test
public void joinInput2SeparatorNull() {
final ArrayList<String> strings = new ArrayList<String>();
final ArrayList<String> strings = new ArrayList<>();
strings.add("foo");
strings.add("bar");
final String retval = CollectionUtil.join(strings, null);
@ -26,7 +25,7 @@ public class CollectionUtilTest {
@Test
public void joinInput1SeparatorNotNull() {
final ArrayList<String> strings = new ArrayList<String>();
final ArrayList<String> strings = new ArrayList<>();
strings.add("foo");
final String retval = CollectionUtil.join(strings, ",");
Assert.assertEquals("foo", retval);
@ -34,7 +33,7 @@ public class CollectionUtilTest {
@Test
public void joinInput2SeparatorNotNull() {
final ArrayList<String> strings = new ArrayList<String>();
final ArrayList<String> strings = new ArrayList<>();
strings.add("foo");
strings.add("bar");
final String retval = CollectionUtil.join(strings, ",");

View file

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

View file

@ -12,7 +12,7 @@ import static org.junit.Assert.assertEquals;
public class KeyUtilsTest {
@Test
public void loadSecretKey() throws Exception {
public void loadSecretKey() {
byte[] secretBytes = new byte[32];
ThreadLocalRandom.current().nextBytes(secretBytes);
SecretKeySpec expected = new SecretKeySpec(secretBytes, "HmacSHA256");

View file

@ -2,7 +2,6 @@ package org.keycloak.common.util;
import org.junit.Test;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;
import static org.junit.Assert.assertEquals;
@ -10,28 +9,28 @@ import static org.junit.Assert.assertEquals;
public class PemUtilsTest {
@Test
public void testGenerateThumbprintBytesSha1() throws IOException, NoSuchAlgorithmException {
public void testGenerateThumbprintBytesSha1() throws NoSuchAlgorithmException {
String[] test = new String[] {"abcdefg"};
byte[] digest = PemUtils.generateThumbprintBytes(test, "SHA-1");
assertEquals(20, digest.length);
}
@Test
public void testGenerateThumbprintBytesSha256() throws IOException, NoSuchAlgorithmException {
public void testGenerateThumbprintBytesSha256() throws NoSuchAlgorithmException {
String[] test = new String[] {"abcdefg"};
byte[] digest = PemUtils.generateThumbprintBytes(test, "SHA-256");
assertEquals(32, digest.length);
}
@Test
public void testGenerateThumbprintSha1() throws IOException, NoSuchAlgorithmException {
public void testGenerateThumbprintSha1() throws NoSuchAlgorithmException {
String[] test = new String[] {"abcdefg"};
String encoded = PemUtils.generateThumbprint(test, "SHA-1");
assertEquals(27, encoded.length());
}
@Test
public void testGenerateThumbprintSha256() throws IOException, NoSuchAlgorithmException {
public void testGenerateThumbprintSha256() throws NoSuchAlgorithmException {
String[] test = new String[] {"abcdefg"};
String encoded = PemUtils.generateThumbprint(test, "SHA-256");
assertEquals(43, encoded.length());