You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@knox.apache.org by kr...@apache.org on 2018/12/20 16:33:16 UTC

[knox] branch master updated: KNOX-1700 - Tests should not extend org.junit.Assert

This is an automated email from the ASF dual-hosted git repository.

krisden pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/knox.git


The following commit(s) were added to refs/heads/master by this push:
     new 2255241  KNOX-1700 - Tests should not extend org.junit.Assert
2255241 is described below

commit 225524175459a403410a3c7d8588ae80f75098ea
Author: Kevin Risden <kr...@apache.org>
AuthorDate: Thu Dec 20 10:54:05 2018 -0500

    KNOX-1700 - Tests should not extend org.junit.Assert
    
    Signed-off-by: Kevin Risden <kr...@apache.org>
---
 .../provider/federation/DefaultValidatorTest.java    |  5 ++++-
 .../HeaderPreAuthFederationFilterTest.java           |  7 ++++---
 .../gateway/provider/federation/IPValidatorTest.java |  8 ++++----
 .../provider/federation/PreAuthServiceTest.java      | 13 +++++++++----
 .../token/impl/DefaultTokenAuthorityServiceTest.java |  7 +++++--
 .../services/security/token/impl/JWTTokenTest.java   | 10 ++++++++--
 .../knox/gateway/util/IpAddressValidatorTest.java    | 12 +++++++-----
 .../org/apache/knox/gateway/util/JsonUtilsTest.java  | 20 +++++++++++---------
 8 files changed, 52 insertions(+), 30 deletions(-)

diff --git a/gateway-provider-security-preauth/src/test/java/org/apache/knox/gateway/provider/federation/DefaultValidatorTest.java b/gateway-provider-security-preauth/src/test/java/org/apache/knox/gateway/provider/federation/DefaultValidatorTest.java
index a4e148b..cfcc8e4 100644
--- a/gateway-provider-security-preauth/src/test/java/org/apache/knox/gateway/provider/federation/DefaultValidatorTest.java
+++ b/gateway-provider-security-preauth/src/test/java/org/apache/knox/gateway/provider/federation/DefaultValidatorTest.java
@@ -24,7 +24,10 @@ import org.junit.Test;
 import javax.servlet.FilterConfig;
 import javax.servlet.http.HttpServletRequest;
 
