diff options
49 files changed, 648 insertions, 623 deletions
diff --git a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/DroolsPdpMdcInfoTest.java b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/DroolsPdpMdcInfoTest.java index 96030962..ba72f36b 100644 --- a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/DroolsPdpMdcInfoTest.java +++ b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/DroolsPdpMdcInfoTest.java @@ -3,6 +3,7 @@ * ONAP Policy Engine - Common Modules * ================================================================================ * 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,19 +21,19 @@ package org.onap.policy.common.logging.eelf; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import com.att.eelf.configuration.Configuration; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class DroolsPdpMdcInfoTest { +class DroolsPdpMdcInfoTest { /** * Test method for {@link org.onap.policy.common.logging.eelf.DroolsPdpMdcInfo#getMdcInfo()}. */ @Test - public void testGetMdcInfo() { + void testGetMdcInfo() { DroolsPdpMdcInfo di = new DroolsPdpMdcInfo(); assertNotNull(di.getMdcInfo()); diff --git a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/ErrorCodeMapTest.java b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/ErrorCodeMapTest.java index c34d9696..764b41b2 100644 --- a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/ErrorCodeMapTest.java +++ b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/ErrorCodeMapTest.java @@ -4,6 +4,7 @@ * ================================================================================ * Copyright (C) 2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2020 AT&T. + * 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.logging.eelf; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.policy.common.logging.eelf.ErrorCodeMap.ErrorCodeInfo; -public class ErrorCodeMapTest { +class ErrorCodeMapTest { @Test - public void testGetErrorCodeInfo() { + void testGetErrorCodeInfo() { assertNotNull(ErrorCodeMap.getErrorCodeInfo(MessageCodes.EXCEPTION_ERROR)); assertNotNull(ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR)); assertNotNull(ErrorCodeMap.getErrorCodeInfo(MessageCodes.MISS_PROPERTY_ERROR)); @@ -46,13 +47,13 @@ public class ErrorCodeMapTest { } @Test - public void testErrorCodeInfoGetErrorCode() { + void testErrorCodeInfoGetErrorCode() { ErrorCodeInfo errorCodeInfo = ErrorCodeMap.getErrorCodeInfo(MessageCodes.EXCEPTION_ERROR); assertEquals("500", errorCodeInfo.getErrorCode()); } @Test - public void testErrorCodeInfoGetErrorDesc() { + void testErrorCodeInfoGetErrorDesc() { ErrorCodeInfo errorCodeInfo = ErrorCodeMap.getErrorCodeInfo(MessageCodes.EXCEPTION_ERROR); assertEquals("This is an exception error message during the process. Please check the error message for detail " + "information", errorCodeInfo.getErrorDesc()); diff --git a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventDataTest.java b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventDataTest.java index 882cc2cf..6e518c22 100644 --- a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventDataTest.java +++ b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventDataTest.java @@ -3,6 +3,7 @@ * ONAP Policy Engine - Common Modules * ================================================================================ * 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,14 +21,14 @@ package org.onap.policy.common.logging.eelf; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import java.time.Instant; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class EventDataTest { +class EventDataTest { private static final Instant istart = Instant.ofEpochMilli(100000L); private static final Instant iend = Instant.ofEpochMilli(200000L); @@ -35,7 +36,7 @@ public class EventDataTest { * Test method for {@link EventData#EventData()}. */ @Test - public void testEventData() { + void testEventData() { EventData eventData = new EventData(); assertNull(eventData.getEndTime()); @@ -47,7 +48,7 @@ public class EventDataTest { * Test method for {@link EventData#EventData(String, Instant, Instant)}. */ @Test - public void testEventDataStringInstantInstant() { + void testEventDataStringInstantInstant() { EventData eventData = new EventData("myreq", istart, iend); assertEquals("myreq", eventData.getRequestId()); @@ -59,7 +60,7 @@ public class EventDataTest { * Test method for {@link EventData#getRequestId()} and {@link EventData#setRequestId(String)}. */ @Test - public void testGetSetRequestId() { + void testGetSetRequestId() { EventData eventData = new EventData(); assertNull(eventData.getRequestId()); @@ -74,7 +75,7 @@ public class EventDataTest { * Test method for {@link EventData#getStartTime()} and {@link EventData#setStartTime(Instant)}. */ @Test - public void testGetSetStartTime() { + void testGetSetStartTime() { EventData eventData = new EventData(); assertNull(eventData.getStartTime()); @@ -93,7 +94,7 @@ public class EventDataTest { * Test method for {@link EventData#getEndTime()} and {@link EventData#setEndTime(Instant)}. */ @Test - public void testGetSetEndTime() { + void testGetSetEndTime() { EventData eventData = new EventData(); assertNull(eventData.getEndTime()); @@ -112,7 +113,7 @@ public class EventDataTest { * Test method for {@link EventData#toString()}. */ @Test - public void testToString() { + void testToString() { EventData eventData = new EventData("myreq", istart, iend); assertEquals("myreq Starting Time : 1970-01-01T00:01:40Z Ending Time : 1970-01-01T00:03:20Z", eventData.toString()); @@ -122,7 +123,7 @@ public class EventDataTest { * Test method for {@link EventData#hashCode()}. */ @Test - public void testHashCode() { + void testHashCode() { int hc1 = new EventData("abc", istart, iend).hashCode(); assertNotEquals(hc1, new EventData("abd", istart, iend).hashCode()); @@ -133,7 +134,7 @@ public class EventDataTest { * Test method for {@link EventData#equals(Object)}. */ @Test - public void testEqualsObject() { + void testEqualsObject() { final EventData d1 = new EventData("abc", istart, iend); final EventData d2 = new EventData("abd", istart, iend); final EventData d3 = new EventData("abc", iend, istart); @@ -142,15 +143,15 @@ public class EventDataTest { assertEquals(d1, d1); // compare with null - assertNotEquals(d1, null); + assertNotEquals(null, d1); // compare with request id // note: ignoring sonar because we want to test d1.equals(), not "abc".equals() assertEquals(d1, "abc"); // NOSONAR - assertNotEquals(d1, "abd"); + assertNotEquals("abd", d1); // compare with int - different class type - assertNotEquals(d1, 10); + assertNotEquals(10, d1); // "this" has null request id assertNotEquals(new EventData(), d1); diff --git a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventTrackInfoHandlerTest.java b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventTrackInfoHandlerTest.java index 2cc1e59e..92d24009 100644 --- a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventTrackInfoHandlerTest.java +++ b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventTrackInfoHandlerTest.java @@ -3,6 +3,7 @@ * ONAP Policy Engine - Common Modules * ================================================================================ * 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,15 +21,15 @@ package org.onap.policy.common.logging.eelf; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.time.Instant; import java.util.concurrent.ConcurrentMap; -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 EventTrackInfoHandlerTest { +class EventTrackInfoHandlerTest { private static final Instant inow = Instant.now(); private static final Instant iexpired = Instant.ofEpochMilli(10000L); @@ -41,7 +42,7 @@ public class EventTrackInfoHandlerTest { private EventTrackInfoHandler hdlr; - @BeforeClass + @BeforeAll public static void setUpBeforeClass() { tracker = PolicyLogger.getEventTracker(); info = tracker.getEventInfo(); @@ -50,21 +51,21 @@ public class EventTrackInfoHandlerTest { /** * Perform set up for test cases. */ - @Before - public void setUp() { + @BeforeEach + void setUp() { info.clear(); hdlr = new EventTrackInfoHandler(); } @Test - public void testNoEvents() { + void testNoEvents() { hdlr.run(); assertEquals(0, info.size()); } @Test - public void testNothingExpired() { + void testNothingExpired() { tracker.storeEventData(data1); tracker.storeEventData(data2); @@ -73,7 +74,7 @@ public class EventTrackInfoHandlerTest { } @Test - public void testSomeExpired() { + void testSomeExpired() { // not expired tracker.storeEventData(data1); tracker.storeEventData(data2); @@ -99,7 +100,7 @@ public class EventTrackInfoHandlerTest { } @Test - public void testMultipleRuns() { + void testMultipleRuns() { hdlr.run(); assertEquals(0, info.size()); diff --git a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventTrackInfoTest.java b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventTrackInfoTest.java index 0ca5feb5..49a3463f 100644 --- a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventTrackInfoTest.java +++ b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/EventTrackInfoTest.java @@ -3,6 +3,7 @@ * ONAP Policy Engine - Common Modules * ================================================================================ * 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,17 +21,17 @@ package org.onap.policy.common.logging.eelf; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -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.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.time.Instant; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class EventTrackInfoTest { +class EventTrackInfoTest { private static final Instant istart = Instant.ofEpochMilli(100000L); private static final Instant iend = Instant.ofEpochMilli(200000L); @@ -40,8 +41,8 @@ public class EventTrackInfoTest { private EventTrackInfo info; - @Before - public void setUp() { + @BeforeEach + void setUp() { info = new EventTrackInfo(); } @@ -50,7 +51,7 @@ public class EventTrackInfoTest { * Test method for {@link EventTrackInfo#EventTrackInfo()}. */ @Test - public void testEventTrackInfo() { + void testEventTrackInfo() { assertNotNull(info.getEventInfo()); } @@ -58,7 +59,7 @@ public class EventTrackInfoTest { * Test method for {@link EventTrackInfo#getEventDataByRequestId(String)}. */ @Test - public void testGetEventDataByRequestId() { + void testGetEventDataByRequestId() { info.storeEventData(data1); info.storeEventData(data2); @@ -71,7 +72,7 @@ public class EventTrackInfoTest { * Test method for {@link EventTrackInfo#storeEventData(EventData)}. */ @Test - public void testStoreEventData() { + void testStoreEventData() { // should ignore null info.storeEventData(null); assertTrue(info.getEventInfo().isEmpty()); @@ -100,7 +101,7 @@ public class EventTrackInfoTest { * Test method for {@link EventTrackInfo#remove(String)}. */ @Test - public void testRemove() { + void testRemove() { info.storeEventData(data1); info.storeEventData(data2); @@ -118,7 +119,7 @@ public class EventTrackInfoTest { * Test method for {@link EventTrackInfo#getEventInfo()}. */ @Test - public void testGetEventInfo() { + void testGetEventInfo() { info.storeEventData(data1); info.storeEventData(data2); diff --git a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/PolicyLoggerTest.java b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/PolicyLoggerTest.java index 62fcfaf4..d7239f4e 100644 --- a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/PolicyLoggerTest.java +++ b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/PolicyLoggerTest.java @@ -4,7 +4,7 @@ * ================================================================================ * Copyright (C) 2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2023 Nordix Foundation. + * Modifications 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. @@ -32,11 +32,11 @@ import static com.att.eelf.configuration.Configuration.MDC_SERVER_IP_ADDRESS; import static com.att.eelf.configuration.Configuration.MDC_SERVICE_INSTANCE_ID; import static com.att.eelf.configuration.Configuration.MDC_SERVICE_NAME; import static org.assertj.core.api.Assertions.assertThatCode; -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 static org.mockito.Mockito.never; import static org.onap.policy.common.logging.eelf.OnapConfigProperties.PARTNER_NAME; import static org.onap.policy.common.logging.eelf.OnapConfigProperties.RESPONSE_CODE; @@ -49,26 +49,26 @@ import com.att.eelf.configuration.EELFLogger.Level; import java.time.Instant; import java.util.Properties; import java.util.UUID; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.slf4j.MDC; import org.springframework.test.util.ReflectionTestUtils; -public class PolicyLoggerTest { +class PolicyLoggerTest { /** * Perform set up for test cases. */ - @Before - public void setUp() { + @BeforeEach + void setUp() { Properties properties = new Properties(); properties.setProperty("policy.component", "XACML"); PolicyLogger.init(properties); } @Test - public void testSetAndGetDebugLevelLevel() { + void testSetAndGetDebugLevelLevel() { PolicyLogger.setDebugLevel(Level.INFO); assertEquals(Level.INFO, PolicyLogger.getDebugLevel()); PolicyLogger.setDebugLevel(Level.DEBUG); @@ -76,7 +76,7 @@ public class PolicyLoggerTest { } @Test - public void testSetAndGetAuditLevelLevel() { + void testSetAndGetAuditLevelLevel() { PolicyLogger.setAuditLevel(Level.INFO); assertEquals(Level.INFO, PolicyLogger.getAuditLevel()); PolicyLogger.setAuditLevel(Level.DEBUG); @@ -84,7 +84,7 @@ public class PolicyLoggerTest { } @Test - public void testSetAndGetMetricsLevelLevel() { + void testSetAndGetMetricsLevelLevel() { PolicyLogger.setMetricsLevel(Level.INFO); assertEquals(Level.INFO, PolicyLogger.getMetricsLevel()); PolicyLogger.setMetricsLevel(Level.DEBUG); @@ -92,7 +92,7 @@ public class PolicyLoggerTest { } @Test - public void testSetAndGetErrorLevelLevel() { + void testSetAndGetErrorLevelLevel() { PolicyLogger.setErrorLevel(Level.INFO); assertEquals(Level.INFO, PolicyLogger.getErrorLevel()); PolicyLogger.setErrorLevel(Level.DEBUG); @@ -100,14 +100,14 @@ public class PolicyLoggerTest { } @Test - public void testSetAndGetClassname() { + void testSetAndGetClassname() { assertEquals("ClassName", PolicyLogger.getClassname()); PolicyLogger.setClassname("PolicyLoggerTest"); assertEquals("PolicyLoggerTest", PolicyLogger.getClassname()); } @Test - public void testPostMdcInfoForEventString() { + void testPostMdcInfoForEventString() { PolicyLogger.postMdcInfoForEvent("transactionId"); assertEquals("", MDC.get(MDC_REMOTE_HOST)); @@ -123,7 +123,7 @@ public class PolicyLoggerTest { } @Test - public void testPostMdcInfoForEventStringDrools() { + void testPostMdcInfoForEventStringDrools() { Properties properties = new Properties(); properties.setProperty("policy.component", "DROOLS"); PolicyLogger.init(properties); @@ -136,13 +136,13 @@ public class PolicyLoggerTest { } @Test - public void testSetAndGetTransId() { + void testSetAndGetTransId() { PolicyLogger.setTransId("123456"); assertEquals("123456", PolicyLogger.getTransId()); } @Test - public void testPostMdcInfoForEventObject() { + void testPostMdcInfoForEventObject() { PolicyLogger.postMdcInfoForEvent(1); assertEquals("", MDC.get(MDC_REMOTE_HOST)); @@ -158,7 +158,7 @@ public class PolicyLoggerTest { } @Test - public void testPostMdcInfoForTriggeredRule() { + void testPostMdcInfoForTriggeredRule() { PolicyLogger.postMdcInfoForTriggeredRule("transactionId"); assertEquals("", MDC.get(MDC_REMOTE_HOST)); @@ -173,7 +173,7 @@ public class PolicyLoggerTest { } @Test - public void testPostMdcUuidForTriggeredRule() { + void testPostMdcUuidForTriggeredRule() { PolicyLogger.postMdcUuidForTriggeredRule(1); assertEquals("", MDC.get(MDC_REMOTE_HOST)); @@ -188,7 +188,7 @@ public class PolicyLoggerTest { } @Test - public void testInfoMessageCodesStringStringArray() { + void testInfoMessageCodesStringStringArray() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger); PolicyLogger.info(MessageCodes.ERROR_DATA_ISSUE, "str1", "str2"); @@ -196,7 +196,7 @@ public class PolicyLoggerTest { } @Test - public void testInfoStringString() { + void testInfoStringString() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger); PolicyLogger.info("str1", "str2"); @@ -207,7 +207,7 @@ public class PolicyLoggerTest { } @Test - public void testInfoObject() { + void testInfoObject() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger); PolicyLogger.info("str1"); @@ -215,7 +215,7 @@ public class PolicyLoggerTest { } @Test - public void testInfoMessageCodesThrowableStringArray() { + void testInfoMessageCodesThrowableStringArray() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger); PolicyLogger.info(MessageCodes.ERROR_DATA_ISSUE, new NullPointerException(), "str1", "str2"); @@ -224,7 +224,7 @@ public class PolicyLoggerTest { } @Test - public void testInfoMessageCodesStringThrowableStringArray() { + void testInfoMessageCodesStringThrowableStringArray() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger); PolicyLogger.info(MessageCodes.ERROR_DATA_ISSUE, "PolicyLoggerTest", new NullPointerException(), "str1", @@ -234,7 +234,7 @@ public class PolicyLoggerTest { } @Test - public void testWarnMessageCodesStringStringArray() { + void testWarnMessageCodesStringStringArray() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger); PolicyLogger.warn(MessageCodes.ERROR_DATA_ISSUE, "str1"); @@ -242,7 +242,7 @@ public class PolicyLoggerTest { } @Test - public void testWarnStringString() { + void testWarnStringString() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger); PolicyLogger.warn("str1", "str2"); @@ -253,7 +253,7 @@ public class PolicyLoggerTest { } @Test - public void testWarnObject() { + void testWarnObject() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger); PolicyLogger.warn(1); @@ -261,7 +261,7 @@ public class PolicyLoggerTest { } @Test - public void testWarnMessageCodesThrowableStringArray() { + void testWarnMessageCodesThrowableStringArray() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger); PolicyLogger.warn(MessageCodes.ERROR_DATA_ISSUE, new NullPointerException(), "str1", "str2"); @@ -270,7 +270,7 @@ public class PolicyLoggerTest { } @Test - public void testWarnMessageCodesStringThrowableStringArray() { + void testWarnMessageCodesStringThrowableStringArray() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger); PolicyLogger.warn(MessageCodes.ERROR_DATA_ISSUE, "PolicyLoggerTest", new NullPointerException(), "str1", @@ -280,7 +280,7 @@ public class PolicyLoggerTest { } @Test - public void testWarnString() { + void testWarnString() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger); PolicyLogger.warn("str1"); @@ -288,7 +288,7 @@ public class PolicyLoggerTest { } @Test - public void testErrorStringString() { + void testErrorStringString() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger); PolicyLogger.error("str1", "str2"); @@ -302,7 +302,7 @@ public class PolicyLoggerTest { } @Test - public void testErrorString() { + void testErrorString() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger); PolicyLogger.error("str1"); @@ -314,7 +314,7 @@ public class PolicyLoggerTest { } @Test - public void testErrorObject() { + void testErrorObject() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger); PolicyLogger.error(1); @@ -326,7 +326,7 @@ public class PolicyLoggerTest { } @Test - public void testErrorMessageCodesThrowableStringArray() { + void testErrorMessageCodesThrowableStringArray() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger); PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, new NullPointerException(), "str1", "str2"); @@ -335,7 +335,7 @@ public class PolicyLoggerTest { } @Test - public void testErrorMessageCodesStringThrowableStringArray() { + void testErrorMessageCodesStringThrowableStringArray() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger); PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "PolicyLoggerTest", new NullPointerException(), "str1", @@ -345,7 +345,7 @@ public class PolicyLoggerTest { } @Test - public void testErrorMessageCodesStringArray() { + void testErrorMessageCodesStringArray() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger); PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "str1", "str2"); @@ -353,7 +353,7 @@ public class PolicyLoggerTest { } @Test - public void testDebugMessageCodesStringArray() { + void testDebugMessageCodesStringArray() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger); PolicyLogger.debug(MessageCodes.ERROR_DATA_ISSUE, "str1", "str2"); @@ -361,7 +361,7 @@ public class PolicyLoggerTest { } @Test - public void testDebugStringString() { + void testDebugStringString() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger); PolicyLogger.debug("str1", "str2"); @@ -372,7 +372,7 @@ public class PolicyLoggerTest { } @Test - public void testDebugString() { + void testDebugString() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger); PolicyLogger.debug("str1"); @@ -380,7 +380,7 @@ public class PolicyLoggerTest { } @Test - public void testDebugObject() { + void testDebugObject() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger); PolicyLogger.debug(1); @@ -388,7 +388,7 @@ public class PolicyLoggerTest { } @Test - public void testAuditStringObject() { + void testAuditStringObject() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "auditLogger", mockLogger); PolicyLogger.audit("PolicyLoggerTest", 1); @@ -401,7 +401,7 @@ public class PolicyLoggerTest { } @Test - public void testAuditObject() { + void testAuditObject() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "auditLogger", mockLogger); PolicyLogger.audit(1); @@ -411,7 +411,7 @@ public class PolicyLoggerTest { } @Test - public void testDebugMessageCodesThrowableStringArray() { + void testDebugMessageCodesThrowableStringArray() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger); PolicyLogger.debug(MessageCodes.ERROR_DATA_ISSUE, new NullPointerException(), "str1", "str2"); @@ -420,7 +420,7 @@ public class PolicyLoggerTest { } @Test - public void testDebugMessageCodesStringThrowableStringArray() { + void testDebugMessageCodesStringThrowableStringArray() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger); PolicyLogger.debug(MessageCodes.ERROR_DATA_ISSUE, "PolicyLoggerTest", new NullPointerException(), "str1", @@ -430,7 +430,7 @@ public class PolicyLoggerTest { } @Test - public void testIsDebugEnabled() { + void testIsDebugEnabled() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger); Mockito.when(mockLogger.isDebugEnabled()).thenReturn(false).thenReturn(true); @@ -439,7 +439,7 @@ public class PolicyLoggerTest { } @Test - public void testIsErrorEnabled() { + void testIsErrorEnabled() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger); Mockito.when(mockLogger.isErrorEnabled()).thenReturn(false).thenReturn(true); @@ -448,7 +448,7 @@ public class PolicyLoggerTest { } @Test - public void testIsWarnEnabled() { + void testIsWarnEnabled() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger); Mockito.when(mockLogger.isWarnEnabled()).thenReturn(false).thenReturn(true); @@ -457,7 +457,7 @@ public class PolicyLoggerTest { } @Test - public void testIsInfoEnabled1() { + void testIsInfoEnabled1() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger); Mockito.when(mockLogger.isInfoEnabled()).thenReturn(false).thenReturn(true); @@ -466,7 +466,7 @@ public class PolicyLoggerTest { } @Test - public void testIsAuditEnabled() { + void testIsAuditEnabled() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger); Mockito.when(mockLogger.isInfoEnabled()).thenReturn(false).thenReturn(true); @@ -475,7 +475,7 @@ public class PolicyLoggerTest { } @Test - public void testIsInfoEnabled() { + void testIsInfoEnabled() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger); Mockito.when(mockLogger.isInfoEnabled()).thenReturn(false).thenReturn(true); @@ -484,7 +484,7 @@ public class PolicyLoggerTest { } @Test - public void testTraceStringString() { + void testTraceStringString() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger); PolicyLogger.trace("str1", "str2"); @@ -492,7 +492,7 @@ public class PolicyLoggerTest { } @Test - public void testTraceObject() { + void testTraceObject() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger); PolicyLogger.trace(1); @@ -500,7 +500,7 @@ public class PolicyLoggerTest { } @Test - public void testRecordAuditEventStartAndEnd() { + void testRecordAuditEventStartAndEnd() { PolicyLogger.recordAuditEventStart("eventId"); assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get("eventId")); @@ -509,7 +509,7 @@ public class PolicyLoggerTest { } @Test - public void testRecordAuditEventStartAndEndUuid() { + void testRecordAuditEventStartAndEndUuid() { UUID uuid = UUID.randomUUID(); PolicyLogger.recordAuditEventStart(uuid);; assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get(uuid.toString())); @@ -520,7 +520,7 @@ public class PolicyLoggerTest { @Test - public void testRecordAuditEventEndStringStringString() { + void testRecordAuditEventEndStringStringString() { PolicyLogger.recordAuditEventStart("eventId"); assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get("eventId")); @@ -529,7 +529,7 @@ public class PolicyLoggerTest { } @Test - public void testRecordAuditEventEndUuidStringString() { + void testRecordAuditEventEndUuidStringString() { UUID uuid = UUID.randomUUID(); PolicyLogger.recordAuditEventStart(uuid);; assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get(uuid.toString())); @@ -540,7 +540,7 @@ public class PolicyLoggerTest { @Test - public void testCreatAuditEventTrackingRecordStringStringString() { + void testCreatAuditEventTrackingRecordStringStringString() { PolicyLogger.recordAuditEventStart("eventId"); assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get("eventId")); @@ -549,7 +549,7 @@ public class PolicyLoggerTest { } @Test - public void testCreatAuditEventTrackingRecordUuidString() { + void testCreatAuditEventTrackingRecordUuidString() { UUID uuid = UUID.randomUUID(); PolicyLogger.recordAuditEventStart(uuid);; assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get(uuid.toString())); @@ -559,32 +559,32 @@ public class PolicyLoggerTest { } @Test - public void testRecordAuditEventStartToEnd() { + void testRecordAuditEventStartToEnd() { PolicyLogger.recordAuditEventStartToEnd("eventId", "rule", Instant.now(), Instant.now(), "policyVersion"); assertEquals("eventId", MDC.get(MDC_KEY_REQUEST_ID)); } @Test - public void testRecordMetricEventStringString() { + void testRecordMetricEventStringString() { PolicyLogger.recordMetricEvent("eventId", "str1"); assertEquals("eventId", MDC.get(MDC_KEY_REQUEST_ID)); } @Test - public void testRecordMetricEventStringStringString() { + void testRecordMetricEventStringStringString() { PolicyLogger.recordMetricEvent("eventId", "PolicyLoggerTest", "str1"); assertEquals("eventId", MDC.get(MDC_KEY_REQUEST_ID)); } @Test - public void testRecordMetricEventUuidString() { + void testRecordMetricEventUuidString() { UUID uuid = UUID.randomUUID(); PolicyLogger.recordMetricEvent(uuid, "str1"); assertEquals(uuid.toString(), MDC.get(MDC_KEY_REQUEST_ID)); } @Test - public void testRecordMetricEventString() { + void testRecordMetricEventString() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "metricsLogger", mockLogger); PolicyLogger.recordMetricEvent("eventId"); @@ -593,7 +593,7 @@ public class PolicyLoggerTest { } @Test - public void testMetricsString() { + void testMetricsString() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "metricsLogger", mockLogger); PolicyLogger.metrics("str1"); @@ -602,7 +602,7 @@ public class PolicyLoggerTest { } @Test - public void testMetricsStringObject() { + void testMetricsStringObject() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "metricsLogger", mockLogger); PolicyLogger.metrics("PolicyLoggerTest", 1); @@ -614,7 +614,7 @@ public class PolicyLoggerTest { } @Test - public void testMetricsObject() { + void testMetricsObject() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "metricsLogger", mockLogger); PolicyLogger.metrics(1); @@ -623,7 +623,7 @@ public class PolicyLoggerTest { } @Test - public void testMetricsPrintln() { + void testMetricsPrintln() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "metricsLogger", mockLogger); PolicyLogger.metricsPrintln("str1"); @@ -631,12 +631,12 @@ public class PolicyLoggerTest { } @Test - public void testInitNullProperties() { + void testInitNullProperties() { assertThatCode(() -> PolicyLogger.init(null)).doesNotThrowAnyException(); } @Test - public void testInit() { + void testInit() { Properties properties = new Properties(); properties.setProperty("override.logback.level.setup", "true"); properties.setProperty("metricsLogger.level", "OFF"); @@ -653,56 +653,56 @@ public class PolicyLoggerTest { } @Test - public void testSetDebugLevelString() { + void testSetDebugLevelString() { PolicyLogger.setOverrideLogbackLevel(true); PolicyLogger.setDebugLevel("TRACE"); assertEquals(Level.TRACE, PolicyLogger.getDebugLevel()); } @Test - public void testSetErrorLevelStringOff() { + void testSetErrorLevelStringOff() { PolicyLogger.setOverrideLogbackLevel(true); PolicyLogger.setErrorLevel("OFF"); assertEquals(Level.OFF, PolicyLogger.getErrorLevel()); } @Test - public void testSetErrorLevelStringOther() { + void testSetErrorLevelStringOther() { PolicyLogger.setOverrideLogbackLevel(true); PolicyLogger.setErrorLevel("INFO"); assertEquals(Level.ERROR, PolicyLogger.getErrorLevel()); } @Test - public void testSetMetricsLevelStringOff() { + void testSetMetricsLevelStringOff() { PolicyLogger.setOverrideLogbackLevel(true); PolicyLogger.setMetricsLevel("OFF"); assertEquals(Level.OFF, PolicyLogger.getMetricsLevel()); } @Test - public void testSetMetricsLevelStringOther() { + void testSetMetricsLevelStringOther() { PolicyLogger.setOverrideLogbackLevel(true); PolicyLogger.setMetricsLevel("ERROR"); assertEquals(Level.INFO, PolicyLogger.getMetricsLevel()); } @Test - public void testSetAuditLevelStringOff() { + void testSetAuditLevelStringOff() { PolicyLogger.setOverrideLogbackLevel(true); PolicyLogger.setAuditLevel("OFF"); assertEquals(Level.OFF, PolicyLogger.getAuditLevel()); } @Test - public void testSetAuditLevelStringOther() { + void testSetAuditLevelStringOther() { PolicyLogger.setOverrideLogbackLevel(true); PolicyLogger.setAuditLevel("ERROR"); assertEquals(Level.INFO, PolicyLogger.getAuditLevel()); } @Test - public void testSetAndIsOverrideLogbackLevel() { + void testSetAndIsOverrideLogbackLevel() { PolicyLogger.setOverrideLogbackLevel(false); assertFalse(PolicyLogger.isOverrideLogbackLevel()); PolicyLogger.setOverrideLogbackLevel(true); @@ -710,7 +710,7 @@ public class PolicyLoggerTest { } @Test - public void testSetServerInfo() { + void testSetServerInfo() { PolicyLogger.setServerInfo("serverHost", "serverPort"); assertEquals("serverHost:serverPort", MDC.get(SERVER_NAME)); } diff --git a/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/EelfLoggerTest.java b/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/EelfLoggerTest.java index 1d77451b..66b48e07 100644 --- a/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/EelfLoggerTest.java +++ b/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/EelfLoggerTest.java @@ -4,7 +4,7 @@ * ================================================================================ * Copyright (C) 2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2023 Nordix Foundation. + * Modifications 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. @@ -23,75 +23,75 @@ package org.onap.policy.common.logging.flexlogger; import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID; -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 static org.mockito.Mockito.never; import com.att.eelf.configuration.EELFLogger; import java.util.UUID; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.onap.policy.common.logging.eelf.MessageCodes; import org.onap.policy.common.logging.eelf.PolicyLogger; import org.slf4j.MDC; import org.springframework.test.util.ReflectionTestUtils; -public class EelfLoggerTest { +class EelfLoggerTest { EelfLogger eelfLogger = new EelfLogger("EelfLoggerTest", "transactionId"); @Test - public void testEelfLoggerClassOfQ() { + void testEelfLoggerClassOfQ() { new EelfLogger(this.getClass()); assertNotNull(PolicyLogger.getTransId()); assertFalse(PolicyLogger.getTransId().isEmpty()); } @Test - public void testEelfLoggerString() { + void testEelfLoggerString() { new EelfLogger("EelfLoggerTest"); assertNotNull(PolicyLogger.getTransId()); assertFalse(PolicyLogger.getTransId().isEmpty()); } @Test - public void testEelfLoggerClassOfQBoolean() { + void testEelfLoggerClassOfQBoolean() { new EelfLogger(this.getClass(), true); assertNotNull(PolicyLogger.getTransId()); assertFalse(PolicyLogger.getTransId().isEmpty()); } @Test - public void testEelfLoggerStringBoolean() { + void testEelfLoggerStringBoolean() { new EelfLogger("EelfLoggerTest", true); assertNotNull(PolicyLogger.getTransId()); assertFalse(PolicyLogger.getTransId().isEmpty()); } @Test - public void testEelfLoggerClassOfQString() { + void testEelfLoggerClassOfQString() { new EelfLogger(this.getClass(), "transactionId"); assertEquals("transactionId", PolicyLogger.getTransId()); } @Test - public void testEelfLoggerStringString() { + void testEelfLoggerStringString() { new EelfLogger("EelfLoggerTest", "transactionId"); assertEquals("transactionId", PolicyLogger.getTransId()); } @Test - public void testSetAndGetTransId() { + void testSetAndGetTransId() { assertEquals("transactionId", eelfLogger.getTransId()); eelfLogger.setTransId("transactionId2"); assertEquals("transactionId2", eelfLogger.getTransId()); } @Test - public void testDebugObject() { + void testDebugObject() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger); eelfLogger.debug("message"); @@ -102,7 +102,7 @@ public class EelfLoggerTest { } @Test - public void testErrorObject() { + void testErrorObject() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger); eelfLogger.error("message"); @@ -113,7 +113,7 @@ public class EelfLoggerTest { } @Test - public void testInfoObject() { + void testInfoObject() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger); eelfLogger.info("message"); @@ -124,7 +124,7 @@ public class EelfLoggerTest { } @Test - public void testWarnObject() { + void testWarnObject() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger); eelfLogger.warn("message"); @@ -135,7 +135,7 @@ public class EelfLoggerTest { } @Test - public void testTraceObject() { + void testTraceObject() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger); eelfLogger.trace("message"); @@ -143,7 +143,7 @@ public class EelfLoggerTest { } @Test - public void testIsDebugEnabled() { + void testIsDebugEnabled() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger); Mockito.when(mockLogger.isDebugEnabled()).thenReturn(false).thenReturn(true); @@ -153,7 +153,7 @@ public class EelfLoggerTest { } @Test - public void testIsInfoEnabled() { + void testIsInfoEnabled() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger); Mockito.when(mockLogger.isInfoEnabled()).thenReturn(false).thenReturn(true); @@ -162,7 +162,7 @@ public class EelfLoggerTest { } @Test - public void testIsWarnEnabled() { + void testIsWarnEnabled() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger); Mockito.when(mockLogger.isWarnEnabled()).thenReturn(false).thenReturn(true); @@ -171,7 +171,7 @@ public class EelfLoggerTest { } @Test - public void testIsErrorEnabled() { + void testIsErrorEnabled() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger); Mockito.when(mockLogger.isErrorEnabled()).thenReturn(false).thenReturn(true); @@ -180,21 +180,14 @@ public class EelfLoggerTest { } @Test - public void testIsAuditEnabled() { - PolicyLogger.setOverrideLogbackLevel(true); - PolicyLogger.setAuditLevel("ERROR"); - assertTrue(eelfLogger.isAuditEnabled()); - } - - @Test - public void testIsMetricsEnabled() { + void testIsMetricsEnabled() { PolicyLogger.setOverrideLogbackLevel(true); PolicyLogger.setMetricsLevel("ERROR"); assertTrue(eelfLogger.isMetricsEnabled()); } @Test - public void testIsTraceEnabled() { + void testIsTraceEnabled() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger); Mockito.when(mockLogger.isDebugEnabled()).thenReturn(false).thenReturn(true); @@ -203,14 +196,14 @@ public class EelfLoggerTest { } @Test - public void testAuditObject() { + void testAuditObject() { PolicyLogger.setOverrideLogbackLevel(true); PolicyLogger.setAuditLevel("ERROR"); assertTrue(eelfLogger.isAuditEnabled()); } @Test - public void testDebugObjectThrowable() { + void testDebugObjectThrowable() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger); eelfLogger.debug("message", new NullPointerException()); @@ -219,7 +212,7 @@ public class EelfLoggerTest { } @Test - public void testErrorObjectThrowable() { + void testErrorObjectThrowable() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger); eelfLogger.error("message", new NullPointerException()); @@ -229,7 +222,7 @@ public class EelfLoggerTest { } @Test - public void testInfoObjectThrowable() { + void testInfoObjectThrowable() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger); eelfLogger.info("message", new NullPointerException()); @@ -240,7 +233,7 @@ public class EelfLoggerTest { } @Test - public void testWarnObjectThrowable() { + void testWarnObjectThrowable() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger); eelfLogger.warn("message", new NullPointerException()); @@ -249,7 +242,7 @@ public class EelfLoggerTest { } @Test - public void testTraceObjectThrowable() { + void testTraceObjectThrowable() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger); eelfLogger.trace("message", new NullPointerException()); @@ -257,7 +250,7 @@ public class EelfLoggerTest { } @Test - public void testAuditObjectThrowable() { + void testAuditObjectThrowable() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "auditLogger", mockLogger); eelfLogger.audit("message", new NullPointerException()); @@ -265,20 +258,20 @@ public class EelfLoggerTest { } @Test - public void testRecordAuditEventStartString() { + void testRecordAuditEventStartString() { eelfLogger.recordAuditEventStart("eventId"); assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get("eventId")); } @Test - public void testRecordAuditEventStartUuid() { + void testRecordAuditEventStartUuid() { UUID uuid = UUID.randomUUID(); eelfLogger.recordAuditEventStart(uuid); assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get(uuid.toString())); } @Test - public void testRecordAuditEventEndStringStringString() { + void testRecordAuditEventEndStringStringString() { eelfLogger.recordAuditEventStart("eventId"); assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get("eventId")); @@ -287,7 +280,7 @@ public class EelfLoggerTest { } @Test - public void testRecordAuditEventEndUuidStringString() { + void testRecordAuditEventEndUuidStringString() { UUID uuid = UUID.randomUUID(); eelfLogger.recordAuditEventStart(uuid);; assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get(uuid.toString())); @@ -297,7 +290,7 @@ public class EelfLoggerTest { } @Test - public void testRecordAuditEventEndStringString() { + void testRecordAuditEventEndStringString() { eelfLogger.recordAuditEventStart("eventId"); assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get("eventId")); @@ -306,7 +299,7 @@ public class EelfLoggerTest { } @Test - public void testRecordAuditEventEndUuidString() { + void testRecordAuditEventEndUuidString() { UUID uuid = UUID.randomUUID(); eelfLogger.recordAuditEventStart(uuid);; assertNotNull(PolicyLogger.getEventTracker().getEventInfo().get(uuid.toString())); @@ -316,20 +309,20 @@ public class EelfLoggerTest { } @Test - public void testRecordMetricEventStringString() { + void testRecordMetricEventStringString() { eelfLogger.recordMetricEvent("eventId", "str1"); assertEquals("eventId", MDC.get(MDC_KEY_REQUEST_ID)); } @Test - public void testRecordMetricEventUuidString() { + void testRecordMetricEventUuidString() { UUID uuid = UUID.randomUUID(); eelfLogger.recordMetricEvent(uuid, "str2"); assertEquals(uuid.toString(), MDC.get(MDC_KEY_REQUEST_ID)); } @Test - public void testMetrics() { + void testMetrics() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "metricsLogger", mockLogger); eelfLogger.metrics(1); @@ -341,7 +334,7 @@ public class EelfLoggerTest { } @Test - public void testErrorMessageCodesThrowableStringArray() { + void testErrorMessageCodesThrowableStringArray() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger); eelfLogger.error(MessageCodes.GENERAL_ERROR, new NullPointerException(), "str1", "str2"); @@ -350,7 +343,7 @@ public class EelfLoggerTest { } @Test - public void testErrorMessageCodesStringArray() { + void testErrorMessageCodesStringArray() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "errorLogger", mockLogger); eelfLogger.error(MessageCodes.GENERAL_ERROR, "str1", "str2"); @@ -359,13 +352,13 @@ public class EelfLoggerTest { } @Test - public void testPostMdcInfoForEventString() { + void testPostMdcInfoForEventString() { eelfLogger.postMdcInfoForEvent("transactionId"); assertEquals("transactionId", MDC.get(MDC_KEY_REQUEST_ID)); } @Test - public void testWarnMessageCodesStringArray() { + void testWarnMessageCodesStringArray() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger); eelfLogger.warn(MessageCodes.GENERAL_ERROR, "str1", "str2"); @@ -373,7 +366,7 @@ public class EelfLoggerTest { } @Test - public void testWarnMessageCodesThrowableStringArray() { + void testWarnMessageCodesThrowableStringArray() { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); ReflectionTestUtils.setField(PolicyLogger.class, "debugLogger", mockLogger); eelfLogger.warn(MessageCodes.GENERAL_ERROR, new NullPointerException(), "str1", "str2"); @@ -383,13 +376,13 @@ public class EelfLoggerTest { } @Test - public void testPostMdcInfoForTriggeredRule() { + void testPostMdcInfoForTriggeredRule() { eelfLogger.postMdcInfoForTriggeredRule("transactionId"); assertEquals("transactionId", MDC.get(MDC_KEY_REQUEST_ID)); } @Test - public void testPostMDdcInfoForEventObject() { + void testPostMDdcInfoForEventObject() { eelfLogger.postMdcInfoForEvent(1); assertEquals("1", MDC.get(MDC_KEY_REQUEST_ID)); } diff --git a/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/FlexLoggerTest.java b/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/FlexLoggerTest.java index c0194f2b..547f0a4a 100644 --- a/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/FlexLoggerTest.java +++ b/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/FlexLoggerTest.java @@ -4,7 +4,7 @@ * ================================================================================ * Copyright (C) 2018 Ericsson. All rights reserved. * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2023 Nordix Foundation. + * Modifications 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. @@ -23,20 +23,20 @@ package org.onap.policy.common.logging.flexlogger; import static org.assertj.core.api.Assertions.assertThatCode; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertSame; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertSame; import java.io.IOException; import java.util.HashSet; import java.util.Set; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.policy.common.logging.flexlogger.FlexLogger.PropertiesCallBack; import org.springframework.test.util.ReflectionTestUtils; -public class FlexLoggerTest { +class FlexLoggerTest { @Test - public void testGetLoggerClassOfQEelf() { + void testGetLoggerClassOfQEelf() { ReflectionTestUtils.setField(FlexLogger.class, "loggerType", LoggerType.EELF); Logger logger = FlexLogger.getLogger((Class<?>) null); assertSame(logger, FlexLogger.getLogger((Class<?>) null)); @@ -44,61 +44,61 @@ public class FlexLoggerTest { } @Test - public void testGetLoggerClassOfQSystemOut() { + void testGetLoggerClassOfQSystemOut() { ReflectionTestUtils.setField(FlexLogger.class, "loggerType", LoggerType.SYSTEMOUT); Logger logger = FlexLogger.getLogger(this.getClass()); assertSame(logger, FlexLogger.getLogger(this.getClass())); } @Test - public void testGetLoggerStringEelf() { + void testGetLoggerStringEelf() { ReflectionTestUtils.setField(FlexLogger.class, "loggerType", LoggerType.EELF); Logger logger = FlexLogger.getLogger(); assertSame(logger, FlexLogger.getLogger()); } @Test - public void testGetLoggerStringSystemOut() { + void testGetLoggerStringSystemOut() { ReflectionTestUtils.setField(FlexLogger.class, "loggerType", LoggerType.SYSTEMOUT); Logger logger = FlexLogger.getLogger(); assertSame(logger, FlexLogger.getLogger()); } @Test - public void testGetLoggerClassOfQBooleanEelf() { + void testGetLoggerClassOfQBooleanEelf() { ReflectionTestUtils.setField(FlexLogger.class, "loggerType", LoggerType.EELF); Logger logger = FlexLogger.getLogger(this.getClass(), true); assertSame(logger, FlexLogger.getLogger(this.getClass(), true)); } @Test - public void testGetLoggerClassOfQBooleanSystemOut() { + void testGetLoggerClassOfQBooleanSystemOut() { ReflectionTestUtils.setField(FlexLogger.class, "loggerType", LoggerType.SYSTEMOUT); Logger logger = FlexLogger.getLogger(this.getClass(), true); assertSame(logger, FlexLogger.getLogger(this.getClass(), true)); } @Test - public void testGetLoggerStringBooleanEelf() { + void testGetLoggerStringBooleanEelf() { ReflectionTestUtils.setField(FlexLogger.class, "loggerType", LoggerType.EELF); Logger logger = FlexLogger.getLogger(true); assertSame(logger, FlexLogger.getLogger(true)); } @Test - public void testGetLoggerStringBooleanSystemOut() { + void testGetLoggerStringBooleanSystemOut() { ReflectionTestUtils.setField(FlexLogger.class, "loggerType", LoggerType.SYSTEMOUT); Logger logger = FlexLogger.getLogger(true); assertSame(logger, FlexLogger.getLogger(true)); } @Test - public void testGetClassName() { + void testGetClassName() { assertNotEquals("FlexLogger", new FlexLogger().getClassName()); } @Test - public void testPropertiesCallBack() throws IOException { + void testPropertiesCallBack() { Set<String> changedKeys = new HashSet<>(); changedKeys.add("debugLogger.level"); changedKeys.add("metricsLogger.level"); diff --git a/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/PropertyUtilTest.java b/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/PropertyUtilTest.java index 13f525c9..75c512b2 100644 --- a/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/PropertyUtilTest.java +++ b/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/PropertyUtilTest.java @@ -3,7 +3,7 @@ * ONAP-Logging * ================================================================================ * Copyright (C) 2018-2020 Ericsson, AT&T. All rights reserved. - * Modifications Copyright (C) 2023 Nordix Foundation. + * Modifications 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. @@ -21,9 +21,9 @@ package org.onap.policy.common.logging.flexlogger; -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.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.doAnswer; @@ -38,15 +38,15 @@ import java.util.Timer; import java.util.TimerTask; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; -import org.junit.After; -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.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.common.logging.flexlogger.PropertyUtil.Listener; import org.springframework.test.util.ReflectionTestUtils; -public class PropertyUtilTest { +class PropertyUtilTest { private static final String TIMER_FIELD = "timer"; private static final File FILE = new File("target/test.properties"); @@ -56,13 +56,13 @@ public class PropertyUtilTest { private Timer timer; private TestListener testListener; - @BeforeClass + @BeforeAll public static void setUpBeforeClass() { saveTimer = (Timer) ReflectionTestUtils.getField(PropertyUtil.LazyHolder.class, TIMER_FIELD); } - @AfterClass + @AfterAll public static void tearDownAfterClass() { ReflectionTestUtils.setField(PropertyUtil.LazyHolder.class, TIMER_FIELD, saveTimer); @@ -71,8 +71,8 @@ public class PropertyUtilTest { /** * Perform test case set up. */ - @Before - public void setUp() throws IOException { + @BeforeEach + void setUp() throws IOException { task = null; timer = mock(Timer.class); ReflectionTestUtils.setField(PropertyUtil.LazyHolder.class, TIMER_FIELD, timer); @@ -91,19 +91,19 @@ public class PropertyUtilTest { fileOutputStream.close(); } - @After - public void tearDown() throws IOException { + @AfterEach + void tearDown() throws IOException { PropertyUtil.stopListening(FILE, testListener); FILE.delete(); } @Test - public void testTimer() { + void testTimer() { assertNotNull(saveTimer); } @Test - public void testGetProperties() throws IOException { + void testGetProperties() throws IOException { FileOutputStream fileOutputStream = new FileOutputStream(FILE); Properties properties = new Properties(); properties.put("testProperty", "testValue"); @@ -115,7 +115,7 @@ public class PropertyUtilTest { } @Test - public void testPropertiesChanged() throws IOException, InterruptedException { + void testPropertiesChanged() throws IOException, InterruptedException { PropertyUtil.getProperties(FILE, testListener); FileOutputStream fileOutputStream = new FileOutputStream(FILE); @@ -130,7 +130,7 @@ public class PropertyUtilTest { } @Test - public void testStopListening() throws IOException { + void testStopListening() throws IOException { FileOutputStream fileOutputStream = new FileOutputStream(FILE); Properties properties = new Properties(); properties.put("testProperty", "testValue"); diff --git a/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/SystemOutLoggerTest.java b/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/SystemOutLoggerTest.java index 38c9e0d2..343eea9c 100644 --- a/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/SystemOutLoggerTest.java +++ b/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/SystemOutLoggerTest.java @@ -4,6 +4,7 @@ * ================================================================================ * Copyright (C) 2018 Ericsson. All rights reserved. * Modifications 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,35 +23,35 @@ package org.onap.policy.common.logging.flexlogger; import static org.assertj.core.api.Assertions.assertThatCode; -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 com.att.eelf.configuration.EELFLogger.Level; import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.util.UUID; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.policy.common.logging.eelf.MessageCodes; import org.onap.policy.common.logging.eelf.PolicyLogger; -public class SystemOutLoggerTest { +class SystemOutLoggerTest { SystemOutLogger systemOutLogger = new SystemOutLogger("SystemOutLoggerTest"); @Test - public void testSystemOutLoggerClassOfQ() { + void testSystemOutLoggerClassOfQ() { assertThatCode(() -> new SystemOutLogger(SystemOutLoggerTest.class)).doesNotThrowAnyException(); } @Test - public void testSetAndGetTransId() { + void testSetAndGetTransId() { systemOutLogger.setTransId("transactionId"); assertEquals("transactionId", systemOutLogger.getTransId()); } @Test - public void testDebugObject() { + void testDebugObject() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); PrintStream old = System.out; @@ -66,7 +67,7 @@ public class SystemOutLoggerTest { } @Test - public void testErrorObject() { + void testErrorObject() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); PrintStream old = System.out; @@ -82,7 +83,7 @@ public class SystemOutLoggerTest { } @Test - public void testInfoObject() { + void testInfoObject() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); PrintStream old = System.out; @@ -98,7 +99,7 @@ public class SystemOutLoggerTest { } @Test - public void testWarnObject() { + void testWarnObject() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); PrintStream old = System.out; @@ -114,7 +115,7 @@ public class SystemOutLoggerTest { } @Test - public void testTraceObject() { + void testTraceObject() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); PrintStream old = System.out; @@ -130,7 +131,7 @@ public class SystemOutLoggerTest { } @Test - public void testIsDebugEnabled() { + void testIsDebugEnabled() { PolicyLogger.setDebugLevel(Level.DEBUG); systemOutLogger = new SystemOutLogger("SystemOutLoggerTest"); assertTrue(systemOutLogger.isDebugEnabled()); @@ -140,7 +141,7 @@ public class SystemOutLoggerTest { } @Test - public void testIsWarnEnabled() { + void testIsWarnEnabled() { PolicyLogger.setDebugLevel(Level.WARN); systemOutLogger = new SystemOutLogger("SystemOutLoggerTest"); assertTrue(systemOutLogger.isWarnEnabled()); @@ -150,7 +151,7 @@ public class SystemOutLoggerTest { } @Test - public void testIsInfoEnabled() { + void testIsInfoEnabled() { PolicyLogger.setDebugLevel(Level.INFO); systemOutLogger = new SystemOutLogger("SystemOutLoggerTest"); assertTrue(systemOutLogger.isInfoEnabled()); @@ -160,7 +161,7 @@ public class SystemOutLoggerTest { } @Test - public void testIsErrorEnabled() { + void testIsErrorEnabled() { PolicyLogger.setErrorLevel(Level.ERROR); systemOutLogger = new SystemOutLogger("SystemOutLoggerTest"); assertTrue(systemOutLogger.isErrorEnabled()); @@ -170,7 +171,7 @@ public class SystemOutLoggerTest { } @Test - public void testIsAuditEnabled() { + void testIsAuditEnabled() { PolicyLogger.setAuditLevel(Level.INFO); systemOutLogger = new SystemOutLogger("SystemOutLoggerTest"); assertTrue(systemOutLogger.isAuditEnabled()); @@ -180,7 +181,7 @@ public class SystemOutLoggerTest { } @Test - public void testIsMetricsEnabled() { + void testIsMetricsEnabled() { PolicyLogger.setMetricsLevel(Level.INFO); systemOutLogger = new SystemOutLogger("SystemOutLoggerTest"); assertTrue(systemOutLogger.isMetricsEnabled()); @@ -190,7 +191,7 @@ public class SystemOutLoggerTest { } @Test - public void testAuditObject() { + void testAuditObject() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); PrintStream old = System.out; @@ -206,7 +207,7 @@ public class SystemOutLoggerTest { } @Test - public void testRecordAuditEventStartString() { + void testRecordAuditEventStartString() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); PrintStream old = System.out; @@ -222,7 +223,7 @@ public class SystemOutLoggerTest { } @Test - public void testRecordAuditEventStartUuid() { + void testRecordAuditEventStartUuid() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); PrintStream old = System.out; @@ -238,7 +239,7 @@ public class SystemOutLoggerTest { } @Test - public void testRecordAuditEventEndStringStringString() { + void testRecordAuditEventEndStringStringString() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); PrintStream old = System.out; @@ -253,7 +254,7 @@ public class SystemOutLoggerTest { } @Test - public void testRecordAuditEventEndUuidStringString() { + void testRecordAuditEventEndUuidStringString() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); PrintStream old = System.out; @@ -269,7 +270,7 @@ public class SystemOutLoggerTest { } @Test - public void testRecordAuditEventEndStringString() { + void testRecordAuditEventEndStringString() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); PrintStream old = System.out; @@ -284,7 +285,7 @@ public class SystemOutLoggerTest { } @Test - public void testRecordAuditEventEndUuidString() { + void testRecordAuditEventEndUuidString() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); PrintStream old = System.out; @@ -300,14 +301,14 @@ public class SystemOutLoggerTest { } @Test - public void testRecordMetricEventStringString() { + void testRecordMetricEventStringString() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); PrintStream old = System.out; try { System.setOut(ps); systemOutLogger.recordMetricEvent("eventId", "rule"); - assertTrue(baos.toString(), baos.toString().contains("SystemOutLoggerTest : eventId:eventIdmessage:rule")); + assertTrue(baos.toString().contains("SystemOutLoggerTest : eventId:eventIdmessage:rule"), baos.toString()); } finally { System.out.flush(); System.setOut(old); @@ -315,7 +316,7 @@ public class SystemOutLoggerTest { } @Test - public void testRecordMetricEventUuidString() { + void testRecordMetricEventUuidString() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); PrintStream old = System.out; @@ -331,7 +332,7 @@ public class SystemOutLoggerTest { } @Test - public void testMetrics() { + void testMetrics() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); PrintStream old = System.out; @@ -346,7 +347,7 @@ public class SystemOutLoggerTest { } @Test - public void testErrorMessageCodesThrowableStringArray() { + void testErrorMessageCodesThrowableStringArray() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); PrintStream old = System.out; @@ -362,7 +363,7 @@ public class SystemOutLoggerTest { } @Test - public void testErrorMessageCodesStringArray() { + void testErrorMessageCodesStringArray() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); PrintStream old = System.out; @@ -379,12 +380,12 @@ public class SystemOutLoggerTest { } @Test - public void testPostMdcInfoForEventString() { + void testPostMdcInfoForEventString() { assertEquals("transactionId", systemOutLogger.postMdcInfoForEvent("transactionId")); } @Test - public void testWarnMessageCodesStringArray() { + void testWarnMessageCodesStringArray() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); PrintStream old = System.out; @@ -401,7 +402,7 @@ public class SystemOutLoggerTest { } @Test - public void testWarnMessageCodesThrowableStringArray() { + void testWarnMessageCodesThrowableStringArray() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); PrintStream old = System.out; @@ -418,7 +419,7 @@ public class SystemOutLoggerTest { } @Test - public void testDebugObjectThrowable() { + void testDebugObjectThrowable() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); PrintStream old = System.out; @@ -426,8 +427,8 @@ public class SystemOutLoggerTest { System.setOut(ps); systemOutLogger.setTransId("transactionId"); systemOutLogger.debug("1", new NullPointerException()); - assertTrue(baos.toString(), - baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException")); + assertTrue(baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"), + baos.toString()); } finally { System.out.flush(); System.setOut(old); @@ -435,7 +436,7 @@ public class SystemOutLoggerTest { } @Test - public void testErrorObjectThrowable() { + void testErrorObjectThrowable() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); PrintStream old = System.out; @@ -443,8 +444,8 @@ public class SystemOutLoggerTest { System.setOut(ps); systemOutLogger.setTransId("transactionId"); systemOutLogger.error("1", new NullPointerException()); - assertTrue(baos.toString(), - baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException")); + assertTrue(baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"), + baos.toString()); } finally { System.out.flush(); System.setOut(old); @@ -452,7 +453,7 @@ public class SystemOutLoggerTest { } @Test - public void testInfoObjectThrowable() { + void testInfoObjectThrowable() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); PrintStream old = System.out; @@ -460,8 +461,8 @@ public class SystemOutLoggerTest { System.setOut(ps); systemOutLogger.setTransId("transactionId"); systemOutLogger.info("1", new NullPointerException()); - assertTrue(baos.toString(), - baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException")); + assertTrue(baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"), + baos.toString()); } finally { System.out.flush(); System.setOut(old); @@ -469,7 +470,7 @@ public class SystemOutLoggerTest { } @Test - public void testWarnObjectThrowable() { + void testWarnObjectThrowable() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); PrintStream old = System.out; @@ -477,8 +478,8 @@ public class SystemOutLoggerTest { System.setOut(ps); systemOutLogger.setTransId("transactionId"); systemOutLogger.warn("1", new NullPointerException()); - assertTrue(baos.toString(), - baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException")); + assertTrue(baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"), + baos.toString()); } finally { System.out.flush(); System.setOut(old); @@ -486,7 +487,7 @@ public class SystemOutLoggerTest { } @Test - public void testTraceObjectThrowable() { + void testTraceObjectThrowable() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); PrintStream old = System.out; @@ -494,8 +495,8 @@ public class SystemOutLoggerTest { System.setOut(ps); systemOutLogger.setTransId("transactionId"); systemOutLogger.trace(1, new NullPointerException()); - assertTrue(baos.toString(), - baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException")); + assertTrue(baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"), + baos.toString()); } finally { System.out.flush(); System.setOut(old); @@ -503,7 +504,7 @@ public class SystemOutLoggerTest { } @Test - public void testAuditObjectThrowable() { + void testAuditObjectThrowable() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); PrintStream old = System.out; @@ -511,8 +512,8 @@ public class SystemOutLoggerTest { System.setOut(ps); systemOutLogger.setTransId("transactionId"); systemOutLogger.audit("1", new NullPointerException()); - assertTrue(baos.toString(), - baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException")); + assertTrue(baos.toString().contains("transactionId|SystemOutLoggerTest : 1:java.lang.NullPointerException"), + baos.toString()); } finally { System.out.flush(); System.setOut(old); @@ -520,19 +521,19 @@ public class SystemOutLoggerTest { } @Test - public void testIsTraceEnabled() { + void testIsTraceEnabled() { assertFalse(systemOutLogger.isTraceEnabled()); } @Test - public void testPostMdcInfoForTriggeredRule() { + void testPostMdcInfoForTriggeredRule() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); PrintStream old = System.out; try { System.setOut(ps); systemOutLogger.postMdcInfoForTriggeredRule("transactionId"); - assertTrue(baos.toString(), baos.toString().contains("transactionId")); + assertTrue(baos.toString().contains("transactionId"), baos.toString()); } finally { System.out.flush(); System.setOut(old); @@ -540,14 +541,14 @@ public class SystemOutLoggerTest { } @Test - public void testPostMdcInfoForEventObject() { + void testPostMdcInfoForEventObject() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); PrintStream old = System.out; try { System.setOut(ps); systemOutLogger.postMdcInfoForEvent(1); - assertTrue(baos.toString(), baos.toString().contains("1")); + assertTrue(baos.toString().contains("1"), baos.toString()); } finally { System.out.flush(); System.setOut(old); diff --git a/common-parameters/pom.xml b/common-parameters/pom.xml index 8ecd611e..fc7b980e 100644 --- a/common-parameters/pom.xml +++ b/common-parameters/pom.xml @@ -58,11 +58,6 @@ <artifactId>gson</artifactId> </dependency> <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - <dependency> <groupId>org.assertj</groupId> <artifactId>assertj-core</artifactId> <scope>test</scope> diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/ExceptionTest.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/ExceptionTest.java index 48d2f4b5..875fe44a 100644 --- a/common-parameters/src/test/java/org/onap/policy/common/parameters/ExceptionTest.java +++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/ExceptionTest.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. * Modifications 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,17 +22,17 @@ package org.onap.policy.common.parameters; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import java.io.IOException; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class ExceptionTest { +class ExceptionTest { private static final String PARAMETER_EXCEPTION = "Parameter Exception"; private static final String EXCEPTION_OBJECT = "Exception Object"; @Test - public void testParameterException() { + void testParameterException() { assertEquals(PARAMETER_EXCEPTION, new ParameterException(PARAMETER_EXCEPTION).getMessage()); assertEquals(EXCEPTION_OBJECT, @@ -44,7 +45,7 @@ public class ExceptionTest { } @Test - public void testParameterRuntimeException() { + void testParameterRuntimeException() { assertEquals(PARAMETER_EXCEPTION, new ParameterRuntimeException(PARAMETER_EXCEPTION).getMessage()); assertEquals(EXCEPTION_OBJECT, diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/TestBeanValidationResult.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/TestBeanValidationResult.java index b7bea204..2fc09949 100644 --- a/common-parameters/src/test/java/org/onap/policy/common/parameters/TestBeanValidationResult.java +++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/TestBeanValidationResult.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. @@ -21,10 +22,10 @@ package org.onap.policy.common.parameters; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -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.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Arrays; import java.util.List; @@ -32,10 +33,10 @@ import java.util.Map; import java.util.Map.Entry; import java.util.TreeMap; import java.util.function.BiConsumer; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -public class TestBeanValidationResult { +class TestBeanValidationResult { private static final String TEXT1 = "abc"; private static final String TEXT2 = "def"; private static final String MY_LIST = "my-list"; @@ -59,8 +60,8 @@ public class TestBeanValidationResult { /** * Sets up. */ - @Before - public void setUp() { + @BeforeEach + void setUp() { clean = new ObjectValidationResult(TEXT1, 10); cleanMsg = clean.getResult("", "", true); @@ -72,13 +73,13 @@ public class TestBeanValidationResult { } @Test - public void testBeanValidationResult() { + void testBeanValidationResult() { assertTrue(bean.isValid()); assertNull(bean.getResult()); } @Test - public void testAddResult_testGetResult() { + void testAddResult_testGetResult() { // null should be ok assertTrue(bean.addResult(null)); @@ -99,7 +100,7 @@ public class TestBeanValidationResult { } @Test - public void testValidateNotNull() { + void testValidateNotNull() { assertTrue(bean.validateNotNull("sub-name", "sub-object")); assertTrue(bean.isValid()); assertNull(bean.getResult()); @@ -110,7 +111,7 @@ public class TestBeanValidationResult { } @Test - public void testValidateNotNullList() { + void testValidateNotNullList() { List<ValidationResult> list = Arrays.asList(clean); assertTrue(bean.validateNotNullList(MY_LIST, list, item -> item)); assertTrue(bean.isValid()); @@ -124,7 +125,7 @@ public class TestBeanValidationResult { } @Test - public void testValidateNotNullList_NullList() { + void testValidateNotNullList_NullList() { List<ValidationResult> list = null; assertFalse(bean.validateNotNullList(MY_LIST, list, item -> item)); assertFalse(bean.isValid()); @@ -133,7 +134,7 @@ public class TestBeanValidationResult { } @Test - public void testValidateList() { + void testValidateList() { List<ValidationResult> list = null; bean = new BeanValidationResult(NAME, OBJECT); assertTrue(bean.validateList(MY_LIST, list, item -> item)); @@ -164,7 +165,7 @@ public class TestBeanValidationResult { } @Test - public void testValidateMap() { + void testValidateMap() { Map<String, ValidationResult> map = null; bean = new BeanValidationResult(NAME, OBJECT); assertTrue(bean.validateMap(MY_MAP, map, validMapEntry())); diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/TestBeanValidator.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/TestBeanValidator.java index 83d0a7f9..31c34209 100644 --- a/common-parameters/src/test/java/org/onap/policy/common/parameters/TestBeanValidator.java +++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/TestBeanValidator.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 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. @@ -21,7 +22,7 @@ package org.onap.policy.common.parameters; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Collection; import java.util.HashMap; @@ -30,8 +31,8 @@ import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Consumer; import lombok.Getter; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.common.parameters.annotations.ClassName; import org.onap.policy.common.parameters.annotations.Max; import org.onap.policy.common.parameters.annotations.Min; @@ -41,7 +42,7 @@ import org.onap.policy.common.parameters.annotations.Pattern; import org.onap.policy.common.parameters.annotations.Size; import org.onap.policy.common.parameters.annotations.Valid; -public class TestBeanValidator { +class TestBeanValidator { private static final String TOP = "top"; private static final String STR_FIELD = "strValue"; private static final String INT_FIELD = "intValue"; @@ -52,13 +53,13 @@ public class TestBeanValidator { private BeanValidator validator; - @Before - public void setUp() { + @BeforeEach + void setUp() { validator = new BeanValidator(); } @Test - public void testValidateTop_testValidateFields() { + void testValidateTop_testValidateFields() { // validate null assertTrue(validator.validateTop(TOP, null).isValid()); @@ -117,7 +118,7 @@ public class TestBeanValidator { } @Test - public void testVerNotNull() { + void testVerNotNull() { class NotNullCheck { @Getter @Min(1) @@ -136,7 +137,7 @@ public class TestBeanValidator { } @Test - public void testVerNotBlank() { + void testVerNotBlank() { class NotBlankCheck { @Getter @NotBlank @@ -178,7 +179,7 @@ public class TestBeanValidator { * Tests verSize with a collection. */ @Test - public void testVerSizeCollection() { + void testVerSizeCollection() { class CollectionSizeCheck { @Getter @Size(min = 3) @@ -208,7 +209,7 @@ public class TestBeanValidator { * Tests verSize with a map. */ @Test - public void testVerSizeMap() { + void testVerSizeMap() { class MapSizeCheck { @Getter @Size(min = 3) @@ -238,7 +239,7 @@ public class TestBeanValidator { * Tests verSize with an object for which it doesn't apply. */ @Test - public void testVerSizeOther() { + void testVerSizeOther() { class OtherSizeCheck { @Getter @Size(min = 3) @@ -252,7 +253,7 @@ public class TestBeanValidator { } @Test - public void testVerRegex() { + void testVerRegex() { class RegexCheck { @Getter @Pattern(regexp = "[a-f]*") @@ -304,7 +305,7 @@ public class TestBeanValidator { } @Test - public void testVerMax() { + void testVerMax() { /* * Field is not a number. */ @@ -398,7 +399,7 @@ public class TestBeanValidator { } @Test - public void testVerMin() { + void testVerMin() { /* * Field is not a number. */ @@ -492,7 +493,7 @@ public class TestBeanValidator { } @Test - public void testVerClassName() { + void testVerClassName() { class ClassNameCheck { @Getter @ClassName @@ -516,7 +517,7 @@ public class TestBeanValidator { } @Test - public void testVerCascade() { + void testVerCascade() { class Item { @Getter @NotNull @@ -554,7 +555,7 @@ public class TestBeanValidator { } @Test - public void testVerCollection() { + void testVerCollection() { @Getter class Container { List<@Min(5) Integer> items; @@ -589,7 +590,7 @@ public class TestBeanValidator { } @Test - public void testVerMap() { + void testVerMap() { @Getter class Container { Map<String, @Min(5) Integer> items; @@ -624,7 +625,7 @@ public class TestBeanValidator { } @Test - public void testGetEntryName() { + void testGetEntryName() { assertThat(validator.getEntryName(makeEntry(null, 0))).isEmpty(); assertThat(validator.getEntryName(makeEntry("", 0))).isEmpty(); assertThat(validator.getEntryName(makeEntry(STRING_VALUE, 0))).isEqualTo(STRING_VALUE); diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/TestFieldValidator.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/TestFieldValidator.java index 81a7b8ff..0fb39b0f 100644 --- a/common-parameters/src/test/java/org/onap/policy/common/parameters/TestFieldValidator.java +++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/TestFieldValidator.java @@ -3,7 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2023 Nordix Foundation. + * Modifications 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. @@ -30,13 +30,13 @@ import java.lang.reflect.InvocationTargetException; import java.util.List; import java.util.Map; import lombok.Getter; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.common.parameters.annotations.Min; import org.onap.policy.common.parameters.annotations.NotBlank; import org.onap.policy.common.parameters.annotations.NotNull; -public class TestFieldValidator extends ValidatorUtil { +class TestFieldValidator extends ValidatorUtil { private static final String INT_LIST_FIELD = "intList"; private static final String INT_MAP_FIELD = "intMap"; private static final String UNANNOTATED_FIELD = "unannotated"; @@ -113,13 +113,13 @@ public class TestFieldValidator extends ValidatorUtil { private int exMethod; - @Before - public void setUp() { + @BeforeEach + void setUp() { bean = new BeanValidator(); } @Test - public void testGetAnnotation() { + void testGetAnnotation() { // field-level annotation assertThat(new FieldValidator(bean, TestFieldValidator.class, getField(INT_FIELD)).isEmpty()).isFalse(); @@ -128,7 +128,7 @@ public class TestFieldValidator extends ValidatorUtil { } @Test - public void testFieldValidator() throws NoSuchFieldException, SecurityException { + void testFieldValidator() throws NoSuchFieldException, SecurityException { /* * Note: nested classes contain fields like "$this", thus the check for "$" in the * variable name is already covered by the other tests. @@ -165,7 +165,7 @@ public class TestFieldValidator extends ValidatorUtil { } @Test - public void testFieldValidator_SetNullAllowed() { + void testFieldValidator_SetNullAllowed() { // default - null is allowed assertThat(new FieldValidator(bean, TestFieldValidator.class, getField(INT_FIELD)).isNullAllowed()).isTrue(); @@ -179,7 +179,7 @@ public class TestFieldValidator extends ValidatorUtil { } @Test - public void testAddListValidator() { + void testAddListValidator() { // unannotated assertThat(new FieldValidator(bean, TestFieldValidator.class, getField("unannotatedList")).isEmpty()).isTrue(); @@ -189,7 +189,7 @@ public class TestFieldValidator extends ValidatorUtil { } @Test - public void testAddMapValidator() { + void testAddMapValidator() { // unannotated assertThat(new FieldValidator(bean, TestFieldValidator.class, getField("unannotatedMap")).isEmpty()).isTrue(); @@ -226,7 +226,7 @@ public class TestFieldValidator extends ValidatorUtil { @SuppressWarnings("deprecation") @Test - public void testValidateField_testGetValue() { + void testValidateField_testGetValue() { // unannotated BeanValidationResult result = new BeanValidationResult(MY_NAME, this); new FieldValidator(bean, getClass(), getField(UNANNOTATED_FIELD)).validateField(result, this); @@ -253,7 +253,7 @@ public class TestFieldValidator extends ValidatorUtil { } @Test - public void testValidateField_testGetValue_ListField() { + void testValidateField_testGetValue_ListField() { // valid BeanValidationResult result = new BeanValidationResult(MY_NAME, this); intList = List.of(10, 20, 30, 40); @@ -269,7 +269,7 @@ public class TestFieldValidator extends ValidatorUtil { } @Test - public void testValidateField_testGetValue_MapField() { + void testValidateField_testGetValue_MapField() { // valid BeanValidationResult result = new BeanValidationResult(MY_NAME, this); intMap = Map.of("ten", 10, "twenty", 20, "thirty", 30, "forty", 40); @@ -285,7 +285,7 @@ public class TestFieldValidator extends ValidatorUtil { } @Test - public void testClassOnly() { + void testClassOnly() { // class-level annotation has no bearing on a static field assertThat(new FieldValidator(bean, ClassAnnot.class, getField(ClassAnnot.class, "staticValue")).isEmpty()) .isTrue(); @@ -297,7 +297,7 @@ public class TestFieldValidator extends ValidatorUtil { } @Test - public void testGetAccessor() { + void testGetAccessor() { // uses "getXxx" assertThat(new FieldValidator(bean, TestFieldValidator.class, getField(INT_FIELD)).isEmpty()).isFalse(); @@ -306,7 +306,7 @@ public class TestFieldValidator extends ValidatorUtil { } @Test - public void testGetMethod() { + void testGetMethod() { assertThat(new FieldValidator(bean, TestFieldValidator.class, getField(INT_FIELD)).isEmpty()).isFalse(); // these are invalid for various reasons @@ -321,7 +321,7 @@ public class TestFieldValidator extends ValidatorUtil { } @Test - public void testValidMethod() { + void testValidMethod() { assertThat(new FieldValidator(bean, TestFieldValidator.class, getField(INT_FIELD)).isEmpty()).isFalse(); // these are invalid for various reasons @@ -340,7 +340,7 @@ public class TestFieldValidator extends ValidatorUtil { } @Test - public void testIsFieldAnnotated_testSetFieldAnnotated() { + void testIsFieldAnnotated_testSetFieldAnnotated() { // annotated at the field level assertThat(new FieldValidator(bean, getClass(), getField(INT_FIELD)).isFieldAnnotated()).isTrue(); @@ -352,7 +352,7 @@ public class TestFieldValidator extends ValidatorUtil { return -1000; } - public void getVoidMethod() { + void getVoidMethod() { // do nothing } diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/TestItemValidator.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/TestItemValidator.java index cadcfdee..b2686fdf 100644 --- a/common-parameters/src/test/java/org/onap/policy/common/parameters/TestItemValidator.java +++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/TestItemValidator.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. @@ -26,13 +27,13 @@ import static org.assertj.core.api.Assertions.assertThat; import java.lang.annotation.Retention; import java.lang.annotation.Target; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.common.parameters.annotations.Min; import org.onap.policy.common.parameters.annotations.NotBlank; import org.onap.policy.common.parameters.annotations.NotNull; -public class TestItemValidator extends ValidatorUtil { +class TestItemValidator extends ValidatorUtil { // annotated fields - each field must have exactly one annotation @@ -69,13 +70,13 @@ public class TestItemValidator extends ValidatorUtil { private String multiMatch; - @Before - public void setUp() { + @BeforeEach + void setUp() { bean = new BeanValidator(); } @Test - public void testGetAnnotation() { + void testGetAnnotation() { // no matches assertThat(new ItemValidator(bean, getAnnotType("noAnnotations"), true).isEmpty()).isTrue(); @@ -100,12 +101,12 @@ public class TestItemValidator extends ValidatorUtil { } @Test - public void testItemValidatorBeanValidatorAnnotation() { + void testItemValidatorBeanValidatorAnnotation() { assertThat(new ItemValidator(bean, getAnnotType("match")).isEmpty()).isFalse(); } @Test - public void testItemValidatorBeanValidatorAnnotationBoolean() { + void testItemValidatorBeanValidatorAnnotationBoolean() { assertThat(new ItemValidator(bean, getAnnotType("match"), true).isEmpty()).isFalse(); assertThat(new ItemValidator(bean, getAnnotType("match"), false).isEmpty()).isTrue(); diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/TestObjectValidationResult.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/TestObjectValidationResult.java index 5fd7d892..c72d4f4a 100644 --- a/common-parameters/src/test/java/org/onap/policy/common/parameters/TestObjectValidationResult.java +++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/TestObjectValidationResult.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,21 +21,21 @@ package org.onap.policy.common.parameters; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -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.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class TestObjectValidationResult { +class TestObjectValidationResult { private static final String NAME = "my-name"; private static final Object OBJECT = "my-object"; private ObjectValidationResult result; @Test - public void testValidationResultImplStringObjectValidationStatusString() { + void testValidationResultImplStringObjectValidationStatusString() { result = new ObjectValidationResult(NAME, OBJECT, ValidationStatus.INVALID, "invalid data"); assertEquals(NAME, result.getName()); assertEquals(OBJECT, result.getObject()); @@ -43,7 +44,7 @@ public class TestObjectValidationResult { } @Test - public void testGetResult() { + void testGetResult() { result = new ObjectValidationResult(NAME, OBJECT); assertEquals(ValidationStatus.CLEAN, result.getStatus()); assertNull(result.getResult()); diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/TestValidation.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/TestValidation.java index b19b92da..a696963c 100644 --- a/common-parameters/src/test/java/org/onap/policy/common/parameters/TestValidation.java +++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/TestValidation.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2018 Ericsson. All rights reserved. * Modifications 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. @@ -22,16 +23,16 @@ package org.onap.policy.common.parameters; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.policy.common.parameters.annotations.Max; import org.onap.policy.common.parameters.annotations.Min; import org.onap.policy.common.parameters.annotations.NotBlank; import org.onap.policy.common.parameters.annotations.NotNull; import org.onap.policy.common.parameters.annotations.Valid; -public class TestValidation { +class TestValidation { private static final String NOT_BLANK_STRING_MESSAGE = "field 'notBlankString' type 'java.lang.String' value '' INVALID, must be a non-blank string\n" .replace('\'', '"'); @@ -66,7 +67,7 @@ public class TestValidation { private long maxLong; @Test - public void testGetValidationResult() { + void testGetValidationResult() { Contained item = new Contained(); item.setName("item"); @@ -87,7 +88,7 @@ public class TestValidation { } @Test - public void testParameterValidationResult_NotNull() throws Exception { + void testParameterValidationResult_NotNull() throws Exception { ParameterValidationResult result = new ParameterValidationResult( TestValidation.class.getDeclaredField(NOT_NULL_STRING_NAME), null); assertEquals(ValidationStatus.INVALID, result.getStatus()); @@ -139,7 +140,7 @@ public class TestValidation { } @Test - public void testParameterValidationResult_NotBlank() throws Exception { + void testParameterValidationResult_NotBlank() throws Exception { ParameterValidationResult result = new ParameterValidationResult(TestValidation.class.getDeclaredField(NOT_BLANK_STRING_NAME), ""); assertEquals(ValidationStatus.INVALID, result.getStatus()); @@ -180,7 +181,7 @@ public class TestValidation { } @Test - public void testParameterValidationResult_Min() throws Exception { + void testParameterValidationResult_Min() throws Exception { ParameterValidationResult result = new ParameterValidationResult(TestValidation.class.getDeclaredField(MIN_LONG_NAME), 9L); assertEquals(ValidationStatus.INVALID, result.getStatus()); @@ -200,7 +201,7 @@ public class TestValidation { } @Test - public void testParameterValidationResult_Max() throws Exception { + void testParameterValidationResult_Max() throws Exception { ParameterValidationResult result = new ParameterValidationResult(TestValidation.class.getDeclaredField(MAX_LONG_NAME), 11L); assertEquals(ValidationStatus.INVALID, result.getStatus()); diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/TestValidationResultImpl.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/TestValidationResultImpl.java index da6107cf..f6851b5e 100644 --- a/common-parameters/src/test/java/org/onap/policy/common/parameters/TestValidationResultImpl.java +++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/TestValidationResultImpl.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,27 +21,27 @@ package org.onap.policy.common.parameters; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -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.assertNull; +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 TestValidationResultImpl { +class TestValidationResultImpl { private static final String NAME = "my-name"; private static final Object OBJECT = "my-object"; private MyResult result; - @Before - public void setUp() { + @BeforeEach + void setUp() { result = new MyResult(NAME, OBJECT); } @Test - public void testValidationResultImplStringObjectValidationStatusString() { + void testValidationResultImplStringObjectValidationStatusString() { result = new MyResult(NAME, OBJECT, ValidationStatus.INVALID, "invalid data"); assertEquals(NAME, result.getName()); assertEquals(OBJECT, result.getObject()); @@ -49,7 +50,7 @@ public class TestValidationResultImpl { } @Test - public void testValidateNotNull() { + void testValidateNotNull() { assertTrue(result.validateNotNull()); assertTrue(result.isValid()); assertNull(result.getResult()); @@ -62,7 +63,7 @@ public class TestValidationResultImpl { } @Test - public void testSetResultValidationStatus() { + void testSetResultValidationStatus() { result.setResult(ValidationStatus.WARNING); assertEquals(ValidationStatus.WARNING, result.getStatus()); @@ -75,7 +76,7 @@ public class TestValidationResultImpl { } @Test - public void testSetResult_testGetResult_testGetStatus() { + void testSetResult_testGetResult_testGetStatus() { assertEquals(ValidationStatus.CLEAN, result.getStatus()); assertEquals("CLEAN item has status CLEAN", result.getResult("xxx ", "yyy", true)); @@ -97,7 +98,7 @@ public class TestValidationResultImpl { } @Test - public void testGetName() { + void testGetName() { assertEquals(NAME, result.getName()); } diff --git a/common-parameters/src/test/java/org/onap/policy/common/parameters/TestValueValidator.java b/common-parameters/src/test/java/org/onap/policy/common/parameters/TestValueValidator.java index dcf08695..0cd3776d 100644 --- a/common-parameters/src/test/java/org/onap/policy/common/parameters/TestValueValidator.java +++ b/common-parameters/src/test/java/org/onap/policy/common/parameters/TestValueValidator.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. @@ -24,13 +25,13 @@ import static org.assertj.core.api.Assertions.assertThat; import java.lang.annotation.Annotation; import java.util.concurrent.atomic.AtomicBoolean; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.common.parameters.annotations.Min; import org.onap.policy.common.parameters.annotations.NotBlank; import org.onap.policy.common.parameters.annotations.NotNull; -public class TestValueValidator extends ValidatorUtil { +class TestValueValidator extends ValidatorUtil { private ValueValidator validator; @@ -41,13 +42,13 @@ public class TestValueValidator extends ValidatorUtil { private final int annotField = 1; - @Before - public void setUp() { + @BeforeEach + void setUp() { validator = new MyValueValidator(); } @Test - public void testIsEmpty() { + void testIsEmpty() { assertThat(validator.isEmpty()).isTrue(); validator.addAnnotation(NotNull.class, (result2, fieldName, value) -> true); @@ -55,7 +56,7 @@ public class TestValueValidator extends ValidatorUtil { } @Test - public void testValidateValue_NullValue() { + void testValidateValue_NullValue() { BeanValidationResult result = new BeanValidationResult(MY_NAME, this); validator.validateValue(result, MY_FIELD, null); @@ -68,7 +69,7 @@ public class TestValueValidator extends ValidatorUtil { } @Test - public void testValidateValue_NotNullValue() { + void testValidateValue_NotNullValue() { BeanValidationResult result = new BeanValidationResult(MY_NAME, this); validator.validateValue(result, MY_FIELD, HELLO); @@ -81,7 +82,7 @@ public class TestValueValidator extends ValidatorUtil { } @Test - public void testAddAnnotationClassOfTChecker() { + void testAddAnnotationClassOfTChecker() { // the field does not have this annotation validator.addAnnotation(Min.class, (result2, fieldName, value) -> true); assertThat(validator.isEmpty()).isTrue(); @@ -98,7 +99,7 @@ public class TestValueValidator extends ValidatorUtil { } @Test - public void testAddAnnotationClassOfTCheckerWithAnnotOfT() { + void testAddAnnotationClassOfTCheckerWithAnnotOfT() { // the field does not have this annotation validator.addAnnotation(Min.class, (result2, fieldName, annot, value) -> true); assertThat(validator.isEmpty()).isTrue(); @@ -122,7 +123,7 @@ public class TestValueValidator extends ValidatorUtil { } @Test - public void testGetAnnotation() { + void testGetAnnotation() { assertThat(new ValueValidator().getAnnotation(NotNull.class)).isNull(); } diff --git a/gson/pom.xml b/gson/pom.xml index 0353f139..0f11f374 100644 --- a/gson/pom.xml +++ b/gson/pom.xml @@ -55,11 +55,6 @@ <artifactId>re2j</artifactId> </dependency> <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - <scope>test</scope> - </dependency> - <dependency> <groupId>org.assertj</groupId> <artifactId>assertj-core</artifactId> <scope>test</scope> diff --git a/gson/src/test/java/org/onap/policy/common/gson/DoubleConverterTest.java b/gson/src/test/java/org/onap/policy/common/gson/DoubleConverterTest.java index f4e3a76b..72cb41db 100644 --- a/gson/src/test/java/org/onap/policy/common/gson/DoubleConverterTest.java +++ b/gson/src/test/java/org/onap/policy/common/gson/DoubleConverterTest.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,20 +21,19 @@ package org.onap.policy.common.gson; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; import java.util.ArrayList; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class DoubleConverterTest { +class DoubleConverterTest { @Test - @SuppressWarnings("unchecked") - public void testConvertFromDoubleObject() { + void testConvertFromDoubleObject() { // these should be unchanged assertNull(DoubleConverter.convertFromDouble((Object) null)); assertEquals("hello", DoubleConverter.convertFromDouble("hello")); @@ -68,7 +68,7 @@ public class DoubleConverterTest { } @Test - public void testConvertFromDoubleList() { + void testConvertFromDoubleList() { // null is ok DoubleConverter.convertFromDouble((List<Object>) null); @@ -86,7 +86,7 @@ public class DoubleConverterTest { } @Test - public void testConvertFromDoubleMap() { + void testConvertFromDoubleMap() { // null is ok DoubleConverter.convertFromDouble((Map<String, Object>) null); diff --git a/gson/src/test/java/org/onap/policy/common/gson/GsonMessageBodyHandlerTest.java b/gson/src/test/java/org/onap/policy/common/gson/GsonMessageBodyHandlerTest.java index fc101430..00e1caf0 100644 --- a/gson/src/test/java/org/onap/policy/common/gson/GsonMessageBodyHandlerTest.java +++ b/gson/src/test/java/org/onap/policy/common/gson/GsonMessageBodyHandlerTest.java @@ -3,7 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2023 Nordix Foundation. + * Modifications 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.gson; import static org.assertj.core.api.Assertions.assertThat; -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 jakarta.ws.rs.core.MediaType; import java.io.ByteArrayInputStream; @@ -39,10 +39,10 @@ import java.util.HashMap; import java.util.Map; import java.util.UUID; 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 GsonMessageBodyHandlerTest { +class GsonMessageBodyHandlerTest { private static final String GEN_TYPE = "some-type"; private static final String[] subtypes = {"json", "jSoN", "hello+json", "javascript", "x-javascript", "x-json"}; @@ -54,18 +54,18 @@ public class GsonMessageBodyHandlerTest { private GsonMessageBodyHandler hdlr; - @Before - public void setUp() { + @BeforeEach + void setUp() { hdlr = new GsonMessageBodyHandler(); } @Test - public void testIsWriteable() { + void testIsWriteable() { // null media type assertTrue(hdlr.isWriteable(null, null, null, null)); for (String subtype : subtypes) { - assertTrue("writeable " + subtype, hdlr.isWriteable(null, null, null, new MediaType(GEN_TYPE, subtype))); + assertTrue(hdlr.isWriteable(null, null, null, new MediaType(GEN_TYPE, subtype)), "writeable " + subtype); } @@ -79,12 +79,12 @@ public class GsonMessageBodyHandlerTest { } @Test - public void testGetSize() { + void testGetSize() { assertEquals(-1, hdlr.getSize(null, null, null, null, null)); } @Test - public void testWriteTo_testReadFrom() throws Exception { + void testWriteTo_testReadFrom() throws Exception { ByteArrayOutputStream outstr = new ByteArrayOutputStream(); MyObject obj1 = new MyObject(10); hdlr.writeTo(obj1, obj1.getClass(), CLASS_OBJ, null, null, null, outstr); @@ -95,7 +95,7 @@ public class GsonMessageBodyHandlerTest { } @Test - public void testWriteTo_DifferentTypes() throws Exception { + void testWriteTo_DifferentTypes() throws Exception { ByteArrayOutputStream outstr = new ByteArrayOutputStream(); // use a derived type, but specify the base type when writing @@ -108,7 +108,7 @@ public class GsonMessageBodyHandlerTest { } @Test - public void testIsReadable() { + void testIsReadable() { // null media type assertTrue(hdlr.isReadable(null, null, null, null)); @@ -116,7 +116,7 @@ public class GsonMessageBodyHandlerTest { assertFalse(hdlr.isReadable(null, null, null, new MediaType(GEN_TYPE, null))); for (String subtype : subtypes) { - assertTrue("readable " + subtype, hdlr.isReadable(null, null, null, new MediaType(GEN_TYPE, subtype))); + assertTrue(hdlr.isReadable(null, null, null, new MediaType(GEN_TYPE, subtype)), "readable " + subtype); } @@ -130,7 +130,7 @@ public class GsonMessageBodyHandlerTest { } @Test - public void testReadFrom_DifferentTypes() throws Exception { + void testReadFrom_DifferentTypes() throws Exception { ByteArrayOutputStream outstr = new ByteArrayOutputStream(); MyObject obj1 = new MyObject(10); hdlr.writeTo(obj1, obj1.getClass(), CLASS_OBJ, null, null, null, outstr); @@ -148,7 +148,7 @@ public class GsonMessageBodyHandlerTest { } @Test - public void testMapDouble() throws Exception { + void testMapDouble() throws Exception { MyMap map = new MyMap(); map.props = new HashMap<>(); map.props.put("plainString", "def"); @@ -171,7 +171,7 @@ public class GsonMessageBodyHandlerTest { } @Test - public void testInterestingFields() throws IOException { + void testInterestingFields() throws IOException { InterestingFields data = new InterestingFields(); data.instant = Instant.ofEpochMilli(1583249713500L); data.uuid = UUID.fromString("a850cb9f-3c5e-417c-abfd-0679cdcd1ab0"); diff --git a/gson/src/test/java/org/onap/policy/common/gson/InstantAsMillisTypeAdapterTest.java b/gson/src/test/java/org/onap/policy/common/gson/InstantAsMillisTypeAdapterTest.java index c48919a7..f2ddf06a 100644 --- a/gson/src/test/java/org/onap/policy/common/gson/InstantAsMillisTypeAdapterTest.java +++ b/gson/src/test/java/org/onap/policy/common/gson/InstantAsMillisTypeAdapterTest.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. @@ -21,20 +22,20 @@ package org.onap.policy.common.gson; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import java.time.Instant; import lombok.ToString; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class InstantAsMillisTypeAdapterTest { +class InstantAsMillisTypeAdapterTest { private static Gson gson = new GsonBuilder().registerTypeAdapter(Instant.class, new InstantAsMillisTypeAdapter()).create(); @Test - public void test() { + void test() { InterestingFields data = new InterestingFields(); data.instant = Instant.ofEpochMilli(1583249713500L); diff --git a/gson/src/test/java/org/onap/policy/common/gson/InstantTypeAdapterTest.java b/gson/src/test/java/org/onap/policy/common/gson/InstantTypeAdapterTest.java index 68f54ed8..2e27d1dc 100644 --- a/gson/src/test/java/org/onap/policy/common/gson/InstantTypeAdapterTest.java +++ b/gson/src/test/java/org/onap/policy/common/gson/InstantTypeAdapterTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 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. @@ -22,21 +23,21 @@ package org.onap.policy.common.gson; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonParseException; import java.time.Instant; import lombok.ToString; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class InstantTypeAdapterTest { +class InstantTypeAdapterTest { private static Gson gson = new GsonBuilder().registerTypeAdapter(Instant.class, new InstantTypeAdapter()).create(); @Test - public void test() { + void test() { InterestingFields data = new InterestingFields(); data.instant = Instant.ofEpochMilli(1583249713500L); diff --git a/gson/src/test/java/org/onap/policy/common/gson/JacksonExclusionStrategyTest.java b/gson/src/test/java/org/onap/policy/common/gson/JacksonExclusionStrategyTest.java index 9d8d3495..38f2f32a 100644 --- a/gson/src/test/java/org/onap/policy/common/gson/JacksonExclusionStrategyTest.java +++ b/gson/src/test/java/org/onap/policy/common/gson/JacksonExclusionStrategyTest.java @@ -3,7 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2019-2021 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. @@ -21,9 +21,9 @@ package org.onap.policy.common.gson; -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 com.google.gson.FieldAttributes; import com.google.gson.Gson; @@ -33,22 +33,22 @@ import java.lang.reflect.GenericArrayType; import java.util.LinkedList; import java.util.TreeMap; import lombok.ToString; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; -public class JacksonExclusionStrategyTest { +class JacksonExclusionStrategyTest { private static JacksonExclusionStrategy strategy; private static Gson gson; - @BeforeClass + @BeforeAll public static void setUpBeforeClass() { strategy = new JacksonExclusionStrategy(); gson = new GsonBuilder().setExclusionStrategies(strategy).create(); } @Test - public void testWithGson() { + void testWithGson() { Derived data = new Derived(); data.setId(10); data.setText("some text"); @@ -65,7 +65,7 @@ public class JacksonExclusionStrategyTest { } @Test - public void testShouldSkipField() throws Exception { + void testShouldSkipField() throws Exception { // should skip every field of Data assertTrue(strategy.shouldSkipField(new FieldAttributes(Data.class.getDeclaredField("id")))); assertTrue(strategy.shouldSkipField(new FieldAttributes(Data.class.getDeclaredField("text")))); @@ -75,18 +75,18 @@ public class JacksonExclusionStrategyTest { } @Test - public void testShouldSkipClass() { + void testShouldSkipClass() { assertFalse(strategy.shouldSkipClass(null)); assertFalse(strategy.shouldSkipClass(Object.class)); } @Test - public void testIsManaged() { + void testIsManaged() { // these classes SHOULD be managed Class<?>[] managed = {Data.class, Intfc.class, com.google.gson.TypeAdapter.class}; for (Class<?> clazz : managed) { - assertTrue(clazz.getName(), JacksonExclusionStrategy.isManaged(clazz)); + assertTrue(JacksonExclusionStrategy.isManaged(clazz), clazz.getName()); } // generic classes should NOT be managed @@ -97,7 +97,7 @@ public class JacksonExclusionStrategyTest { MyMap.class, MyList.class, MyJson.class, GenericArrayType.class}; for (Class<?> clazz : unmanaged) { - assertFalse(clazz.getName(), JacksonExclusionStrategy.isManaged(clazz)); + assertFalse(JacksonExclusionStrategy.isManaged(clazz), clazz.getName()); } } @@ -113,7 +113,7 @@ public class JacksonExclusionStrategyTest { return id; } - public void setId(int id) { + void setId(int id) { this.id = id; } @@ -121,7 +121,7 @@ public class JacksonExclusionStrategyTest { return text; } - public void setText(String text) { + void setText(String text) { this.text = text; } } @@ -134,7 +134,7 @@ public class JacksonExclusionStrategyTest { return value; } - public void setValue(String value) { + void setValue(String value) { this.value = value; } } diff --git a/gson/src/test/java/org/onap/policy/common/gson/JacksonFieldAdapterFactoryTest.java b/gson/src/test/java/org/onap/policy/common/gson/JacksonFieldAdapterFactoryTest.java index dc62186b..65bf90f0 100644 --- a/gson/src/test/java/org/onap/policy/common/gson/JacksonFieldAdapterFactoryTest.java +++ b/gson/src/test/java/org/onap/policy/common/gson/JacksonFieldAdapterFactoryTest.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,10 +21,10 @@ package org.onap.policy.common.gson; -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.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 com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -32,11 +33,11 @@ import com.google.gson.reflect.TypeToken; import java.util.ArrayList; import java.util.List; import lombok.ToString; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.policy.common.gson.annotation.GsonJsonIgnore; import org.onap.policy.common.gson.annotation.GsonJsonProperty; -public class JacksonFieldAdapterFactoryTest { +class JacksonFieldAdapterFactoryTest { private static JacksonFieldAdapterFactory factory = new JacksonFieldAdapterFactory(); @@ -44,7 +45,7 @@ public class JacksonFieldAdapterFactoryTest { .registerTypeAdapterFactory(factory).create(); @Test - public void testCreate() { + void testCreate() { // unhandled types assertNull(factory.create(gson, TypeToken.get(JsonElement.class))); assertNull(factory.create(gson, TypeToken.get(NothingToSerialize.class))); @@ -83,7 +84,7 @@ public class JacksonFieldAdapterFactoryTest { } @Test - public void testCreate_Lists() { + void testCreate_Lists() { DataList lst = new DataList(); lst.theList = new ArrayList<>(); lst.theList.add(new Data(200, "text 20")); @@ -99,7 +100,7 @@ public class JacksonFieldAdapterFactoryTest { } @Test - public void testCreate_OnlyOutProps() { + void testCreate_OnlyOutProps() { InFieldIgnored data = new InFieldIgnored(); data.value = "out only"; @@ -113,7 +114,7 @@ public class JacksonFieldAdapterFactoryTest { } @Test - public void testCreate_OnlyInProps() { + void testCreate_OnlyInProps() { OutFieldIgnored data = new OutFieldIgnored(); data.value = "in only"; @@ -154,7 +155,7 @@ public class JacksonFieldAdapterFactoryTest { this.text = text; } - public void setId(int id) { + void setId(int id) { this.id = id; } } diff --git a/gson/src/test/java/org/onap/policy/common/gson/JacksonHandlerTest.java b/gson/src/test/java/org/onap/policy/common/gson/JacksonHandlerTest.java index 7131817d..316104c5 100644 --- a/gson/src/test/java/org/onap/policy/common/gson/JacksonHandlerTest.java +++ b/gson/src/test/java/org/onap/policy/common/gson/JacksonHandlerTest.java @@ -3,7 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2023 Nordix Foundation. + * Modifications 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. @@ -21,9 +21,9 @@ package org.onap.policy.common.gson; -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 com.google.gson.Gson; import com.google.gson.JsonObject; @@ -35,14 +35,14 @@ import java.util.HashMap; import java.util.Map; import java.util.TreeMap; import lombok.ToString; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.policy.common.gson.annotation.GsonJsonAnyGetter; import org.onap.policy.common.gson.annotation.GsonJsonAnySetter; -public class JacksonHandlerTest { +class JacksonHandlerTest { @Test - public void test() throws Exception { + void test() throws Exception { JacksonHandler hdlr = new JacksonHandler(); assertTrue(hdlr.isReadable(null, null, null, MediaType.APPLICATION_JSON_TYPE)); @@ -85,7 +85,7 @@ public class JacksonHandlerTest { } @Test - public void testMapDouble() throws Exception { + void testMapDouble() throws Exception { MyMap map = new MyMap(); map.props = new HashMap<>(); map.props.put("plainString", "def"); diff --git a/gson/src/test/java/org/onap/policy/common/gson/JacksonMethodAdapterFactoryTest.java b/gson/src/test/java/org/onap/policy/common/gson/JacksonMethodAdapterFactoryTest.java index 7afb0e5a..41996941 100644 --- a/gson/src/test/java/org/onap/policy/common/gson/JacksonMethodAdapterFactoryTest.java +++ b/gson/src/test/java/org/onap/policy/common/gson/JacksonMethodAdapterFactoryTest.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,11 +21,11 @@ package org.onap.policy.common.gson; -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 com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -33,13 +34,13 @@ import com.google.gson.reflect.TypeToken; import java.util.Map; import java.util.TreeMap; import lombok.ToString; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.policy.common.gson.annotation.GsonJsonAnyGetter; import org.onap.policy.common.gson.annotation.GsonJsonAnySetter; import org.onap.policy.common.gson.annotation.GsonJsonIgnore; import org.onap.policy.common.gson.annotation.GsonJsonProperty; -public class JacksonMethodAdapterFactoryTest { +class JacksonMethodAdapterFactoryTest { private static JacksonMethodAdapterFactory factory = new JacksonMethodAdapterFactory(); @@ -47,7 +48,7 @@ public class JacksonMethodAdapterFactoryTest { .registerTypeAdapterFactory(factory).create(); @Test - public void testCreate() { + void testCreate() { // unhandled types assertNull(factory.create(gson, TypeToken.get(JsonElement.class))); assertNull(factory.create(gson, TypeToken.get(NothingToSerialize.class))); @@ -101,8 +102,8 @@ public class JacksonMethodAdapterFactoryTest { dblget.overMap.put("getB", 110); String result2 = gson.toJson(dblget); - dblget.overMap.keySet().forEach(key -> assertTrue("over contains " + key, result2.contains(key))); - der.map.keySet().forEach(key -> assertFalse("sub contains " + key, result2.contains(key))); + dblget.overMap.keySet().forEach(key -> assertTrue(result2.contains(key), "over contains " + key)); + der.map.keySet().forEach(key -> assertFalse(result2.contains(key), "sub contains " + key)); // override of AnySetter Map<String, Integer> map = new TreeMap<>(); diff --git a/gson/src/test/java/org/onap/policy/common/gson/LocalDateTimeTypeAdapterTest.java b/gson/src/test/java/org/onap/policy/common/gson/LocalDateTimeTypeAdapterTest.java index 2778a4ba..87f3c46d 100644 --- a/gson/src/test/java/org/onap/policy/common/gson/LocalDateTimeTypeAdapterTest.java +++ b/gson/src/test/java/org/onap/policy/common/gson/LocalDateTimeTypeAdapterTest.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. @@ -22,21 +23,21 @@ package org.onap.policy.common.gson; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonParseException; import java.time.LocalDateTime; import lombok.ToString; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class LocalDateTimeTypeAdapterTest { +class LocalDateTimeTypeAdapterTest { private static Gson gson = new GsonBuilder().registerTypeAdapter(LocalDateTime.class, new LocalDateTimeTypeAdapter()).create(); @Test - public void test() { + void test() { InterestingFields data = new InterestingFields(); data.date = LocalDateTime.of(2020, 2, 3, 4, 5, 6, 789000000); diff --git a/gson/src/test/java/org/onap/policy/common/gson/LocalDateTypeAdapterTest.java b/gson/src/test/java/org/onap/policy/common/gson/LocalDateTypeAdapterTest.java index 17acf5e6..b62a19b6 100644 --- a/gson/src/test/java/org/onap/policy/common/gson/LocalDateTypeAdapterTest.java +++ b/gson/src/test/java/org/onap/policy/common/gson/LocalDateTypeAdapterTest.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. @@ -22,22 +23,22 @@ package org.onap.policy.common.gson; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonParseException; import java.time.LocalDate; import lombok.ToString; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class LocalDateTypeAdapterTest { +class LocalDateTypeAdapterTest { private static Gson gson = new GsonBuilder().registerTypeAdapter(LocalDate.class, new LocalDateTypeAdapter()).create(); private static final String TEST_DATE = "2020-01-01"; @Test - public void test() { + void test() { InterestingFields data = new InterestingFields(); data.date = LocalDate.parse(TEST_DATE); diff --git a/gson/src/test/java/org/onap/policy/common/gson/MapDoubleAdapterFactoryTest.java b/gson/src/test/java/org/onap/policy/common/gson/MapDoubleAdapterFactoryTest.java index 30d99466..048e09e5 100644 --- a/gson/src/test/java/org/onap/policy/common/gson/MapDoubleAdapterFactoryTest.java +++ b/gson/src/test/java/org/onap/policy/common/gson/MapDoubleAdapterFactoryTest.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. @@ -20,8 +21,8 @@ package org.onap.policy.common.gson; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -30,14 +31,14 @@ import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class MapDoubleAdapterFactoryTest { +class MapDoubleAdapterFactoryTest { private static Gson gson = new GsonBuilder().registerTypeAdapterFactory(new MapDoubleAdapterFactory()).create(); @Test @SuppressWarnings("unchecked") - public void testMap() { + void testMap() { MyMap map = new MyMap(); map.data = new HashMap<>(); map.data.put("plainString", "def"); @@ -71,7 +72,7 @@ public class MapDoubleAdapterFactoryTest { } @Test - public void testList() { + void testList() { MyList list = new MyList(); list.data = new ArrayList<>(); list.data.add("ghi"); @@ -93,7 +94,7 @@ public class MapDoubleAdapterFactoryTest { } @Test - public void test_ValueIsNotObject() { + void test_ValueIsNotObject() { MyDoubleMap map = new MyDoubleMap(); map.data = new LinkedHashMap<>(); map.data.put("plainDouble", 13.5); @@ -110,7 +111,7 @@ public class MapDoubleAdapterFactoryTest { } @Test - public void test_KeyIsNotString() { + void test_KeyIsNotString() { MyObjectMap map = new MyObjectMap(); map.data = new LinkedHashMap<>(); @@ -128,7 +129,7 @@ public class MapDoubleAdapterFactoryTest { } @Test - public void test_ListValueIsNotObject() { + void test_ListValueIsNotObject() { MyDoubleList list = new MyDoubleList(); list.data = new ArrayList<>(); list.data.add(13.5); diff --git a/gson/src/test/java/org/onap/policy/common/gson/OffsetDateTimeAdapterTest.java b/gson/src/test/java/org/onap/policy/common/gson/OffsetDateTimeAdapterTest.java index a0bcb1b2..33212b89 100644 --- a/gson/src/test/java/org/onap/policy/common/gson/OffsetDateTimeAdapterTest.java +++ b/gson/src/test/java/org/onap/policy/common/gson/OffsetDateTimeAdapterTest.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. @@ -22,22 +23,22 @@ package org.onap.policy.common.gson; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonParseException; import java.time.OffsetDateTime; import lombok.ToString; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class OffsetDateTimeAdapterTest { +class OffsetDateTimeAdapterTest { private static Gson gson = new GsonBuilder().registerTypeAdapter(OffsetDateTime.class, new OffsetDateTimeTypeAdapter()).create(); private static final String TEST_DATE = "2020-01-01T12:00:00.999+05:00"; @Test - public void test() { + void test() { InterestingFields data = new InterestingFields(); data.date = OffsetDateTime.parse(TEST_DATE); diff --git a/gson/src/test/java/org/onap/policy/common/gson/OffsetTimeTypeAdapterTest.java b/gson/src/test/java/org/onap/policy/common/gson/OffsetTimeTypeAdapterTest.java index 8098af98..27f179f1 100644 --- a/gson/src/test/java/org/onap/policy/common/gson/OffsetTimeTypeAdapterTest.java +++ b/gson/src/test/java/org/onap/policy/common/gson/OffsetTimeTypeAdapterTest.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. @@ -22,22 +23,22 @@ package org.onap.policy.common.gson; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonParseException; import java.time.OffsetTime; import lombok.ToString; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class OffsetTimeTypeAdapterTest { +class OffsetTimeTypeAdapterTest { private static Gson gson = new GsonBuilder().registerTypeAdapter(OffsetTime.class, new OffsetTimeTypeAdapter()).create(); private static final String TEST_TIME = "12:00:00.999+05:00"; @Test - public void test() { + void test() { InterestingFields data = new InterestingFields(); data.time = OffsetTime.parse(TEST_TIME); diff --git a/gson/src/test/java/org/onap/policy/common/gson/StringTypeAdapterTest.java b/gson/src/test/java/org/onap/policy/common/gson/StringTypeAdapterTest.java index f35677cd..a2027512 100644 --- a/gson/src/test/java/org/onap/policy/common/gson/StringTypeAdapterTest.java +++ b/gson/src/test/java/org/onap/policy/common/gson/StringTypeAdapterTest.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. @@ -22,7 +23,7 @@ package org.onap.policy.common.gson; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -30,15 +31,15 @@ import com.google.gson.JsonParseException; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.ToString; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class StringTypeAdapterTest { +class StringTypeAdapterTest { private static Gson gson = new GsonBuilder().registerTypeAdapter(MyData.class, new MyAdapter()).create(); private static final int TEST_NUM1 = 10; private static final int TEST_NUM3 = 30; @Test - public void test() { + void test() { InterestingFields data = new InterestingFields(); data.data1 = new MyData(TEST_NUM1); data.data2 = null; diff --git a/gson/src/test/java/org/onap/policy/common/gson/ZoneOffsetTypeAdapterTest.java b/gson/src/test/java/org/onap/policy/common/gson/ZoneOffsetTypeAdapterTest.java index d9a33169..a334c307 100644 --- a/gson/src/test/java/org/onap/policy/common/gson/ZoneOffsetTypeAdapterTest.java +++ b/gson/src/test/java/org/onap/policy/common/gson/ZoneOffsetTypeAdapterTest.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. @@ -22,22 +23,22 @@ package org.onap.policy.common.gson; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonParseException; import java.time.ZoneOffset; import lombok.ToString; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class ZoneOffsetTypeAdapterTest { +class ZoneOffsetTypeAdapterTest { private static Gson gson = new GsonBuilder().registerTypeAdapter(ZoneOffset.class, new ZoneOffsetTypeAdapter()).create(); private static final String TEST_ZONE = "+05:00"; @Test - public void test() { + void test() { InterestingFields data = new InterestingFields(); data.zone = ZoneOffset.of(TEST_ZONE); diff --git a/gson/src/test/java/org/onap/policy/common/gson/ZonedDateTimeTypeAdapterTest.java b/gson/src/test/java/org/onap/policy/common/gson/ZonedDateTimeTypeAdapterTest.java index 032533eb..bf534a5c 100644 --- a/gson/src/test/java/org/onap/policy/common/gson/ZonedDateTimeTypeAdapterTest.java +++ b/gson/src/test/java/org/onap/policy/common/gson/ZonedDateTimeTypeAdapterTest.java @@ -3,6 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 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. @@ -22,7 +23,7 @@ package org.onap.policy.common.gson; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -30,14 +31,14 @@ import com.google.gson.JsonParseException; import java.time.ZoneId; import java.time.ZonedDateTime; import lombok.ToString; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class ZonedDateTimeTypeAdapterTest { +class ZonedDateTimeTypeAdapterTest { private static Gson gson = new GsonBuilder().registerTypeAdapter(ZonedDateTime.class, new ZonedDateTimeTypeAdapter()).create(); @Test - public void test() { + void test() { InterestingFields data = new InterestingFields(); data.date = ZonedDateTime.of(2020, 2, 3, 4, 5, 6, 789000000, ZoneId.of("US/Eastern")); diff --git a/gson/src/test/java/org/onap/policy/common/gson/internal/AdapterTest.java b/gson/src/test/java/org/onap/policy/common/gson/internal/AdapterTest.java index fd999951..ebe2b727 100644 --- a/gson/src/test/java/org/onap/policy/common/gson/internal/AdapterTest.java +++ b/gson/src/test/java/org/onap/policy/common/gson/internal/AdapterTest.java @@ -3,7 +3,7 @@ * ONAP * ================================================================================ * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2023 Nordix Foundation. + * Modifications 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. @@ -21,9 +21,9 @@ package org.onap.policy.common.gson.internal; -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 static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -35,9 +35,9 @@ import com.google.gson.JsonPrimitive; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.List; -import org.junit.After; -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.Test; import org.onap.policy.common.gson.JacksonExclusionStrategy; import org.onap.policy.common.gson.annotation.GsonJsonProperty; import org.onap.policy.common.gson.internal.Adapter.Factory; @@ -45,7 +45,7 @@ import org.onap.policy.common.gson.internal.DataAdapterFactory.Data; import org.onap.policy.common.gson.internal.DataAdapterFactory.DerivedData; import org.springframework.test.util.ReflectionTestUtils; -public class AdapterTest { +class AdapterTest { private static final String GET_INVALID_NAME = "get$InvalidName"; private static final String SET_INVALID_NAME = "set$InvalidName"; private static final String EMPTY_ALIAS = "emptyAlias"; @@ -82,18 +82,18 @@ public class AdapterTest { private Data dataField; - @BeforeClass + @BeforeAll public static void setUpBeforeClass() { saveFactory = (Factory) ReflectionTestUtils.getField(Adapter.class, FACTORY_FIELD); } - @After - public void tearDown() { + @AfterEach + void tearDown() { ReflectionTestUtils.setField(Adapter.class, FACTORY_FIELD, saveFactory); } @Test - public void testIsManagedField() { + void testIsManagedField() { assertTrue(Adapter.isManaged(field(VALUE_NAME))); // return an invalid field name @@ -104,7 +104,7 @@ public class AdapterTest { } @Test - public void testIsManagedMethod() { + void testIsManagedMethod() { assertTrue(Adapter.isManaged(mget(GET_VALUE_NAME))); // return an invalid method name @@ -119,7 +119,7 @@ public class AdapterTest { } @Test - public void testAdapterField_Converter() { + void testAdapterField_Converter() { Adapter adapter = new Adapter(gson, field("dataField")); // first, write something of type Data @@ -137,7 +137,7 @@ public class AdapterTest { @Test @SuppressWarnings("unchecked") - public void testAdapterField_Converter_List() { + void testAdapterField_Converter_List() { listField = DataAdapterFactory.makeList(); Adapter adapter = new Adapter(gson, field("listField")); @@ -168,7 +168,7 @@ public class AdapterTest { } @Test - public void testAdapterMethod_Converter() throws Exception { + void testAdapterMethod_Converter() throws Exception { listField = DataAdapterFactory.makeList(); Method getter = mget("getMyList"); @@ -192,7 +192,7 @@ public class AdapterTest { } @Test - public void testGetPropName_testGetFullName_testMakeError() { + void testGetPropName_testGetFullName_testMakeError() { // test field Adapter adapter = new Adapter(gson, field(VALUE_NAME)); @@ -217,7 +217,7 @@ public class AdapterTest { } @Test - public void testToJsonTree() { + void testToJsonTree() { Adapter adapter = new Adapter(gson, field(VALUE_NAME)); JsonElement tree = adapter.toJsonTree("hello"); @@ -226,14 +226,14 @@ public class AdapterTest { } @Test - public void testFromJsonTree() { + void testFromJsonTree() { Adapter adapter = new Adapter(gson, field(VALUE_NAME)); assertEquals("world", adapter.fromJsonTree(new JsonPrimitive("world"))); } @Test - public void testDetmPropName() { + void testDetmPropName() { assertEquals(EMPTY_ALIAS, Adapter.detmPropName(field(EMPTY_ALIAS))); assertEquals("name-with-alias", Adapter.detmPropName(field("nameWithAlias"))); assertEquals("unaliased", Adapter.detmPropName(field("unaliased"))); @@ -246,7 +246,7 @@ public class AdapterTest { } @Test - public void testDetmGetterPropName() { + void testDetmGetterPropName() { assertEquals(EMPTY_ALIAS, Adapter.detmGetterPropName(mget("getEmptyAlias"))); assertEquals("get-with-alias", Adapter.detmGetterPropName(mget("getWithAlias"))); assertEquals("plain", Adapter.detmGetterPropName(mget("getPlain"))); @@ -265,7 +265,7 @@ public class AdapterTest { } @Test - public void testDetmSetterPropName() { + void testDetmSetterPropName() { assertEquals(EMPTY_ALIAS, Adapter.detmSetterPropName(mset("setEmptyAlias"))); assertEquals("set-with-alias", Adapter.detmSetterPropName(mset("setWithAlias"))); assertEquals("plain", Adapter.detmSetterPropName(mset("setPlain"))); @@ -281,12 +281,12 @@ public class AdapterTest { } @Test - public void testGetQualifiedNameField() throws Exception { + void testGetQualifiedNameField() throws Exception { assertEquals(MY_NAME + ".value", Adapter.getQualifiedName(AdapterTest.class.getDeclaredField(VALUE_NAME))); } @Test - public void testGetQualifiedNameMethod() { + void testGetQualifiedNameMethod() { assertEquals(MY_NAME + GET_VALUE, Adapter.getQualifiedName(mget(GET_VALUE_NAME))); } diff --git a/gson/src/test/java/org/onap/policy/common/gson/internal/AnyGetterSerializerTest.java b/gson/src/test/java/org/onap/policy/common/gson/internal/AnyGetterSerializerTest.java index f68e3e3e..1e206cf5 100644 --- a/gson/src/test/java/org/onap/policy/common/gson/internal/AnyGetterSerializerTest.java +++ b/gson/src/test/java/org/onap/policy/common/gson/internal/AnyGetterSerializerTest.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,8 +22,8 @@ package org.onap.policy.common.gson.internal; import static org.assertj.core.api.Assertions.assertThatThrownBy; -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 com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -33,12 +34,12 @@ import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.common.gson.JacksonExclusionStrategy; import org.onap.policy.common.gson.internal.DataAdapterFactory.Data; -public class AnyGetterSerializerTest { +class AnyGetterSerializerTest { private static DataAdapterFactory dataAdapter = new DataAdapterFactory(); @@ -53,14 +54,14 @@ public class AnyGetterSerializerTest { * * @throws Exception if an error occurs */ - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { set = new HashSet<>(Arrays.asList("id", "value")); ser = new AnyGetterSerializer(gson, set, MapData.class.getDeclaredMethod("getTheMap")); } @Test - public void testAddToTree_testCopyLiftedItems() { + void testAddToTree_testCopyLiftedItems() { JsonObject tree = new JsonObject(); tree.addProperty("hello", "world"); @@ -83,7 +84,7 @@ public class AnyGetterSerializerTest { } @Test - public void testAddToTree_NullMap() { + void testAddToTree_NullMap() { JsonObject tree = new JsonObject(); tree.addProperty("hello", "world"); @@ -98,7 +99,7 @@ public class AnyGetterSerializerTest { } @Test - public void testAddToTree_NotAnObject() throws Exception { + void testAddToTree_NotAnObject() throws Exception { ser = new AnyGetterSerializer(gson, set, NotAnObject.class.getDeclaredMethod("getNonMap")); JsonObject tree = new JsonObject(); diff --git a/gson/src/test/java/org/onap/policy/common/gson/internal/AnySetterDeserializerTest.java b/gson/src/test/java/org/onap/policy/common/gson/internal/AnySetterDeserializerTest.java index c03e3695..d833925b 100644 --- a/gson/src/test/java/org/onap/policy/common/gson/internal/AnySetterDeserializerTest.java +++ b/gson/src/test/java/org/onap/policy/common/gson/internal/AnySetterDeserializerTest.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,9 +21,9 @@ package org.onap.policy.common.gson.internal; -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 com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -33,12 +34,12 @@ import java.util.List; import java.util.Map; import java.util.Set; import java.util.TreeMap; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.common.gson.JacksonExclusionStrategy; import org.onap.policy.common.gson.internal.DataAdapterFactory.Data; -public class AnySetterDeserializerTest { +class AnySetterDeserializerTest { private static DataAdapterFactory dataAdapter = new DataAdapterFactory(); @@ -53,15 +54,15 @@ public class AnySetterDeserializerTest { * * @throws Exception if an error occurs */ - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { set = new HashSet<>(Arrays.asList("id", "value")); deser = new AnySetterDeserializer(gson, set, MapData.class.getDeclaredMethod("setItem", String.class, List.class)); } @Test - public void testAnySetterDeserializer() { + void testAnySetterDeserializer() { JsonObject json = new JsonObject(); // these should not be copied diff --git a/gson/src/test/java/org/onap/policy/common/gson/internal/ClassWalkerTest.java b/gson/src/test/java/org/onap/policy/common/gson/internal/ClassWalkerTest.java index a1350643..ee55c626 100644 --- a/gson/src/test/java/org/onap/policy/common/gson/internal/ClassWalkerTest.java +++ b/gson/src/test/java/org/onap/policy/common/gson/internal/ClassWalkerTest.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,9 +22,9 @@ package org.onap.policy.common.gson.internal; 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.JsonParseException; import java.lang.reflect.Field; @@ -36,14 +37,14 @@ import java.util.Map; import java.util.TreeMap; import java.util.TreeSet; import java.util.stream.Collectors; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.onap.policy.common.gson.annotation.GsonJsonAnyGetter; import org.onap.policy.common.gson.annotation.GsonJsonAnySetter; import org.onap.policy.common.gson.annotation.GsonJsonIgnore; import org.onap.policy.common.gson.annotation.GsonJsonProperty; -public class ClassWalkerTest { +class ClassWalkerTest { private static final String SET_OVERRIDE = ".setOverride"; private static final String INVALID_FIELD_NAME = "invalidFieldName"; @@ -53,13 +54,13 @@ public class ClassWalkerTest { /** * Set up. */ - @Before - public void setUp() { + @BeforeEach + void setUp() { walker = new MyWalker(); } @Test - public void testExamineClassOfQ_testExamineField_testExamineInField_testExamineOutField() { + void testExamineClassOfQ_testExamineField_testExamineInField_testExamineOutField() { walker.walkClassHierarchy(DerivedFromBottom.class); assertEquals("[Intfc1, Intfc2, Intfc1, Intfc3, Bottom, DerivedFromBottom]", walker.classes.toString()); @@ -79,7 +80,7 @@ public class ClassWalkerTest { } @Test - public void testHasAnyGetter() { + void testHasAnyGetter() { walker.walkClassHierarchy(Object.class); assertNull(walker.getAnyGetter()); assertNull(walker.getAnySetter()); @@ -94,7 +95,7 @@ public class ClassWalkerTest { } @Test - public void testHasAnySetter() { + void testHasAnySetter() { walker.walkClassHierarchy(Object.class); assertNull(walker.getAnySetter()); assertNull(walker.getAnyGetter()); @@ -109,7 +110,7 @@ public class ClassWalkerTest { } @Test - public void testExamineMethod() { + void testExamineMethod() { walker.walkClassHierarchy(DerivedFromData.class); assertEquals("[Data, DerivedFromData]", walker.classes.toString()); @@ -161,7 +162,7 @@ public class ClassWalkerTest { } @Test - public void testExamineMethod_AnyGetter() { + void testExamineMethod_AnyGetter() { walker.walkClassHierarchy(AnyGetterOverride.class); assertNotNull(walker.getAnyGetter()); @@ -169,7 +170,7 @@ public class ClassWalkerTest { } @Test - public void testExamineMethod_AnySetter() { + void testExamineMethod_AnySetter() { walker.walkClassHierarchy(AnySetterOverride.class); assertNotNull(walker.getAnySetter()); @@ -177,7 +178,7 @@ public class ClassWalkerTest { } @Test - public void testGetInNotIgnored_testGetOutNotIgnored() { + void testGetInNotIgnored_testGetOutNotIgnored() { walker.walkClassHierarchy(DerivedFromData.class); assertEquals("[id, onlyIn, text, value]", new TreeSet<>(walker.getInNotIgnored()).toString()); diff --git a/gson/src/test/java/org/onap/policy/common/gson/internal/FieldDeserializerTest.java b/gson/src/test/java/org/onap/policy/common/gson/internal/FieldDeserializerTest.java index acb241e6..8f783bcb 100644 --- a/gson/src/test/java/org/onap/policy/common/gson/internal/FieldDeserializerTest.java +++ b/gson/src/test/java/org/onap/policy/common/gson/internal/FieldDeserializerTest.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,8 +22,8 @@ package org.onap.policy.common.gson.internal; import static org.assertj.core.api.Assertions.assertThatThrownBy; -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 com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -31,11 +32,11 @@ import com.google.gson.JsonNull; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.policy.common.gson.JacksonExclusionStrategy; import org.onap.policy.common.gson.internal.DataAdapterFactory.Data; -public class FieldDeserializerTest { +class FieldDeserializerTest { private static final String TEXT_FIELD_NAME = "text"; private static final String LIST_FIELD_NAME = "listField"; private static final String INITIAL_VALUE = "initial value"; @@ -53,7 +54,7 @@ public class FieldDeserializerTest { private List<Data> listField; @Test - public void testGetFromTree() throws Exception { + void testGetFromTree() throws Exception { deser = new FieldDeserializer(gson, FieldDeserializerTest.class.getDeclaredField(TEXT_FIELD_NAME)); JsonObject json = new JsonObject(); @@ -90,7 +91,7 @@ public class FieldDeserializerTest { } @Test - public void testGetFromTree_SetEx() throws Exception { + void testGetFromTree_SetEx() throws Exception { deser = new FieldDeserializer(gson, FieldDeserializerTest.class.getDeclaredField(TEXT_FIELD_NAME)) { @Override public Object fromJsonTree(JsonElement tree) { diff --git a/gson/src/test/java/org/onap/policy/common/gson/internal/FieldSerializerTest.java b/gson/src/test/java/org/onap/policy/common/gson/internal/FieldSerializerTest.java index 156e4ef3..a55d9908 100644 --- a/gson/src/test/java/org/onap/policy/common/gson/internal/FieldSerializerTest.java +++ b/gson/src/test/java/org/onap/policy/common/gson/internal/FieldSerializerTest.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,8 +22,8 @@ package org.onap.policy.common.gson.internal; import static org.assertj.core.api.Assertions.assertThatThrownBy; -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 com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -30,11 +31,11 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParseException; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.policy.common.gson.JacksonExclusionStrategy; import org.onap.policy.common.gson.internal.DataAdapterFactory.Data; -public class FieldSerializerTest { +class FieldSerializerTest { private static final String TEXT_FIELD_NAME = "text"; private static final String LIST_FIELD_NAME = "listField"; @@ -79,7 +80,7 @@ public class FieldSerializerTest { } @Test - public void testAddToTree_GetEx() throws Exception { + void testAddToTree_GetEx() throws Exception { ser = new FieldSerializer(gson, FieldSerializerTest.class.getDeclaredField(TEXT_FIELD_NAME)) { @Override protected Object getFromObject(Object source) throws IllegalAccessException { diff --git a/gson/src/test/java/org/onap/policy/common/gson/internal/JacksonTypeAdapterTest.java b/gson/src/test/java/org/onap/policy/common/gson/internal/JacksonTypeAdapterTest.java index 5e73d06e..e2d350ec 100644 --- a/gson/src/test/java/org/onap/policy/common/gson/internal/JacksonTypeAdapterTest.java +++ b/gson/src/test/java/org/onap/policy/common/gson/internal/JacksonTypeAdapterTest.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,7 +21,7 @@ package org.onap.policy.common.gson.internal; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -34,10 +35,10 @@ import java.io.StringWriter; import java.util.ArrayList; import java.util.List; 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 JacksonTypeAdapterTest { +class JacksonTypeAdapterTest { private static final String HELLO = "hello"; private static final String WORLD = "world"; @@ -53,8 +54,8 @@ public class JacksonTypeAdapterTest { /** * Initializes the previously defined fields. */ - @Before - public void setUp() { + @BeforeEach + void setUp() { // create list of serializers, one for "id" and one for "value" sers = new ArrayList<>(2); sers.add(new NamedSer(HELLO) { @@ -91,7 +92,7 @@ public class JacksonTypeAdapterTest { } @Test - public void testWriteJsonWriterT() throws Exception { + void testWriteJsonWriterT() throws Exception { Data data = new Data("abc", "def"); StringWriter wtr = new StringWriter(); @@ -106,7 +107,7 @@ public class JacksonTypeAdapterTest { * @throws Exception if an error occurs */ @Test - public void testWriteJsonWriterT_NotAnObject() throws Exception { + void testWriteJsonWriterT_NotAnObject() throws Exception { TypeAdapter<String> delegate = gson.getAdapter(String.class); JacksonTypeAdapter<String> stringAdapter = new JacksonTypeAdapter<>(gson, delegate, sers, desers); @@ -117,7 +118,7 @@ public class JacksonTypeAdapterTest { } @Test - public void testReadJsonReader() throws Exception { + void testReadJsonReader() throws Exception { Data data = adapter .read(new JsonReader(new StringReader("{'hello':'four','world':'score'}".replace('\'', '"')))); @@ -130,7 +131,7 @@ public class JacksonTypeAdapterTest { * @throws Exception if an error occurs */ @Test - public void testReadJsonReader_NotAnObject() throws Exception { + void testReadJsonReader_NotAnObject() throws Exception { TypeAdapter<String> delegate = gson.getAdapter(String.class); JacksonTypeAdapter<String> stringAdapter = new JacksonTypeAdapter<>(gson, delegate, sers, desers); diff --git a/gson/src/test/java/org/onap/policy/common/gson/internal/LifterTest.java b/gson/src/test/java/org/onap/policy/common/gson/internal/LifterTest.java index e0b9eb30..e83757b6 100644 --- a/gson/src/test/java/org/onap/policy/common/gson/internal/LifterTest.java +++ b/gson/src/test/java/org/onap/policy/common/gson/internal/LifterTest.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,21 +21,21 @@ package org.onap.policy.common.gson.internal; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import com.google.gson.Gson; import java.util.Arrays; import java.util.HashSet; import java.util.Set; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class LifterTest { +class LifterTest { private static Gson gson = new Gson(); @Test - public void testLifter_testShouldLift() throws Exception { + void testLifter_testShouldLift() throws Exception { Set<String> set = new HashSet<>(Arrays.asList("abc", "def")); Lifter lifter = new Lifter(gson, set, LifterTest.class.getDeclaredMethod("getValue"), String.class); diff --git a/gson/src/test/java/org/onap/policy/common/gson/internal/MethodAdapterTest.java b/gson/src/test/java/org/onap/policy/common/gson/internal/MethodAdapterTest.java index 6c13865d..17a184a3 100644 --- a/gson/src/test/java/org/onap/policy/common/gson/internal/MethodAdapterTest.java +++ b/gson/src/test/java/org/onap/policy/common/gson/internal/MethodAdapterTest.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,19 +22,19 @@ package org.onap.policy.common.gson.internal; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import com.google.gson.Gson; import com.google.gson.JsonParseException; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class MethodAdapterTest { +class MethodAdapterTest { private static final Gson gson = new Gson(); private String saved; @Test - public void testMethodAdapter_testInvoke() throws Exception { + void testMethodAdapter_testInvoke() throws Exception { MethodAdapter adapter = new MethodAdapter(gson, MethodAdapterTest.class.getDeclaredMethod("getValue"), String.class); assertEquals("hello", adapter.invoke(this)); @@ -51,7 +52,7 @@ public class MethodAdapterTest { return "hello"; } - public void setValue(String val) { + void setValue(String val) { saved = val; } } diff --git a/gson/src/test/java/org/onap/policy/common/gson/internal/MethodDeserializerTest.java b/gson/src/test/java/org/onap/policy/common/gson/internal/MethodDeserializerTest.java index 7fcfca18..60fe7a0a 100644 --- a/gson/src/test/java/org/onap/policy/common/gson/internal/MethodDeserializerTest.java +++ b/gson/src/test/java/org/onap/policy/common/gson/internal/MethodDeserializerTest.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. @@ -20,20 +21,20 @@ package org.onap.policy.common.gson.internal; -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 com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonNull; import com.google.gson.JsonObject; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.policy.common.gson.JacksonExclusionStrategy; import org.onap.policy.common.gson.internal.DataAdapterFactory.Data; -public class MethodDeserializerTest { +class MethodDeserializerTest { private static final String PROP_NAME = "text"; private static final String METHOD_NAME = "setText"; private static final String INITIAL_VALUE = "initial value"; @@ -51,7 +52,7 @@ public class MethodDeserializerTest { private List<Data> listField; @Test - public void testGetFromTree() throws Exception { + void testGetFromTree() throws Exception { deser = new MethodDeserializer(gson, MethodDeserializerTest.class.getDeclaredMethod(METHOD_NAME, String.class)); // non-existent value - should not overwrite diff --git a/gson/src/test/java/org/onap/policy/common/gson/internal/MethodSerializerTest.java b/gson/src/test/java/org/onap/policy/common/gson/internal/MethodSerializerTest.java index ed240513..ae41e08d 100644 --- a/gson/src/test/java/org/onap/policy/common/gson/internal/MethodSerializerTest.java +++ b/gson/src/test/java/org/onap/policy/common/gson/internal/MethodSerializerTest.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. @@ -20,19 +21,19 @@ package org.onap.policy.common.gson.internal; -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 com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import java.util.List; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.onap.policy.common.gson.JacksonExclusionStrategy; import org.onap.policy.common.gson.internal.DataAdapterFactory.Data; -public class MethodSerializerTest { +class MethodSerializerTest { private static final String PROP_NAME = "text"; private static final String METHOD_NAME = "getText"; @@ -48,7 +49,7 @@ public class MethodSerializerTest { private List<Data> listField; @Test - public void testAddToTree() throws Exception { + void testAddToTree() throws Exception { ser = new MethodSerializer(gson, MethodSerializerTest.class.getDeclaredMethod(METHOD_NAME)); // serialize null value first @@ -74,7 +75,7 @@ public class MethodSerializerTest { JsonElement tree = ser.toJsonTree(listField); assertTrue(dataAdapter.isDataWritten()); - assertEquals(DataAdapterFactory.ENCODED_LIST, tree.toString()); + assertEquals(DataAdapterFactory.ENCODED_LIST, tree.toString()); } protected String getText() { @@ -100,4 +100,10 @@ </plugin> </plugins> </reporting> + <dependencies> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-api</artifactId> + </dependency> + </dependencies> </project> |