diff options
Diffstat (limited to 'utils-test/src')
24 files changed, 320 insertions, 278 deletions
diff --git a/utils-test/src/main/java/org/onap/policy/common/utils/gson/GsonTestUtils.java b/utils-test/src/main/java/org/onap/policy/common/utils/gson/GsonTestUtils.java index 8276ea4c..da62569e 100644 --- a/utils-test/src/main/java/org/onap/policy/common/utils/gson/GsonTestUtils.java +++ b/utils-test/src/main/java/org/onap/policy/common/utils/gson/GsonTestUtils.java @@ -21,7 +21,7 @@ package org.onap.policy.common.utils.gson; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import com.google.gson.Gson; import com.google.gson.JsonArray; 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 1ab1f285..34dc5681 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 @@ -3,6 +3,7 @@ * Common Utils-Test * ============================================================================= * Copyright (C) 2018, 2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,9 +21,9 @@ package org.onap.policy.common.utils.test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.lang.reflect.Constructor; 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 06ca8046..62584c76 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 @@ -3,6 +3,7 @@ * Common Utils-Test * ============================================================================= * Copyright (C) 2018, 2020-2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,10 +21,10 @@ package org.onap.policy.common.utils.test; -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.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; diff --git a/utils-test/src/main/java/org/onap/policy/common/utils/time/TestTimeMulti.java b/utils-test/src/main/java/org/onap/policy/common/utils/time/TestTimeMulti.java index 9e61eaa3..8ffcd36a 100644 --- a/utils-test/src/main/java/org/onap/policy/common/utils/time/TestTimeMulti.java +++ b/utils-test/src/main/java/org/onap/policy/common/utils/time/TestTimeMulti.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2018-2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +21,7 @@ package org.onap.policy.common.utils.time; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; import java.util.Iterator; import java.util.LinkedList; diff --git a/utils-test/src/test/java/org/onap/policy/common/utils/gson/GsonSerializerTest.java b/utils-test/src/test/java/org/onap/policy/common/utils/gson/GsonSerializerTest.java index 82f5ede0..aa701435 100644 --- a/utils-test/src/test/java/org/onap/policy/common/utils/gson/GsonSerializerTest.java +++ b/utils-test/src/test/java/org/onap/policy/common/utils/gson/GsonSerializerTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,12 +27,12 @@ import com.google.gson.stream.JsonReader; import com.google.gson.stream.JsonWriter; import java.io.IOException; import java.io.StringReader; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class GsonSerializerTest { +class GsonSerializerTest { @Test - public void testReadJsonReader() { + void testReadJsonReader() { JsonReader rdr = new JsonReader(new StringReader("10")); GsonSerializer<Object> ser = new GsonSerializer<Object>() { diff --git a/utils-test/src/test/java/org/onap/policy/common/utils/gson/GsonTestUtilsBuilderTest.java b/utils-test/src/test/java/org/onap/policy/common/utils/gson/GsonTestUtilsBuilderTest.java index 466041e3..d85653d9 100644 --- a/utils-test/src/test/java/org/onap/policy/common/utils/gson/GsonTestUtilsBuilderTest.java +++ b/utils-test/src/test/java/org/onap/policy/common/utils/gson/GsonTestUtilsBuilderTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +21,7 @@ package org.onap.policy.common.utils.gson; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -30,20 +31,20 @@ import com.google.gson.TypeAdapterFactory; import com.google.gson.reflect.TypeToken; import com.google.gson.stream.JsonWriter; import java.io.IOException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class GsonTestUtilsBuilderTest { +class GsonTestUtilsBuilderTest { private GsonTestUtils utils; - @Before + @BeforeEach public void setUp() { utils = new MyBuilder().build(); } @Test - public void testBuilderAddMock() { + void testBuilderAddMock() { PreMock pre = mock(PreMock.class); when(pre.getId()).thenReturn(2000); diff --git a/utils-test/src/test/java/org/onap/policy/common/utils/gson/GsonTestUtilsTest.java b/utils-test/src/test/java/org/onap/policy/common/utils/gson/GsonTestUtilsTest.java index 51522ec0..d355823c 100644 --- a/utils-test/src/test/java/org/onap/policy/common/utils/gson/GsonTestUtilsTest.java +++ b/utils-test/src/test/java/org/onap/policy/common/utils/gson/GsonTestUtilsTest.java @@ -23,9 +23,9 @@ package org.onap.policy.common.utils.gson; import static org.assertj.core.api.Assertions.assertThatCode; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import com.google.gson.JsonArray; import com.google.gson.JsonElement; @@ -38,26 +38,26 @@ import java.io.IOException; import lombok.Getter; import lombok.Setter; import lombok.ToString; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class GsonTestUtilsTest { +class GsonTestUtilsTest { private static final String HELLO = "hello"; private GsonTestUtils utils; - @Before + @BeforeEach public void setUp() { utils = new GsonTestUtils(); } @Test - public void testGetGson() { + void testGetGson() { assertNotNull(utils.getGson()); } @Test - public void testGsonRoundTrip() { + void testGsonRoundTrip() { Data data = new Data(); data.setId(500); @@ -71,7 +71,7 @@ public class GsonTestUtilsTest { } @Test - public void testCompareGsonObjectClass_testCompareGsonObjectFile() { + void testCompareGsonObjectClass_testCompareGsonObjectFile() { Data data = new Data(); data.setId(500); data.setText(HELLO); @@ -98,7 +98,7 @@ public class GsonTestUtilsTest { } @Test - public void testCompareGsonObjectString() { + void testCompareGsonObjectString() { Data data = new Data(); data.setId(600); data.setText(HELLO); @@ -108,7 +108,7 @@ public class GsonTestUtilsTest { } @Test - public void testCompareGsonObjectJsonElement() { + void testCompareGsonObjectJsonElement() { Data data = new Data(); data.setId(650); data.setText(HELLO); @@ -125,7 +125,7 @@ public class GsonTestUtilsTest { } @Test - public void testApplyScripts() { + void testApplyScripts() { Data data = new Data(); data.setId(700); data.setText(HELLO); @@ -144,7 +144,7 @@ public class GsonTestUtilsTest { } @Test - public void testReorderJsonObject() { + void testReorderJsonObject() { // insert properties in a non-alphabetical order JsonObject inner = new JsonObject(); inner.addProperty("objBint", 100); @@ -168,7 +168,7 @@ public class GsonTestUtilsTest { } @Test - public void testReorderJsonArray() { + void testReorderJsonArray() { // insert properties in a non-alphabetical order JsonObject inner = new JsonObject(); inner.add("objCNull", JsonNull.INSTANCE); @@ -185,7 +185,7 @@ public class GsonTestUtilsTest { } @Test - public void testReorderJsonElement() { + void testReorderJsonElement() { // null element JsonElement jsonEl = null; assertNull(utils.reorder(jsonEl)); diff --git a/utils-test/src/test/java/org/onap/policy/common/utils/io/SerializerTest.java b/utils-test/src/test/java/org/onap/policy/common/utils/io/SerializerTest.java index 203c78ec..25461daf 100644 --- a/utils-test/src/test/java/org/onap/policy/common/utils/io/SerializerTest.java +++ b/utils-test/src/test/java/org/onap/policy/common/utils/io/SerializerTest.java @@ -3,7 +3,7 @@ * ONAP Policy Engine - Common Modules * ================================================================================ * Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved. - * Modificaitons Copyright (C) 2023 Nordix Foundation. + * Modificaitons Copyright (C) 2023-2024 Nordix Foundation. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,9 +22,9 @@ package org.onap.policy.common.utils.io; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; @@ -37,14 +37,14 @@ import java.io.Serializable; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.util.Arrays; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.common.utils.io.Serializer.Factory; import org.springframework.test.util.ReflectionTestUtils; -public class SerializerTest { +class SerializerTest { private static final String FACTORY = "factory"; /** @@ -52,28 +52,28 @@ public class SerializerTest { */ private static Factory saveFactory; - @BeforeClass + @BeforeAll public static void setUpBeforeClass() { saveFactory = (Factory) ReflectionTestUtils.getField(Serializer.class, FACTORY); } - @AfterClass + @AfterAll public static void tearDownAfterClass() { ReflectionTestUtils.setField(Serializer.class, FACTORY, saveFactory); } - @Before + @BeforeEach public void setUp() { setFactory(saveFactory); } @Test - public void testFactory() { + void testFactory() { assertNotNull(saveFactory); } @Test - public void testSerialize() throws Exception { + void testSerialize() throws Exception { MyObject obj1 = new MyObject(3); byte[] data = Serializer.serialize(obj1); assertTrue(data.length > 0); @@ -85,13 +85,14 @@ public class SerializerTest { assertEquals(obj1.value, obj2.value); } - @Test(expected = java.io.NotSerializableException.class) - public void testSerialize_Ex() throws Exception { - Serializer.serialize(new NotSerializable()); + @Test + void testSerialize_Ex() { + assertThatThrownBy(() -> Serializer.serialize(new NotSerializable())) + .isInstanceOf(java.io.NotSerializableException.class); } @Test - public void testSerialize_ArrayCloseEx() { + void testSerialize_ArrayCloseEx() { IOException ex = new IOException("testSerialize_ArrayCloseEx"); /* @@ -125,7 +126,7 @@ public class SerializerTest { } @Test - public void testSerialize_ObjectWriteEx() { + void testSerialize_ObjectWriteEx() { IOException ex = new IOException("testSerialize_ObjectWriteEx"); /* @@ -142,7 +143,7 @@ public class SerializerTest { } @Test - public void testSerialize_ObjectCloseEx() throws Exception { + void testSerialize_ObjectCloseEx() throws Exception { IOException ex = new IOException("testSerialize_ObjectCloseEx"); ObjectOutputStream oos = mock(ObjectOutputStream.class); doThrow(ex).when(oos).close(); @@ -168,7 +169,7 @@ public class SerializerTest { } @Test - public void testSerialize_BothCloseEx() throws Exception { + void testSerialize_BothCloseEx() throws Exception { IOException ex = new IOException("testSerialize_BothCloseEx"); IOException ex2 = new IOException("testSerialize_BothCloseEx_2"); ObjectOutputStream oos = mock(ObjectOutputStream.class); @@ -216,14 +217,14 @@ public class SerializerTest { } @Test - public void testDeserialize() throws Exception { + void testDeserialize() throws Exception { MyObject obj1 = new MyObject(3); MyObject obj2 = Serializer.roundTrip(obj1); assertEquals(obj1.value, obj2.value); } @Test - public void testDeserialize_ArrayCloseEx() throws Exception { + void testDeserialize_ArrayCloseEx() { IOException ex = new IOException("testSerialize_ObjectWriteEx"); /* @@ -252,7 +253,7 @@ public class SerializerTest { } @Test - public void testDeserialize_ObjectReadEx() throws Exception { + void testDeserialize_ObjectReadEx() { IOException ex = new IOException("testDeserialize_ObjectReadEx"); /* @@ -269,7 +270,7 @@ public class SerializerTest { } @Test - public void testDeserialize_ObjectRead_ClassEx() throws Exception { + void testDeserialize_ObjectRead_ClassEx() throws Exception { MyObject obj1 = new MyObject(200); // must use binary character set @@ -302,7 +303,7 @@ public class SerializerTest { } @Test - public void testDeserialize_ObjectCloseEx() throws Exception { + void testDeserialize_ObjectCloseEx() { IOException ex = new IOException("testDeserialize_ObjectCloseEx"); /* @@ -325,7 +326,7 @@ public class SerializerTest { } @Test - public void testDeserialize_BothCloseEx() throws Exception { + void testDeserialize_BothCloseEx() { IOException ex = new IOException("testDeserialize_BothCloseEx"); IOException ex2 = new IOException("testDeserialize_BothCloseEx_2"); @@ -359,16 +360,17 @@ public class SerializerTest { } @Test - public void testRoundTrip() throws Exception { + void testRoundTrip() throws Exception { MyObject obj1 = new MyObject(3); MyObject obj2 = Serializer.roundTrip(obj1); assertEquals(obj1.value, obj2.value); } - @Test(expected = java.io.NotSerializableException.class) - public void testRoundTrip_Ex() throws Exception { - Serializer.roundTrip(new NotSerializable()); + @Test + void testRoundTrip_Ex() { + assertThatThrownBy(() -> Serializer.roundTrip(new NotSerializable())) + .isInstanceOf(java.io.NotSerializableException.class); } /** diff --git a/utils-test/src/test/java/org/onap/policy/common/utils/security/SelfSignedKeyStoreTest.java b/utils-test/src/test/java/org/onap/policy/common/utils/security/SelfSignedKeyStoreTest.java index 27bceacf..8a3dfe39 100644 --- a/utils-test/src/test/java/org/onap/policy/common/utils/security/SelfSignedKeyStoreTest.java +++ b/utils-test/src/test/java/org/onap/policy/common/utils/security/SelfSignedKeyStoreTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,9 +28,9 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import java.util.concurrent.TimeUnit; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class SelfSignedKeyStoreTest { private static final String USER_DIR_PROP = "user.dir"; @@ -42,14 +43,14 @@ public class SelfSignedKeyStoreTest { /** * Saves the user.dir property and initializes static fields. */ - @BeforeClass + @BeforeAll public static void setUpBeforeClass() { saveUserDir = System.getProperty(USER_DIR_PROP); defaultName = saveUserDir + "/" + SelfSignedKeyStore.RELATIVE_PATH; defaultKeystore = new File(defaultName); } - @Before + @BeforeEach public void setUp() { System.setProperty(USER_DIR_PROP, saveUserDir); delete(defaultKeystore); @@ -108,7 +109,7 @@ public class SelfSignedKeyStoreTest { * Tests the constructor, when the SAN file is not found. */ @Test - public void testSelfSignedKeyStoreStringNoSanFile() throws Exception { + public void testSelfSignedKeyStoreStringNoSanFile() { assertThatThrownBy(() -> new SelfSignedKeyStore() { @Override protected String getKeystoreSanName() { @@ -121,7 +122,7 @@ public class SelfSignedKeyStoreTest { * Tests the constructor, when write fails. */ @Test - public void testSelfSignedKeyStoreStringWriteFailure() throws Exception { + public void testSelfSignedKeyStoreStringWriteFailure() { assertThatThrownBy(() -> new SelfSignedKeyStore("target/unknown/path/to/keystore")) .isInstanceOf(IOException.class); } diff --git a/utils-test/src/test/java/org/onap/policy/common/utils/test/ConstructionErrorTest.java b/utils-test/src/test/java/org/onap/policy/common/utils/test/ConstructionErrorTest.java index 8a60a5d2..95bba10d 100644 --- a/utils-test/src/test/java/org/onap/policy/common/utils/test/ConstructionErrorTest.java +++ b/utils-test/src/test/java/org/onap/policy/common/utils/test/ConstructionErrorTest.java @@ -3,6 +3,7 @@ * Common Utils-Test * ================================================================================ * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,14 +21,14 @@ package org.onap.policy.common.utils.test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class ConstructionErrorTest extends ErrorsTester { +class ConstructionErrorTest extends ErrorsTester { @Test - public void test() { + void test() { assertEquals(4, testAllError(ConstructionError.class)); } diff --git a/utils-test/src/test/java/org/onap/policy/common/utils/test/ErrorsTesterTest.java b/utils-test/src/test/java/org/onap/policy/common/utils/test/ErrorsTesterTest.java index 2009e297..b6d91f07 100644 --- a/utils-test/src/test/java/org/onap/policy/common/utils/test/ErrorsTesterTest.java +++ b/utils-test/src/test/java/org/onap/policy/common/utils/test/ErrorsTesterTest.java @@ -3,6 +3,7 @@ * Common Utils-Test * ================================================================================ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,14 +21,14 @@ package org.onap.policy.common.utils.test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class ErrorsTesterTest { +class ErrorsTesterTest { @Test - public void test() { + void test() { assertEquals(2, new ErrorsTester().testAllError(SimpleError.class)); assertEquals(5, new ErrorsTester().testAllError(StaticError.class)); } diff --git a/utils-test/src/test/java/org/onap/policy/common/utils/test/ExceptionsTesterTest.java b/utils-test/src/test/java/org/onap/policy/common/utils/test/ExceptionsTesterTest.java index 89ff3ba1..81a85035 100644 --- a/utils-test/src/test/java/org/onap/policy/common/utils/test/ExceptionsTesterTest.java +++ b/utils-test/src/test/java/org/onap/policy/common/utils/test/ExceptionsTesterTest.java @@ -3,6 +3,7 @@ * Common Utils-Test * ================================================================================ * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,21 +21,24 @@ package org.onap.policy.common.utils.test; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class ExceptionsTesterTest { +class ExceptionsTesterTest { @Test - public void test() { + void test() { assertEquals(2, new ExceptionsTester().test(SimpleException.class)); assertEquals(8, new ExceptionsTester().test(StaticException.class)); } - @Test(expected = AssertionError.class) - public void testNoConstructorsException() { - new ExceptionsTester().test(NoConstructorsException.class); + @Test + void testNoConstructorsException() { + ExceptionsTester tester = new ExceptionsTester(); + assertThatThrownBy(() -> tester.test(NoConstructorsException.class)) + .isInstanceOf(AssertionError.class); } /** diff --git a/utils-test/src/test/java/org/onap/policy/common/utils/test/ThrowablesTesterTest.java b/utils-test/src/test/java/org/onap/policy/common/utils/test/ThrowablesTesterTest.java index 3cb53d81..7775ef35 100644 --- a/utils-test/src/test/java/org/onap/policy/common/utils/test/ThrowablesTesterTest.java +++ b/utils-test/src/test/java/org/onap/policy/common/utils/test/ThrowablesTesterTest.java @@ -3,6 +3,7 @@ * Common Utils-Test * ================================================================================ * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,58 +21,73 @@ package org.onap.policy.common.utils.test; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class ThrowablesTesterTest { +class ThrowablesTesterTest { @Test - public void test() { + void test() { assertEquals(2, new ThrowablesTester().testAllThrowable(SimpleThrowable.class)); assertEquals(5, new ThrowablesTester().testAllThrowable(StaticThrowable.class)); } @Test - public void testNoConstructorsThrowable() { + void testNoConstructorsThrowable() { // this will not throw an error, but it should return 0, as there are // no matching constructors assertEquals(0, new ThrowablesTester().testAllThrowable(NoConstructorsThrowable.class)); } - @Test(expected = AssertionError.class) - public void testIgnoreMessageThrowable() { - new ThrowablesTester().testAllThrowable(IgnoreMessageThrowable.class); + @Test + void testIgnoreMessageThrowable() { + ThrowablesTester tester = new ThrowablesTester(); + assertThatThrownBy(() -> tester.testAllThrowable(IgnoreMessageThrowable.class)) + .isInstanceOf(AssertionError.class); } - @Test(expected = AssertionError.class) - public void testIgnoreCauseThrowable() { - new ThrowablesTester().testAllThrowable(IgnoreCauseThrowable.class); + @Test + void testIgnoreCauseThrowable() { + ThrowablesTester tester = new ThrowablesTester(); + assertThatThrownBy(() -> tester.testAllThrowable(IgnoreCauseThrowable.class)) + .isInstanceOf(AssertionError.class); } - @Test(expected = AssertionError.class) - public void testAlwaysSuppressThrowable() { - new ThrowablesTester().testAllThrowable(AlwaysSuppressThrowable.class); + @Test + void testAlwaysSuppressThrowable() { + ThrowablesTester tester = new ThrowablesTester(); + assertThatThrownBy(() -> tester.testAllThrowable(AlwaysSuppressThrowable.class)) + .isInstanceOf(AssertionError.class); } - @Test(expected = AssertionError.class) - public void testNeverSuppressThrowable() { - new ThrowablesTester().testAllThrowable(NeverSuppressThrowable.class); + @Test + void testNeverSuppressThrowable() { + ThrowablesTester tester = new ThrowablesTester(); + assertThatThrownBy(() -> tester.testAllThrowable(NeverSuppressThrowable.class)) + .isInstanceOf(AssertionError.class); } - @Test(expected = AssertionError.class) - public void testAlwaysWritableThrowable() { - new ThrowablesTester().testAllThrowable(AlwaysWritableThrowable.class); + @Test + void testAlwaysWritableThrowable() { + ThrowablesTester tester = new ThrowablesTester(); + assertThatThrownBy(() -> tester.testAllThrowable(AlwaysWritableThrowable.class)) + .isInstanceOf(AssertionError.class); } - @Test(expected = AssertionError.class) - public void testNeverWritableThrowable() { - new ThrowablesTester().testAllThrowable(NeverWritableThrowable.class); + @Test + void testNeverWritableThrowable() { + ThrowablesTester tester = new ThrowablesTester(); + assertThatThrownBy(() -> tester.testAllThrowable(NeverWritableThrowable.class)) + .isInstanceOf(AssertionError.class); } - @Test(expected = ConstructionError.class) - public void testThrowInstantiationException() { - new ThrowablesTester().testAllThrowable(ThrowInstantiationThrowable.class); + @Test + void testThrowInstantiationException() { + ThrowablesTester tester = new ThrowablesTester(); + assertThatThrownBy(() -> tester.testAllThrowable(ThrowInstantiationThrowable.class)) + .isInstanceOf(AssertionError.class); } /** diff --git a/utils-test/src/test/java/org/onap/policy/common/utils/test/log/logback/ExtractAppenderTest.java b/utils-test/src/test/java/org/onap/policy/common/utils/test/log/logback/ExtractAppenderTest.java index 4c2237fc..9367209c 100644 --- a/utils-test/src/test/java/org/onap/policy/common/utils/test/log/logback/ExtractAppenderTest.java +++ b/utils-test/src/test/java/org/onap/policy/common/utils/test/log/logback/ExtractAppenderTest.java @@ -3,6 +3,7 @@ * Common Utils-Test * ================================================================================ * Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,8 +21,8 @@ package org.onap.policy.common.utils.test.log.logback; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import ch.qos.logback.classic.Level; import ch.qos.logback.classic.Logger; @@ -31,13 +32,13 @@ import java.util.LinkedList; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; -import org.junit.After; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.slf4j.LoggerFactory; -public class ExtractAppenderTest { +class ExtractAppenderTest { private static final String ABC_DIGIT = "abc[0-9]"; private static final String ABC_DIGIT1 = "abc[1-9]"; private static final String DEF_DIGIT = "def[0-9]"; @@ -58,13 +59,13 @@ public class ExtractAppenderTest { private List<Thread> threads; - @BeforeClass + @BeforeAll public static void setUpBeforeClass() { logger = (Logger) LoggerFactory.getLogger(ExtractAppenderTest.class); logger.setLevel(Level.INFO); } - @Before + @BeforeEach public void setUp() { threads = new LinkedList<>(); } @@ -72,7 +73,7 @@ public class ExtractAppenderTest { /** * Tear down all appenders and threads. */ - @After + @AfterEach public void tearDown() throws Exception { logger.detachAndStopAllAppenders(); @@ -83,7 +84,7 @@ public class ExtractAppenderTest { } @Test - public void testExtractAppender() { + void testExtractAppender() { AtomicInteger count = new AtomicInteger(0); ExtractAppender appender = new ExtractAppender() { @@ -117,7 +118,7 @@ public class ExtractAppenderTest { } @Test - public void testExtractAppenderStringArray() { + void testExtractAppenderStringArray() { AtomicInteger count = new AtomicInteger(0); ExtractAppender appender = new ExtractAppender(ABC_DIGIT, DEF_DIGIT) { @@ -156,7 +157,7 @@ public class ExtractAppenderTest { } @Test - public void testExtractAppenderQueueStringArray() { + void testExtractAppenderQueueStringArray() { // no. of matches allowed in the list int nallowed = 3; @@ -204,7 +205,7 @@ public class ExtractAppenderTest { } @Test - public void testAppendILoggingEvent_NoPatterns() { + void testAppendILoggingEvent_NoPatterns() { ExtractAppender appender = makeAppender(); logger.info(HELLO); @@ -214,7 +215,7 @@ public class ExtractAppenderTest { } @Test - public void testAppendILoggingEvent_Formatted() { + void testAppendILoggingEvent_Formatted() { ExtractAppender appender = makeAppender(); logger.info("hello {} world{}", "there", "!"); @@ -223,7 +224,7 @@ public class ExtractAppenderTest { } @Test - public void testAppendILoggingEvent_MatchFirstPattern() { + void testAppendILoggingEvent_MatchFirstPattern() { ExtractAppender appender = makeAppender(ABC_DIGIT, DEF_DIGIT); logger.info("hello abc1"); @@ -233,7 +234,7 @@ public class ExtractAppenderTest { } @Test - public void testAppendILoggingEvent_MatchLastPattern() { + void testAppendILoggingEvent_MatchLastPattern() { ExtractAppender appender = makeAppender(ABC_DIGIT, DEF_DIGIT); logger.info("hello def1"); @@ -243,7 +244,7 @@ public class ExtractAppenderTest { } @Test - public void testAppendILoggingEvent_Group1() { + void testAppendILoggingEvent_Group1() { ExtractAppender appender = makeAppender("hello (abc)|(xyz)", DEF_DIGIT); logger.info("hello abc, world!"); @@ -253,7 +254,7 @@ public class ExtractAppenderTest { } @Test - public void testAppendILoggingEvent_Group3() { + void testAppendILoggingEvent_Group3() { ExtractAppender appender = makeAppender("hello (abc)|(pdq)|(xyz)", DEF_DIGIT); logger.info("say hello xyz, world!"); @@ -263,7 +264,7 @@ public class ExtractAppenderTest { } @Test - public void testAppendILoggingEvent_NoGroup() { + void testAppendILoggingEvent_NoGroup() { ExtractAppender appender = makeAppender(HELLO_ABC); logger.info("say hello abc, world!"); @@ -273,7 +274,7 @@ public class ExtractAppenderTest { } @Test - public void testGetExtracted() { + void testGetExtracted() { ExtractAppender appender = makeAppender(ABC_DIGIT1); logger.info(HELLO_ABC1_WORLD); @@ -289,7 +290,7 @@ public class ExtractAppenderTest { } @Test - public void testClearExtractions() { + void testClearExtractions() { final ExtractAppender appender = makeAppender(ABC_DIGIT1); logger.info(HELLO_ABC1_WORLD); @@ -312,7 +313,7 @@ public class ExtractAppenderTest { } @Test - public void testSetPattern() { + void testSetPattern() { final ExtractAppender appender = makeAppender(ABC_DIGIT1); logger.info(HELLO_ABC1_WORLD); @@ -334,7 +335,7 @@ public class ExtractAppenderTest { * Launches threads doing everything in parallel to ensure nothing crashes. */ @Test - public void test_MultiThreaded() throws Exception { + void test_MultiThreaded() throws Exception { // when to stop long tend = System.currentTimeMillis() + 250; diff --git a/utils-test/src/test/java/org/onap/policy/common/utils/time/PeriodicItemTest.java b/utils-test/src/test/java/org/onap/policy/common/utils/time/PeriodicItemTest.java index 3e64edf3..14223b99 100644 --- a/utils-test/src/test/java/org/onap/policy/common/utils/time/PeriodicItemTest.java +++ b/utils-test/src/test/java/org/onap/policy/common/utils/time/PeriodicItemTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,15 +22,15 @@ package org.onap.policy.common.utils.time; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class PeriodicItemTest { +class PeriodicItemTest { private static final long DELAY_MS = 100L; private static final long PERIOD_MS = 200L; private static final Object ASSOCIATE = new Object(); @@ -41,7 +42,7 @@ public class PeriodicItemTest { /** * Sets up objects, including {@link #item}. */ - @Before + @BeforeEach public void setUp() { currentTime = new TestTime(); count = 0; @@ -49,18 +50,18 @@ public class PeriodicItemTest { } @Test - public void testBumpNextTime() { + void testBumpNextTime() { assertTrue(item.bumpNextTime()); assertEquals(currentTime.getMillis() + PERIOD_MS, item.getNextMs()); } @Test - public void testToString() { + void testToString() { assertNotNull(item.toString()); } @Test - public void testPeriodicItem() { + void testPeriodicItem() { assertSame(ASSOCIATE, item.getAssociate()); assertNotNull(item.getAction()); assertEquals(currentTime.getMillis() + DELAY_MS, item.getNextMs()); diff --git a/utils-test/src/test/java/org/onap/policy/common/utils/time/PseudoExecutorTest.java b/utils-test/src/test/java/org/onap/policy/common/utils/time/PseudoExecutorTest.java index 0046f791..d3c00da5 100644 --- a/utils-test/src/test/java/org/onap/policy/common/utils/time/PseudoExecutorTest.java +++ b/utils-test/src/test/java/org/onap/policy/common/utils/time/PseudoExecutorTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,25 +21,25 @@ package org.onap.policy.common.utils.time; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class PseudoExecutorTest { +class PseudoExecutorTest { private int invoked; private PseudoExecutor executor; - @Before + @BeforeEach public void setUp() { invoked = 0; executor = new PseudoExecutor(); } @Test - public void test() { + void test() { assertEquals(0, executor.getQueueLength()); assertEquals(0, executor.getTasks().size()); assertTrue(executor.runAll(0)); diff --git a/utils-test/src/test/java/org/onap/policy/common/utils/time/PseudoScheduledExecutorServiceTest.java b/utils-test/src/test/java/org/onap/policy/common/utils/time/PseudoScheduledExecutorServiceTest.java index 745e989f..5969f1fb 100644 --- a/utils-test/src/test/java/org/onap/policy/common/utils/time/PseudoScheduledExecutorServiceTest.java +++ b/utils-test/src/test/java/org/onap/policy/common/utils/time/PseudoScheduledExecutorServiceTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,10 +22,10 @@ package org.onap.policy.common.utils.time; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Collections; import java.util.List; @@ -32,10 +33,10 @@ import java.util.concurrent.Callable; import java.util.concurrent.Future; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.TimeUnit; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class PseudoScheduledExecutorServiceTest { +class PseudoScheduledExecutorServiceTest { private static final long DELAY_MS = 100L; private static final long PERIOD_MS = 200L; private static final List<Callable<Object>> EMPTY_CALLABLES = Collections.emptyList(); @@ -48,7 +49,7 @@ public class PseudoScheduledExecutorServiceTest { /** * Sets up objects, including {@link #svc}. */ - @Before + @BeforeEach public void setUp() { ran = 0; called = 0; @@ -57,7 +58,7 @@ public class PseudoScheduledExecutorServiceTest { } @Test - public void testShutdown() { + void testShutdown() { // submit some tasks svc.submit(new MyRun()); svc.schedule(new MyRun(), 1L, TimeUnit.SECONDS); @@ -70,7 +71,7 @@ public class PseudoScheduledExecutorServiceTest { } @Test - public void testShutdownNow() { + void testShutdownNow() { // submit some tasks svc.submit(new MyRun()); svc.schedule(new MyRun(), 1L, TimeUnit.SECONDS); @@ -83,7 +84,7 @@ public class PseudoScheduledExecutorServiceTest { } @Test - public void testIsShutdown_testIsTerminated() { + void testIsShutdown_testIsTerminated() { assertFalse(svc.isShutdown()); assertFalse(svc.isTerminated()); @@ -93,7 +94,7 @@ public class PseudoScheduledExecutorServiceTest { } @Test - public void testAwaitTermination() throws InterruptedException { + void testAwaitTermination() throws InterruptedException { assertFalse(svc.awaitTermination(1L, TimeUnit.SECONDS)); svc.shutdown(); @@ -101,7 +102,7 @@ public class PseudoScheduledExecutorServiceTest { } @Test - public void testSubmitCallableOfT() throws Exception { + void testSubmitCallableOfT() throws Exception { Future<Integer> future = svc.submit(new MyCallable()); currentTime.runOneTask(0); @@ -113,7 +114,7 @@ public class PseudoScheduledExecutorServiceTest { } @Test - public void testSubmitRunnableT() throws Exception { + void testSubmitRunnableT() throws Exception { Future<Integer> future = svc.submit(new MyRun(), 2); currentTime.runOneTask(0); @@ -125,7 +126,7 @@ public class PseudoScheduledExecutorServiceTest { } @Test - public void testSubmitRunnable() throws Exception { + void testSubmitRunnable() throws Exception { assertNotNull(svc.submit(new MyRun())); currentTime.runOneTask(0); @@ -136,31 +137,31 @@ public class PseudoScheduledExecutorServiceTest { } @Test - public void testInvokeAllCollectionOfQextendsCallableOfT() { + void testInvokeAllCollectionOfQextendsCallableOfT() { assertThatThrownBy(() -> svc.invokeAll(EMPTY_CALLABLES)) .isInstanceOf(UnsupportedOperationException.class); } @Test - public void testInvokeAllCollectionOfQextendsCallableOfTLongTimeUnit() { + void testInvokeAllCollectionOfQextendsCallableOfTLongTimeUnit() { assertThatThrownBy(() -> svc.invokeAll(EMPTY_CALLABLES, 1, TimeUnit.MILLISECONDS)) .isInstanceOf(UnsupportedOperationException.class); } @Test - public void testInvokeAnyCollectionOfQextendsCallableOfT() { + void testInvokeAnyCollectionOfQextendsCallableOfT() { assertThatThrownBy(() -> svc.invokeAny(EMPTY_CALLABLES)) .isInstanceOf(UnsupportedOperationException.class); } @Test - public void testInvokeAnyCollectionOfQextendsCallableOfTLongTimeUnit() { + void testInvokeAnyCollectionOfQextendsCallableOfTLongTimeUnit() { assertThatThrownBy(() -> svc.invokeAny(EMPTY_CALLABLES, 1, TimeUnit.MILLISECONDS)) .isInstanceOf(UnsupportedOperationException.class); } @Test - public void testExecute() throws InterruptedException { + void testExecute() throws InterruptedException { svc.execute(new MyRun()); currentTime.runOneTask(0); @@ -171,7 +172,7 @@ public class PseudoScheduledExecutorServiceTest { } @Test - public void testScheduleRunnableLongTimeUnit() throws InterruptedException { + void testScheduleRunnableLongTimeUnit() throws InterruptedException { assertNotNull(svc.schedule(new MyRun(), DELAY_MS, TimeUnit.MILLISECONDS)); assertEquals(DELAY_MS, oneTaskElapsedTime()); @@ -182,7 +183,7 @@ public class PseudoScheduledExecutorServiceTest { } @Test - public void testScheduleCallableOfVLongTimeUnit() throws Exception { + void testScheduleCallableOfVLongTimeUnit() throws Exception { ScheduledFuture<Integer> future = svc.schedule(new MyCallable(), DELAY_MS, TimeUnit.MILLISECONDS); assertEquals(DELAY_MS, oneTaskElapsedTime()); @@ -194,7 +195,7 @@ public class PseudoScheduledExecutorServiceTest { } @Test - public void testScheduleAtFixedRate() throws InterruptedException { + void testScheduleAtFixedRate() throws InterruptedException { final ScheduledFuture<?> future = svc.scheduleAtFixedRate(new MyRun(), DELAY_MS, PERIOD_MS, TimeUnit.MILLISECONDS); @@ -218,7 +219,7 @@ public class PseudoScheduledExecutorServiceTest { } @Test - public void testScheduleWithFixedDelay() throws InterruptedException { + void testScheduleWithFixedDelay() throws InterruptedException { final ScheduledFuture<?> future = svc.scheduleWithFixedDelay(new MyRun(), DELAY_MS, PERIOD_MS, TimeUnit.MILLISECONDS); diff --git a/utils-test/src/test/java/org/onap/policy/common/utils/time/PseudoScheduledFutureTest.java b/utils-test/src/test/java/org/onap/policy/common/utils/time/PseudoScheduledFutureTest.java index 248edf61..31156af9 100644 --- a/utils-test/src/test/java/org/onap/policy/common/utils/time/PseudoScheduledFutureTest.java +++ b/utils-test/src/test/java/org/onap/policy/common/utils/time/PseudoScheduledFutureTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,23 +21,24 @@ package org.onap.policy.common.utils.time; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import java.util.concurrent.Delayed; import java.util.concurrent.TimeUnit; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) -public class PseudoScheduledFutureTest { +@ExtendWith(MockitoExtension.class) +class PseudoScheduledFutureTest { private static final long DELAY_MS = 1000L; private int count; @@ -49,9 +51,9 @@ public class PseudoScheduledFutureTest { /** * Sets up objects, including {@link #future}. */ - @Before + @BeforeEach public void setUp() { - when(work.getDelay()).thenReturn(DELAY_MS); + lenient().when(work.getDelay()).thenReturn(DELAY_MS); count = 0; future = new PseudoScheduledFuture<>(() -> ++count, true); @@ -59,7 +61,7 @@ public class PseudoScheduledFutureTest { } @Test - public void testRun() { + void testRun() { // verify with a periodic task - should execute twice count = 0; future.run(); @@ -75,7 +77,7 @@ public class PseudoScheduledFutureTest { } @Test - public void testPseudoScheduledFutureRunnableTBoolean() throws Exception { + void testPseudoScheduledFutureRunnableTBoolean() throws Exception { final Integer result = 100; future = new PseudoScheduledFuture<>(() -> ++count, result, true); assertTrue(future.isPeriodic()); @@ -94,7 +96,7 @@ public class PseudoScheduledFutureTest { } @Test - public void testPseudoScheduledFutureCallableOfTBoolean() throws Exception { + void testPseudoScheduledFutureCallableOfTBoolean() throws Exception { assertTrue(future.isPeriodic()); future.run(); future.run(); @@ -111,13 +113,13 @@ public class PseudoScheduledFutureTest { } @Test - public void testGetDelay() { + void testGetDelay() { assertEquals(DELAY_MS, future.getDelay(TimeUnit.MILLISECONDS)); assertEquals(TimeUnit.MILLISECONDS.toSeconds(DELAY_MS), future.getDelay(TimeUnit.SECONDS)); } @Test - public void testCompareTo() { + void testCompareTo() { Delayed delayed = mock(Delayed.class); when(delayed.getDelay(TimeUnit.MILLISECONDS)).thenReturn(DELAY_MS + 1); @@ -125,18 +127,18 @@ public class PseudoScheduledFutureTest { } @Test - public void testIsPeriodic() { + void testIsPeriodic() { assertTrue(future.isPeriodic()); assertFalse(new PseudoScheduledFuture<>(() -> ++count, false).isPeriodic()); } @Test - public void testGetWorkItem() { + void testGetWorkItem() { assertSame(work, future.getWorkItem()); } @Test - public void testSetWorkItem() { + void testSetWorkItem() { work = mock(WorkItem.class); future.setWorkItem(work); assertSame(work, future.getWorkItem()); diff --git a/utils-test/src/test/java/org/onap/policy/common/utils/time/PseudoTimerTest.java b/utils-test/src/test/java/org/onap/policy/common/utils/time/PseudoTimerTest.java index d7316c1f..69e54524 100644 --- a/utils-test/src/test/java/org/onap/policy/common/utils/time/PseudoTimerTest.java +++ b/utils-test/src/test/java/org/onap/policy/common/utils/time/PseudoTimerTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,16 +22,16 @@ package org.onap.policy.common.utils.time; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Date; import java.util.TimerTask; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class PseudoTimerTest { +class PseudoTimerTest { private static final long DELAY_MS = 1000L; private static final long PERIOD_MS = 2000L; @@ -41,7 +42,7 @@ public class PseudoTimerTest { /** * Sets up objects, including {@link #timer}. */ - @Before + @BeforeEach public void setUp() { count = 0; currentTime = new TestTimeMulti(); @@ -49,7 +50,7 @@ public class PseudoTimerTest { } @Test - public void testCancel() { + void testCancel() { // schedule two tasks timer.scheduleAtFixedRate(new MyTask(), DELAY_MS, PERIOD_MS); timer.schedule(new MyTask(), DELAY_MS); @@ -64,13 +65,13 @@ public class PseudoTimerTest { } @Test - public void testPurge() { + void testPurge() { assertEquals(0, timer.purge()); assertEquals(0, timer.purge()); } @Test - public void testScheduleTimerTaskLong() throws InterruptedException { + void testScheduleTimerTaskLong() throws InterruptedException { timer.schedule(new MyTask(), DELAY_MS); assertFalse(currentTime.isEmpty()); @@ -82,14 +83,14 @@ public class PseudoTimerTest { } @Test - public void testScheduleTimerTaskDate() { + void testScheduleTimerTaskDate() { MyTask task = new MyTask(); Date curdate = new Date(); assertThatThrownBy(() -> timer.schedule(task, curdate)).isInstanceOf(UnsupportedOperationException.class); } @Test - public void testScheduleTimerTaskLongLong() throws InterruptedException { + void testScheduleTimerTaskLongLong() throws InterruptedException { timer.schedule(new MyTask(), DELAY_MS, PERIOD_MS); assertFalse(currentTime.isEmpty()); @@ -105,14 +106,14 @@ public class PseudoTimerTest { } @Test - public void testScheduleTimerTaskDateLong() { + void testScheduleTimerTaskDateLong() { MyTask task = new MyTask(); Date curdate = new Date(); assertThatThrownBy(() -> timer.schedule(task, curdate, 1L)).isInstanceOf(UnsupportedOperationException.class); } @Test - public void testScheduleAtFixedRateTimerTaskLongLong() throws InterruptedException { + void testScheduleAtFixedRateTimerTaskLongLong() throws InterruptedException { timer.scheduleAtFixedRate(new MyTask(), DELAY_MS, PERIOD_MS); assertFalse(currentTime.isEmpty()); @@ -128,7 +129,7 @@ public class PseudoTimerTest { } @Test - public void testScheduleAtFixedRateTimerTaskDateLong() { + void testScheduleAtFixedRateTimerTaskDateLong() { MyTask task = new MyTask(); Date curdate = new Date(); assertThatThrownBy(() -> timer.scheduleAtFixedRate(task, curdate, 1L)) diff --git a/utils-test/src/test/java/org/onap/policy/common/utils/time/RunnableItemTest.java b/utils-test/src/test/java/org/onap/policy/common/utils/time/RunnableItemTest.java index e7bbd018..e35c58fa 100644 --- a/utils-test/src/test/java/org/onap/policy/common/utils/time/RunnableItemTest.java +++ b/utils-test/src/test/java/org/onap/policy/common/utils/time/RunnableItemTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,17 +21,17 @@ package org.onap.policy.common.utils.time; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.concurrent.FutureTask; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class RunnableItemTest { +class RunnableItemTest { private static final long DELAY_MS = 100L; private static final Object ASSOCIATE = new Object(); @@ -41,7 +42,7 @@ public class RunnableItemTest { /** * Sets up objects, including {@link #item}. */ - @Before + @BeforeEach public void setUp() { currentTime = new TestTime(); count = 0; @@ -49,7 +50,7 @@ public class RunnableItemTest { } @Test - public void testWasCancelled() { + void testWasCancelled() { assertFalse(item.wasCancelled()); FutureTask<Object> future = new FutureTask<>(() -> count++); @@ -61,13 +62,13 @@ public class RunnableItemTest { } @Test - public void testIsAssociatedWith() { + void testIsAssociatedWith() { assertFalse(item.isAssociatedWith(this)); assertTrue(item.isAssociatedWith(ASSOCIATE)); } @Test - public void testFire() { + void testFire() { item.fire(); assertEquals(1, count); @@ -78,7 +79,7 @@ public class RunnableItemTest { } @Test - public void testRunnableItem_testGetAssociate_testGetAction() { + void testRunnableItem_testGetAssociate_testGetAction() { assertSame(ASSOCIATE, item.getAssociate()); assertNotNull(item.getAction()); assertEquals(currentTime.getMillis() + DELAY_MS, item.getNextMs()); @@ -96,7 +97,7 @@ public class RunnableItemTest { } @Test - public void testToString() { + void testToString() { assertNotNull(item.toString()); } } diff --git a/utils-test/src/test/java/org/onap/policy/common/utils/time/SleepItemTest.java b/utils-test/src/test/java/org/onap/policy/common/utils/time/SleepItemTest.java index dbd54781..ad8f2fbd 100644 --- a/utils-test/src/test/java/org/onap/policy/common/utils/time/SleepItemTest.java +++ b/utils-test/src/test/java/org/onap/policy/common/utils/time/SleepItemTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,17 +21,17 @@ package org.onap.policy.common.utils.time; -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.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class SleepItemTest { +class SleepItemTest { private static final int SLEEP_MS = 250; private static final long MAX_WAIT_MS = 5000L; @@ -44,7 +45,7 @@ public class SleepItemTest { /** * Sets up objects, including {@link #item}. */ - @Before + @BeforeEach public void setUp() { currentTime = new TestTime(); started = new CountDownLatch(1); @@ -70,7 +71,7 @@ public class SleepItemTest { } @Test - public void testInterrupt() throws InterruptedException { + void testInterrupt() throws InterruptedException { startThread(); item.interrupt(); @@ -80,7 +81,7 @@ public class SleepItemTest { } @Test - public void testFire_testAwait() throws InterruptedException { + void testFire_testAwait() throws InterruptedException { startThread(); // verify that it hasn't finished yet @@ -95,12 +96,12 @@ public class SleepItemTest { } @Test - public void testSleepItem() { + void testSleepItem() { assertEquals(currentTime.getMillis() + SLEEP_MS, item.getNextMs()); } @Test - public void testToString() { + void testToString() { assertNotNull(item.toString()); } diff --git a/utils-test/src/test/java/org/onap/policy/common/utils/time/TestTimeMultiTest.java b/utils-test/src/test/java/org/onap/policy/common/utils/time/TestTimeMultiTest.java index 8b6501a7..f6d1e6a4 100644 --- a/utils-test/src/test/java/org/onap/policy/common/utils/time/TestTimeMultiTest.java +++ b/utils-test/src/test/java/org/onap/policy/common/utils/time/TestTimeMultiTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,11 +23,11 @@ package org.onap.policy.common.utils.time; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.awaitility.Awaitility.await; -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.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.concurrent.Callable; import java.util.concurrent.CountDownLatch; @@ -35,23 +36,23 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class TestTimeMultiTest { +class TestTimeMultiTest { private static final long SHORT_WAIT_MS = 100L; private static final long DELAY_MS = 500L; private static final long MAX_WAIT_MS = 5000L; private TestTimeMulti multi; - @Before + @BeforeEach public void setUp() { multi = new TestTimeMulti(); } @Test - public void testSleep() throws InterruptedException { + void testSleep() throws InterruptedException { // negative sleep time final long tbegin = multi.getMillis(); MyThread thread = new MyThread(-5); @@ -81,17 +82,17 @@ public class TestTimeMultiTest { } @Test - public void testTestTimeMulti() { + void testTestTimeMulti() { assertTrue(multi.getMaxWaitMs() > 0); } @Test - public void testTestTimeMultiLong() { + void testTestTimeMultiLong() { assertEquals(200, new TestTimeMulti(200).getMaxWaitMs()); } @Test - public void testIsEmpty_testQueueLength() throws InterruptedException { + void testIsEmpty_testQueueLength() throws InterruptedException { assertTrue(multi.isEmpty()); // queue up two items @@ -114,7 +115,7 @@ public class TestTimeMultiTest { } @Test - public void testDestroy() throws InterruptedException { + void testDestroy() throws InterruptedException { // this won't interrupt multi.enqueue(new WorkItem(multi, DELAY_MS)); @@ -143,7 +144,7 @@ public class TestTimeMultiTest { } @Test - public void testRunOneTask() throws InterruptedException { + void testRunOneTask() throws InterruptedException { // nothing in the queue yet assertFalse(multi.runOneTask(0)); @@ -163,7 +164,7 @@ public class TestTimeMultiTest { } @Test - public void testWaitFor() throws InterruptedException { + void testWaitFor() throws InterruptedException { // queue up a couple of items multi.enqueue(new WorkItem(multi, DELAY_MS)); multi.enqueue(new WorkItem(multi, DELAY_MS * 2)); @@ -179,7 +180,7 @@ public class TestTimeMultiTest { } @Test - public void testWaitFor_EmptyQueue() throws InterruptedException { + void testWaitFor_EmptyQueue() throws InterruptedException { multi = new TestTimeMulti(SHORT_WAIT_MS); final long realBegin = System.currentTimeMillis(); @@ -192,7 +193,7 @@ public class TestTimeMultiTest { } @Test - public void testWaitUntilCallable() throws InterruptedException { + void testWaitUntilCallable() throws InterruptedException { multi.enqueue(new WorkItem(multi, DELAY_MS)); multi.enqueue(new WorkItem(multi, DELAY_MS * 2)); multi.enqueue(new WorkItem(multi, DELAY_MS * 3)); @@ -209,7 +210,7 @@ public class TestTimeMultiTest { } @Test - public void testWaitUntilCallable_InterruptEx() throws InterruptedException { + void testWaitUntilCallable_InterruptEx() throws InterruptedException { multi = new TestTimeMulti(); Callable<Boolean> callable = () -> { @@ -237,7 +238,7 @@ public class TestTimeMultiTest { } @Test - public void testWaitUntilCallable_ConditionThrowsEx() throws InterruptedException { + void testWaitUntilCallable_ConditionThrowsEx() throws InterruptedException { multi = new TestTimeMulti(); Callable<Boolean> callable = () -> { @@ -252,7 +253,7 @@ public class TestTimeMultiTest { } @Test - public void testWaitUntilCallable_NeverSatisfied() throws InterruptedException { + void testWaitUntilCallable_NeverSatisfied() throws InterruptedException { multi = new TestTimeMulti(SHORT_WAIT_MS); final long realBegin = System.currentTimeMillis(); @@ -262,7 +263,7 @@ public class TestTimeMultiTest { } @Test - public void testWaitUntilLongTimeUnitCallable() throws InterruptedException { + void testWaitUntilLongTimeUnitCallable() throws InterruptedException { multi.enqueue(new WorkItem(multi, DELAY_MS)); multi.enqueue(new WorkItem(multi, DELAY_MS * 2)); multi.enqueue(new WorkItem(multi, DELAY_MS * 3)); @@ -279,7 +280,7 @@ public class TestTimeMultiTest { } @Test - public void testWaitUntilLongTimeUnitCallable_PseudoTimeExpires() throws InterruptedException { + void testWaitUntilLongTimeUnitCallable_PseudoTimeExpires() throws InterruptedException { multi.enqueue(new WorkItem(multi, DELAY_MS)); multi.enqueue(new WorkItem(multi, DELAY_MS * 2)); multi.enqueue(new WorkItem(multi, DELAY_MS * 3)); @@ -291,7 +292,7 @@ public class TestTimeMultiTest { } @Test - public void testRunItem() throws InterruptedException { + void testRunItem() throws InterruptedException { AtomicBoolean fired = new AtomicBoolean(false); multi.enqueue(new MyWorkItem(fired)); @@ -305,7 +306,7 @@ public class TestTimeMultiTest { } @Test - public void testRunItem_Rescheduled() throws InterruptedException { + void testRunItem_Rescheduled() throws InterruptedException { AtomicBoolean fired = new AtomicBoolean(false); multi.enqueue(new MyWorkItem(fired) { @@ -326,7 +327,7 @@ public class TestTimeMultiTest { } @Test - public void testRunItem_Canceled() throws InterruptedException { + void testRunItem_Canceled() throws InterruptedException { AtomicBoolean fired = new AtomicBoolean(false); multi.enqueue(new MyWorkItem(fired) { @@ -354,7 +355,7 @@ public class TestTimeMultiTest { } @Test - public void testEnqueue() throws InterruptedException { + void testEnqueue() throws InterruptedException { CountDownLatch started = new CountDownLatch(1); CountDownLatch finished = new CountDownLatch(1); AtomicReference<InterruptedException> ex = new AtomicReference<>(); @@ -390,7 +391,7 @@ public class TestTimeMultiTest { } @Test - public void testCancelItems() throws InterruptedException { + void testCancelItems() throws InterruptedException { AtomicBoolean fired1 = new AtomicBoolean(); multi.enqueue(new MyWorkItem(fired1)); @@ -420,7 +421,7 @@ public class TestTimeMultiTest { } @Test - public void testPurgeItems() throws InterruptedException { + void testPurgeItems() throws InterruptedException { AtomicBoolean fired = new AtomicBoolean(); // queue up two that are canceled, one that is not diff --git a/utils-test/src/test/java/org/onap/policy/common/utils/time/TestTimeTest.java b/utils-test/src/test/java/org/onap/policy/common/utils/time/TestTimeTest.java index d2cf6783..c3b69eb3 100644 --- a/utils-test/src/test/java/org/onap/policy/common/utils/time/TestTimeTest.java +++ b/utils-test/src/test/java/org/onap/policy/common/utils/time/TestTimeTest.java @@ -3,6 +3,7 @@ * Common Utils-Test * ================================================================================ * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,10 +21,10 @@ package org.onap.policy.common.utils.time; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestTimeTest { diff --git a/utils-test/src/test/java/org/onap/policy/common/utils/time/WorkItemTest.java b/utils-test/src/test/java/org/onap/policy/common/utils/time/WorkItemTest.java index d2fc8d58..f0229ca9 100644 --- a/utils-test/src/test/java/org/onap/policy/common/utils/time/WorkItemTest.java +++ b/utils-test/src/test/java/org/onap/policy/common/utils/time/WorkItemTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2024 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,17 +23,17 @@ package org.onap.policy.common.utils.time; import static org.assertj.core.api.Assertions.assertThatCode; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class WorkItemTest { private TestTime currentTime; private WorkItem item; - @Before + @BeforeEach public void setUp() { currentTime = new TestTime(); item = new WorkItem(currentTime, 0); |