-public class DefaultValidatorTest extends org.junit.Assert {
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+public class DefaultValidatorTest {
   @Test
   public void testDefault() throws Exception {
     final FilterConfig filterConfig = EasyMock.createMock(FilterConfig.class);
diff --git a/gateway-provider-security-preauth/src/test/java/org/apache/knox/gateway/provider/federation/HeaderPreAuthFederationFilterTest.java b/gateway-provider-security-preauth/src/test/java/org/apache/knox/gateway/provider/federation/HeaderPreAuthFederationFilterTest.java
index 2cd72d3..1f778f1 100644
--- a/gateway-provider-security-preauth/src/test/java/org/apache/knox/gateway/provider/federation/HeaderPreAuthFederationFilterTest.java
+++ b/gateway-provider-security-preauth/src/test/java/org/apache/knox/gateway/provider/federation/HeaderPreAuthFederationFilterTest.java
@@ -31,8 +31,11 @@ import javax.servlet.http.HttpServletRequest;
 
 import java.util.List;
 
-public class HeaderPreAuthFederationFilterTest extends org.junit.Assert {
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
+public class HeaderPreAuthFederationFilterTest {
   @Test
   public void testDefaultValidator() throws ServletException {
     HeaderPreAuthFederationFilter hpaff = new HeaderPreAuthFederationFilter();
@@ -122,12 +125,10 @@ public class HeaderPreAuthFederationFilterTest extends org.junit.Assert {
 
   }
 
-
   public static class DummyValidator implements PreAuthValidator {
     static final String NAME = "DummyValidator";
 
     public DummyValidator() {
-
     }
 
     @Override
diff --git a/gateway-provider-security-preauth/src/test/java/org/apache/knox/gateway/provider/federation/IPValidatorTest.java b/gateway-provider-security-preauth/src/test/java/org/apache/knox/gateway/provider/federation/IPValidatorTest.java
index 131ba9c..07000e6 100644
--- a/gateway-provider-security-preauth/src/test/java/org/apache/knox/gateway/provider/federation/IPValidatorTest.java
+++ b/gateway-provider-security-preauth/src/test/java/org/apache/knox/gateway/provider/federation/IPValidatorTest.java
@@ -25,15 +25,17 @@ import org.junit.Test;
 import javax.servlet.FilterConfig;
 import javax.servlet.http.HttpServletRequest;
 
-public class IPValidatorTest extends org.junit.Assert {
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 
+public class IPValidatorTest {
   @Test
   public void testName() {
     IPValidator ipv = new IPValidator();
     assertEquals(ipv.getName(), IPValidator.IP_VALIDATION_METHOD_VALUE);
   }
 
-
   @Test
   public void testIPAddressPositive() throws PreAuthValidationException {
     IPValidator ipv = new IPValidator();
@@ -63,6 +65,4 @@ public class IPValidatorTest extends org.junit.Assert {
 
     assertFalse(ipv.validate(request, filterConfig));
   }
-
-
 }
diff --git a/gateway-provider-security-preauth/src/test/java/org/apache/knox/gateway/provider/federation/PreAuthServiceTest.java b/gateway-provider-security-preauth/src/test/java/org/apache/knox/gateway/provider/federation/PreAuthServiceTest.java
index 3d812b2..1197130 100644
--- a/gateway-provider-security-preauth/src/test/java/org/apache/knox/gateway/provider/federation/PreAuthServiceTest.java
+++ b/gateway-provider-security-preauth/src/test/java/org/apache/knox/gateway/provider/federation/PreAuthServiceTest.java
@@ -31,8 +31,14 @@ import javax.servlet.http.HttpServletRequest;
 import java.util.List;
 import java.util.Map;
 
-public class PreAuthServiceTest extends org.junit.Assert {
-
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+public class PreAuthServiceTest {
   @Test
   public void testValidatorMap() {
     Map<String, PreAuthValidator> valMap = PreAuthService.getValidatorMap();
@@ -125,8 +131,7 @@ public class PreAuthServiceTest extends org.junit.Assert {
     } catch (Exception e) {
       //Expected
       assertEquals("Unable to find validator with name 'preauth.default.validation,  " +
-                       "NOT_EXISTED_VALIDATOR'",
-          e.getMessage());
+                       "NOT_EXISTED_VALIDATOR'", e.getMessage());
     }
   }
 }
diff --git a/gateway-server/src/test/java/org/apache/knox/gateway/services/token/impl/DefaultTokenAuthorityServiceTest.java b/gateway-server/src/test/java/org/apache/knox/gateway/services/token/impl/DefaultTokenAuthorityServiceTest.java
index 2251f16..4b0ea28 100644
--- a/gateway-server/src/test/java/org/apache/knox/gateway/services/token/impl/DefaultTokenAuthorityServiceTest.java
+++ b/gateway-server/src/test/java/org/apache/knox/gateway/services/token/impl/DefaultTokenAuthorityServiceTest.java
@@ -33,11 +33,14 @@ import org.apache.knox.gateway.services.security.token.TokenServiceException;
 import org.easymock.EasyMock;
 import org.junit.Test;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
 /**
  * Some unit tests for the DefaultTokenAuthorityService.
  */
-public class DefaultTokenAuthorityServiceTest extends org.junit.Assert {
-
+public class DefaultTokenAuthorityServiceTest {
   @Test
   public void testTokenCreation() throws Exception {
     Principal principal = EasyMock.createNiceMock(Principal.class);
diff --git a/gateway-spi/src/test/java/org/apache/knox/gateway/services/security/token/impl/JWTTokenTest.java b/gateway-spi/src/test/java/org/apache/knox/gateway/services/security/token/impl/JWTTokenTest.java
index 27ad390..f53bc16 100644
--- a/gateway-spi/src/test/java/org/apache/knox/gateway/services/security/token/impl/JWTTokenTest.java
+++ b/gateway-spi/src/test/java/org/apache/knox/gateway/services/security/token/impl/JWTTokenTest.java
@@ -35,7 +35,14 @@ import com.nimbusds.jose.JWSVerifier;
 import com.nimbusds.jose.crypto.RSASSASigner;
 import com.nimbusds.jose.crypto.RSASSAVerifier;
 
-public class JWTTokenTest extends org.junit.Assert {
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+public class JWTTokenTest {
   private static final String JWT_TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE0MTY5MjkxMDksImp0aSI6ImFhN2Y4ZDBhOTVjIiwic2NvcGVzIjpbInJlcG8iLCJwdWJsaWNfcmVwbyJdfQ.XCEwpBGvOLma4TCoh36FU7XhUbcskygS81HE1uHLf0E";
   private static final String HEADER = "{\"typ\":\"JWT\",\"alg\":\"HS256\"}";
 
@@ -56,7 +63,6 @@ public class JWTTokenTest extends org.junit.Assert {
   public void testTokenParsing() throws Exception {
     JWTToken token = JWTToken.parseToken(JWT_TOKEN);
     assertEquals(token.getHeader(), HEADER);
-
     assertEquals(token.getClaim("jti"), "aa7f8d0a95c");
   }
 
diff --git a/gateway-util-common/src/test/java/org/apache/knox/gateway/util/IpAddressValidatorTest.java b/gateway-util-common/src/test/java/org/apache/knox/gateway/util/IpAddressValidatorTest.java
index 5ca2c81..d96d73c 100644
--- a/gateway-util-common/src/test/java/org/apache/knox/gateway/util/IpAddressValidatorTest.java
+++ b/gateway-util-common/src/test/java/org/apache/knox/gateway/util/IpAddressValidatorTest.java
@@ -19,10 +19,13 @@ package org.apache.knox.gateway.util;
 
 import org.junit.Test;
 
-public class IpAddressValidatorTest extends org.junit.Assert {
-  String test = "127.0.0.1,193.*,192.168.1.*,0:0:0:0:0:0:0:1,0:0:0:0:0:0:*";
-  String testWeirdConfig = ",127.0.0.1,,193.*,192.168.1.*,29*";
-  String testNullConfig;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class IpAddressValidatorTest {
+  private static final String test = "127.0.0.1,193.*,192.168.1.*,0:0:0:0:0:0:0:1,0:0:0:0:0:0:*";
+  private static final String testWeirdConfig = ",127.0.0.1,,193.*,192.168.1.*,29*";
+  private static final String testNullConfig = null;
 
   @Test
   public void testExplicitIpAddress() throws Exception {
@@ -72,5 +75,4 @@ public class IpAddressValidatorTest extends org.junit.Assert {
 
     assertTrue("Should have validated 293.168.1.1", ipv.validateIpAddress("293.168.1.1"));
   }
-
 }
diff --git a/gateway-util-common/src/test/java/org/apache/knox/gateway/util/JsonUtilsTest.java b/gateway-util-common/src/test/java/org/apache/knox/gateway/util/JsonUtilsTest.java
index 4d58d47..84fb7a1 100644
--- a/gateway-util-common/src/test/java/org/apache/knox/gateway/util/JsonUtilsTest.java
+++ b/gateway-util-common/src/test/java/org/apache/knox/gateway/util/JsonUtilsTest.java
@@ -18,21 +18,24 @@
 package org.apache.knox.gateway.util;
 
 import java.util.HashMap;
+import java.util.Map;
 
 import org.junit.Test;
 
 
 import static org.hamcrest.CoreMatchers.containsString;
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.junit.Assert.assertEquals;
 
-public class JsonUtilsTest extends org.junit.Assert {
-  String expiresIn = "\"expires_in\":\"1364487943100\"";
-  String tokenType = "\"token_type\":\"Bearer\"";
-  String accessToken = "\"access_token\":\"ksdfh3489tyiodhfjk\"";
-  String test = '{' + expiresIn + "," + tokenType + "," + accessToken + '}';
+public class JsonUtilsTest {
+  private String expiresIn = "\"expires_in\":\"1364487943100\"";
+  private String tokenType = "\"token_type\":\"Bearer\"";
+  private String accessToken = "\"access_token\":\"ksdfh3489tyiodhfjk\"";
+  private String test = '{' + expiresIn + "," + tokenType + "," + accessToken + '}';
 
   @Test
-  public void testRenderAsJson() throws Exception {
-    HashMap map = new HashMap();
+  public void testRenderAsJson() {
+    Map<String, Object> map = new HashMap<>();
     map.put("access_token", "ksdfh3489tyiodhfjk");
     map.put("token_type", "Bearer");
     map.put( "expires_in", "1364487943100" );
@@ -45,11 +48,10 @@ public class JsonUtilsTest extends org.junit.Assert {
   }
 
   @Test
-  public void testGetMapFromString() throws Exception {
+  public void testGetMapFromString() {
     HashMap map = (HashMap) JsonUtils.getMapFromJsonString(test);
     assertEquals("ksdfh3489tyiodhfjk", map.get("access_token"));
     assertEquals("Bearer", map.get("token_type"));
     assertEquals("1364487943100", map.get("expires_in"));
   }
-
 }