From 5a41e5f8f15d22d956484136050d601a44b2efd3 Mon Sep 17 00:00:00 2001 From: Andrei Arlou Date: Sat, 9 Nov 2019 01:20:05 +0300 Subject: [PATCH] KEYCLOAK-11986 Fix minor warnings in tests from module common --- .../org/keycloak/common/util/CollectionUtilTest.java | 9 ++++----- .../java/org/keycloak/common/util/HtmlUtilsTest.java | 11 +++++------ .../java/org/keycloak/common/util/KeyUtilsTest.java | 2 +- .../java/org/keycloak/common/util/PemUtilsTest.java | 9 ++++----- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/common/src/test/java/org/keycloak/common/util/CollectionUtilTest.java b/common/src/test/java/org/keycloak/common/util/CollectionUtilTest.java index 4b650fb238..dcfc31a920 100644 --- a/common/src/test/java/org/keycloak/common/util/CollectionUtilTest.java +++ b/common/src/test/java/org/keycloak/common/util/CollectionUtilTest.java @@ -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 strings = new ArrayList(); + final ArrayList strings = new ArrayList<>(); final String retval = CollectionUtil.join(strings, ","); Assert.assertEquals("", retval); } @Test public void joinInput2SeparatorNull() { - final ArrayList strings = new ArrayList(); + final ArrayList 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 strings = new ArrayList(); + final ArrayList 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 strings = new ArrayList(); + final ArrayList strings = new ArrayList<>(); strings.add("foo"); strings.add("bar"); final String retval = CollectionUtil.join(strings, ","); diff --git a/common/src/test/java/org/keycloak/common/util/HtmlUtilsTest.java b/common/src/test/java/org/keycloak/common/util/HtmlUtilsTest.java index b2c6c5a4fc..01c069bb65 100644 --- a/common/src/test/java/org/keycloak/common/util/HtmlUtilsTest.java +++ b/common/src/test/java/org/keycloak/common/util/HtmlUtilsTest.java @@ -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<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""); + Assert.assertEquals("1<2", HtmlUtils.escapeAttribute("1<2")); + Assert.assertEquals("2<3&&3>2", HtmlUtils.escapeAttribute("2<3&&3>2") ); + Assert.assertEquals("test", HtmlUtils.escapeAttribute("test")); + Assert.assertEquals("'test'", HtmlUtils.escapeAttribute("\'test\'")); + Assert.assertEquals(""test"", HtmlUtils.escapeAttribute("\"test\"")); } } diff --git a/common/src/test/java/org/keycloak/common/util/KeyUtilsTest.java b/common/src/test/java/org/keycloak/common/util/KeyUtilsTest.java index 29526ea5ca..a1a4080835 100644 --- a/common/src/test/java/org/keycloak/common/util/KeyUtilsTest.java +++ b/common/src/test/java/org/keycloak/common/util/KeyUtilsTest.java @@ -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"); diff --git a/common/src/test/java/org/keycloak/common/util/PemUtilsTest.java b/common/src/test/java/org/keycloak/common/util/PemUtilsTest.java index a5c865443a..b45b15992c 100644 --- a/common/src/test/java/org/keycloak/common/util/PemUtilsTest.java +++ b/common/src/test/java/org/keycloak/common/util/PemUtilsTest.java @@ -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());