diff options
Diffstat (limited to 'utils-test/src/main/java/org/onap/policy/common/utils/test')
4 files changed, 28 insertions, 34 deletions
diff --git a/utils-test/src/main/java/org/onap/policy/common/utils/test/ExceptionsTester.java b/utils-test/src/main/java/org/onap/policy/common/utils/test/ExceptionsTester.java index f457dd21..1ab1f285 100644 --- a/utils-test/src/main/java/org/onap/policy/common/utils/test/ExceptionsTester.java +++ b/utils-test/src/main/java/org/onap/policy/common/utils/test/ExceptionsTester.java @@ -2,7 +2,7 @@ * ============LICENSE_START==================================================== * Common Utils-Test * ============================================================================= - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018, 2021 AT&T Intellectual Property. All rights reserved. * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -70,7 +70,7 @@ public class ExceptionsTester extends ThrowablesTester { * if the constructed objects fail to pass various tests */ public <T extends Exception> int testAllException(final Class<T> claz) { - int ncons = 0; + var ncons = 0; ncons += testAllThrowable(claz); ncons += testException(claz); @@ -111,8 +111,8 @@ public class ExceptionsTester extends ThrowablesTester { return 0; } - Exception cause = new Exception(EXPECTED_EXCEPTION_MSG); - T ex = newInstance(cons, cause); + var cause = new Exception(EXPECTED_EXCEPTION_MSG); + var ex = newInstance(cons, cause); assertNotNull(ex.toString()); assertEquals(ex.getMessage(), ex.getMessage()); @@ -151,8 +151,8 @@ public class ExceptionsTester extends ThrowablesTester { return 0; } - Exception cause = new Exception(EXPECTED_EXCEPTION_MSG); - T ex = newInstance(cons, "world", cause); + var cause = new Exception(EXPECTED_EXCEPTION_MSG); + var ex = newInstance(cons, "world", cause); assertNotNull(ex.toString()); assertEquals("world", ex.getMessage()); diff --git a/utils-test/src/main/java/org/onap/policy/common/utils/test/ThrowablesTester.java b/utils-test/src/main/java/org/onap/policy/common/utils/test/ThrowablesTester.java index 0fba944e..06ca8046 100644 --- a/utils-test/src/main/java/org/onap/policy/common/utils/test/ThrowablesTester.java +++ b/utils-test/src/main/java/org/onap/policy/common/utils/test/ThrowablesTester.java @@ -2,7 +2,7 @@ * ============LICENSE_START==================================================== * Common Utils-Test * ============================================================================= - * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018, 2020-2021 AT&T Intellectual Property. All rights reserved. * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,6 @@ import static org.junit.Assert.assertTrue; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,7 +39,7 @@ public class ThrowablesTester { private static Logger logger = LoggerFactory.getLogger(ThrowablesTester.class); - public static final String EXPECTED_EXCEPTION_MSG = + public static final String EXPECTED_EXCEPTION_MSG = "expected exception"; private static final String EXPECTED_SUPPRESSED_EXCEPTION_MSG = "expected suppressed exception"; @@ -74,7 +73,7 @@ public class ThrowablesTester { */ public final <T extends Throwable> int testAllThrowable( final Class<T> claz) { - int ncons = 0; + var ncons = 0; ncons += testDefault(claz); ncons += testString(claz); @@ -113,7 +112,7 @@ public class ThrowablesTester { return 0; } - T ex = newInstance(cons); + var ex = newInstance(cons); assertNotNull(ex.toString()); assertNull(ex.getMessage()); @@ -152,7 +151,7 @@ public class ThrowablesTester { return 0; } - T ex = newInstance(cons, "hello"); + var ex = newInstance(cons, "hello"); assertNotNull(ex.toString()); assertEquals("hello", ex.getMessage()); @@ -192,7 +191,7 @@ public class ThrowablesTester { return 0; } - T ex = newInstance(cons, CAUSE); + var ex = newInstance(cons, CAUSE); assertEquals(ex.getMessage(), ex.getMessage()); assertNotNull(ex.toString()); @@ -232,7 +231,7 @@ public class ThrowablesTester { return 0; } - T ex = newInstance(cons, "world", CAUSE); + var ex = newInstance(cons, "world", CAUSE); assertNotNull(ex.toString()); assertEquals("world", ex.getMessage()); @@ -383,7 +382,7 @@ public class ThrowablesTester { */ public final <T extends Throwable> void testSuppressStack( final Constructor<T> cons) { - T ex = newInstance(cons, "yes,yes", CAUSE, true, true); + var ex = newInstance(cons, "yes,yes", CAUSE, true, true); ex.addSuppressed(SUPPRESSED); @@ -421,7 +420,7 @@ public class ThrowablesTester { */ public final <T extends Throwable> void testSuppressNoStack( final Constructor<T> cons) { - T ex = newInstance(cons, "yes,no", CAUSE, true, false); + var ex = newInstance(cons, "yes,no", CAUSE, true, false); ex.addSuppressed(SUPPRESSED); @@ -459,7 +458,7 @@ public class ThrowablesTester { */ public final <T extends Throwable> void testNoSuppressStack( final Constructor<T> cons) { - T ex = newInstance(cons, "no,yes", CAUSE, false, true); + var ex = newInstance(cons, "no,yes", CAUSE, false, true); ex.addSuppressed(SUPPRESSED); @@ -495,7 +494,7 @@ public class ThrowablesTester { */ public final <T extends Throwable> void testNoSuppressNoStack( final Constructor<T> cons) { - T ex = newInstance(cons, "no,no", CAUSE, false, false); + var ex = newInstance(cons, "no,no", CAUSE, false, false); ex.addSuppressed(SUPPRESSED); @@ -530,8 +529,7 @@ public class ThrowablesTester { } catch (NoSuchMethodException | SecurityException e) { // this constructor is not defined so nothing to test - logger.debug("skipped test, no constructor for: " - + claz + " due to: " + e); + logger.debug("skipped test, no constructor for: {}", claz, e); return null; } } diff --git a/utils-test/src/main/java/org/onap/policy/common/utils/test/ToStringTester.java b/utils-test/src/main/java/org/onap/policy/common/utils/test/ToStringTester.java index f9ae39ac..ab09291c 100644 --- a/utils-test/src/main/java/org/onap/policy/common/utils/test/ToStringTester.java +++ b/utils-test/src/main/java/org/onap/policy/common/utils/test/ToStringTester.java @@ -1,7 +1,7 @@ /*- * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. - * Modifications Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2018-2021 AT&T Intellectual Property. All rights reserved. * Modifications Copyright (C) 2019 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -29,7 +29,7 @@ import com.openpojo.reflection.PojoClass; import com.openpojo.validation.affirm.Affirm; import com.openpojo.validation.test.Tester; import com.openpojo.validation.utils.ValidationHelper; - +import lombok.AllArgsConstructor; import org.hamcrest.Matcher; @@ -38,23 +38,19 @@ import org.hamcrest.Matcher; * * @author Ram Krishna Verma (ram.krishna.verma@est.tech) */ -@SuppressWarnings("rawtypes") +@AllArgsConstructor public class ToStringTester implements Tester { - private final Matcher matcher; + private final Matcher<?> matcher; public ToStringTester() { matcher = anything(); } - public ToStringTester(final Matcher matcher) { - this.matcher = matcher; - } - @SuppressWarnings("unchecked") @Override public void run(final PojoClass pojoClass) { - final Class clazz = pojoClass.getClazz(); + final Class<?> clazz = pojoClass.getClazz(); if (anyOf(matcher).matches(clazz)) { final Object classInstance = ValidationHelper.getBasicInstance(pojoClass); diff --git a/utils-test/src/main/java/org/onap/policy/common/utils/test/log/logback/ExtractAppender.java b/utils-test/src/main/java/org/onap/policy/common/utils/test/log/logback/ExtractAppender.java index 19c50968..27d9fcc6 100644 --- a/utils-test/src/main/java/org/onap/policy/common/utils/test/log/logback/ExtractAppender.java +++ b/utils-test/src/main/java/org/onap/policy/common/utils/test/log/logback/ExtractAppender.java @@ -2,7 +2,7 @@ * ============LICENSE_START==================================================== * Common Utils-Test * ============================================================================= - * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2018-2019, 2021 AT&T Intellectual Property. All rights reserved. * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,13 +22,13 @@ package org.onap.policy.common.utils.test.log.logback; import ch.qos.logback.classic.spi.ILoggingEvent; import ch.qos.logback.core.AppenderBase; +import com.google.re2j.Matcher; +import com.google.re2j.Pattern; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Queue; -import java.util.regex.Matcher; -import java.util.regex.Pattern; /** * This is an appender that is intended for use by JUnit tests that wish to @@ -110,7 +110,7 @@ public class ExtractAppender extends AppenderBase<ILoggingEvent> { } for (Pattern p : patterns.values()) { - Matcher matcher = p.matcher(msg); + var matcher = p.matcher(msg); if (matcher.find()) { addGroupMatch(matcher); @@ -129,7 +129,7 @@ public class ExtractAppender extends AppenderBase<ILoggingEvent> { private void addGroupMatch(final Matcher mat) { int ngroups = mat.groupCount(); - for (int x = 1; x <= ngroups; ++x) { + for (var x = 1; x <= ngroups; ++x) { String txt = mat.group(x); if (txt != null) { |