Fix simulator topics for lower case
[policy/models.git] / models-sim / models-sim-dmaap / src / test / java / org / onap / policy / models / sim / dmaap / provider / DmaapSimProviderTest.java
index 1473e02..f82ef03 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 package org.onap.policy.models.sim.dmaap.provider;
 
+import static org.assertj.core.api.Assertions.assertThatCode;
 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.mockito.Matchers.any;
-import static org.mockito.Matchers.anyInt;
-import static org.mockito.Matchers.anyLong;
-import static org.mockito.Matchers.eq;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
+import static org.mockito.ArgumentMatchers.anyLong;
+import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.spy;
 import static org.mockito.Mockito.times;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
+import jakarta.ws.rs.core.Response;
+import jakarta.ws.rs.core.Response.Status;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
@@ -38,20 +42,20 @@ import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.runner.RunWith;
 import org.mockito.ArgumentCaptor;
 import org.mockito.Captor;
 import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.mockito.junit.MockitoJUnitRunner;
 import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.common.utils.coder.StandardCoder;
 import org.onap.policy.common.utils.coder.StandardCoderObject;
 import org.onap.policy.models.sim.dmaap.parameters.DmaapSimParameterGroup;
 
+@RunWith(MockitoJUnitRunner.class)
 public class DmaapSimProviderTest {
     private static final String EXPECTED_EXCEPTION = "expected exception";
     private static final long SWEEP_SEC = 10L;
@@ -77,13 +81,14 @@ public class DmaapSimProviderTest {
     @Captor
     private ArgumentCaptor<List<Object>> listCaptor;
 
+    @Captor
+    private ArgumentCaptor<List<Object>> listCaptor2;
+
     /**
      * Sets up.
      */
     @Before
     public void setUp() {
-        MockitoAnnotations.initMocks(this);
-
         when(params.getTopicSweepSec()).thenReturn(SWEEP_SEC);
 
         prov = new MyProvider(params);
@@ -100,7 +105,7 @@ public class DmaapSimProviderTest {
     }
 
     /**
-     * Verifies that the constructor adds all of the expected actions to the service
+     * Verifies that the constructor adds all the expected actions to the service
      * manager container.
      */
     @Test
@@ -167,14 +172,12 @@ public class DmaapSimProviderTest {
         verify(prov).makeTopicData(TOPIC2);
 
         // should process all writes as singleton lists
-        listCaptor.getAllValues().clear();
         verify(data1, times(2)).write(listCaptor.capture());
         assertEquals(Collections.singletonList(value1), listCaptor.getAllValues().get(0));
         assertEquals(Collections.singletonList(value2), listCaptor.getAllValues().get(1));
 
-        listCaptor.getAllValues().clear();
-        verify(data2).write(listCaptor.capture());
-        assertEquals(Collections.singletonList(value2), listCaptor.getAllValues().get(0));
+        verify(data2).write(listCaptor2.capture());
+        assertEquals(Collections.singletonList(value2), listCaptor2.getAllValues().get(0));
     }
 
     @Test
@@ -200,7 +203,7 @@ public class DmaapSimProviderTest {
     public void testProcessDmaapMessageGet_Ex() throws InterruptedException {
         BlockingQueue<Response> respQueue = new LinkedBlockingQueue<>();
 
-        // put in a background thread so it doesn't interrupt the tester thread
+        // put in a background thread, so it doesn't interrupt the tester thread
         new Thread(() -> {
             try {
                 when(data1.read(any(), anyInt(), anyLong())).thenThrow(new InterruptedException(EXPECTED_EXCEPTION));
@@ -238,17 +241,18 @@ public class DmaapSimProviderTest {
 
     @Test
     public void testMakeTimerPool() {
-        // use a real provider so we can test the real makeTimer() method
+        // use a real provider, so we can test the real makeTimer() method
         DmaapSimProvider prov2 = new DmaapSimProvider(params);
         prov2.start();
-        prov2.stop();
+        assertThatCode(prov2::stop).doesNotThrowAnyException();
     }
 
     @Test
     public void testMakeTopicData() {
-        // use a real provider so we can test the real makeTopicData() method
+        // use a real provider, so we can test the real makeTopicData() method
         DmaapSimProvider prov2 = new DmaapSimProvider(params);
-        prov2.processDmaapMessageGet(TOPIC1, CONSUMER1, CONSUMER_ID1, 0, 0);
+        assertThatCode(() -> prov2.processDmaapMessageGet(TOPIC1, CONSUMER1, CONSUMER_ID1, 0, 0))
+                        .doesNotThrowAnyException();
     }
 
     @Test
@@ -274,14 +278,11 @@ public class DmaapSimProviderTest {
 
         @Override
         protected TopicData makeTopicData(String topicName) {
-            switch (topicName) {
-                case TOPIC1:
-                    return data1;
-                case TOPIC2:
-                    return data2;
-                default:
-                    throw new IllegalArgumentException("unknown topic name: " + topicName);
-            }
+            return switch (topicName) {
+                case TOPIC1 -> data1;
+                case TOPIC2 -> data2;
+                default -> throw new IllegalArgumentException("unknown topic name: " + topicName);
+            };
         }
     }
 }