diff options
author | Neil Derraugh <neil.derraugh@yoppworks.com> | 2020-05-20 23:59:37 -0400 |
---|---|---|
committer | Neil Derraugh <neil.derraugh@yoppworks.com> | 2020-05-31 12:48:38 -0400 |
commit | 95bdca4419af09c4eeab5562589ea6baf9a4490d (patch) | |
tree | a91c2e9869c3e9f4849026503703e33d80870aa0 /zusammen-lib/src/test | |
parent | 74dc5044f00a113eef41b345390f8c266112b2d7 (diff) |
Upgrade Junit to 5.6
- Update @Before -> @BeforeEach, @After -> @AfterEach
- Update Mockito usage
- Update assertThrows so not to expect exceptions
Issue-ID: SDC-3078
Signed-off-by: Neil Derraugh <neil.derraugh@yoppworks.com>
Change-Id: I0b1056698767c4b060e243bbda799253072b4b55
Diffstat (limited to 'zusammen-lib/src/test')
3 files changed, 48 insertions, 47 deletions
diff --git a/zusammen-lib/src/test/java/org/onap/sdc/common/zusammen/config/ZusammenConfigTest.java b/zusammen-lib/src/test/java/org/onap/sdc/common/zusammen/config/ZusammenConfigTest.java index 007ad69..ce240a6 100644 --- a/zusammen-lib/src/test/java/org/onap/sdc/common/zusammen/config/ZusammenConfigTest.java +++ b/zusammen-lib/src/test/java/org/onap/sdc/common/zusammen/config/ZusammenConfigTest.java @@ -16,9 +16,9 @@ package org.onap.sdc.common.zusammen.config; -import org.junit.After; import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; public class ZusammenConfigTest { @@ -35,7 +35,7 @@ public class ZusammenConfigTest { Assert.assertEquals(a, System.getProperty("cassandra.nodes")); } - @After + @AfterEach public void cleanUp() { System.setProperty("cassandra.nodes", emptyStr); System.setProperty("cassandra.port", emptyStr); diff --git a/zusammen-lib/src/test/java/org/onap/sdc/common/zusammen/persistence/ZusammenConnectorTest.java b/zusammen-lib/src/test/java/org/onap/sdc/common/zusammen/persistence/ZusammenConnectorTest.java index b65cdc9..3ebcaba 100644 --- a/zusammen-lib/src/test/java/org/onap/sdc/common/zusammen/persistence/ZusammenConnectorTest.java +++ b/zusammen-lib/src/test/java/org/onap/sdc/common/zusammen/persistence/ZusammenConnectorTest.java @@ -19,7 +19,7 @@ package org.onap.sdc.common.zusammen.persistence; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; @@ -52,33 +52,29 @@ import com.amdocs.zusammen.datatypes.response.ReturnCode; import com.google.common.collect.ImmutableList; import java.util.Collection; import java.util.List; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; import org.onap.sdc.common.zusammen.persistence.impl.ZusammenConnectorImpl; -@RunWith(MockitoJUnitRunner.class) public class ZusammenConnectorTest { - @Mock - private ItemAdaptorFactory itemAdaptorFactoryMock; - @Mock - private ItemVersionAdaptorFactory versionAdaptorFactoryMock; - @Mock - private ElementAdaptorFactory elementAdaptorFactoryMock; - @Mock - private HealthAdaptorFactory healthAdaptorFactoryMock; + private final ItemAdaptorFactory itemAdaptorFactoryMock = Mockito.mock(ItemAdaptorFactory.class); + + private final ItemVersionAdaptorFactory versionAdaptorFactoryMock = Mockito.mock(ItemVersionAdaptorFactory.class); + + private final ElementAdaptorFactory elementAdaptorFactoryMock = Mockito.mock(ElementAdaptorFactory.class); + + private final HealthAdaptorFactory healthAdaptorFactoryMock = Mockito.mock(HealthAdaptorFactory.class); private ZusammenConnector zusammenConnector; - @Mock - private SessionContext sessionContext; - @Before + private final SessionContext sessionContext = Mockito.mock(SessionContext.class); + + @BeforeEach public void init() { zusammenConnector = - new ZusammenConnectorImpl(itemAdaptorFactoryMock, versionAdaptorFactoryMock, elementAdaptorFactoryMock, - healthAdaptorFactoryMock); + new ZusammenConnectorImpl(itemAdaptorFactoryMock, versionAdaptorFactoryMock, elementAdaptorFactoryMock, + healthAdaptorFactoryMock); } @@ -115,7 +111,7 @@ public class ZusammenConnectorTest { assertEquals(items.size(), itemList.size()); } - @Test(expected = org.onap.sdc.common.zusammen.services.exceptions.ZusammenException.class) + @Test public void checkListItemFailure() { ItemAdaptor itemAdaptor = mock(ItemAdaptor.class); when(itemAdaptorFactoryMock.createInterface(sessionContext)).thenReturn(itemAdaptor); @@ -123,8 +119,10 @@ public class ZusammenConnectorTest { Response<Collection<Item>> response = new Response<>(items); setResponseErrorReturnCode(response); when(itemAdaptor.list(sessionContext)).thenReturn(response); - zusammenConnector.listItems(sessionContext); - fail("Should never get here"); + assertThrows( + org.onap.sdc.common.zusammen.services.exceptions.ZusammenException.class, + () -> zusammenConnector.listItems(sessionContext) + ); } @Test @@ -140,7 +138,7 @@ public class ZusammenConnectorTest { assertEquals(idStr, retId.getValue()); } - @Test(expected = org.onap.sdc.common.zusammen.services.exceptions.ZusammenException.class) + @Test public void testCreateItemFailure() { ItemAdaptor itemAdaptor = mock(ItemAdaptor.class); when(itemAdaptorFactoryMock.createInterface(sessionContext)).thenReturn(itemAdaptor); @@ -150,11 +148,12 @@ public class ZusammenConnectorTest { setResponseErrorReturnCode(response); Info info = new Info(); when(itemAdaptor.create(sessionContext, info)).thenReturn(response); - zusammenConnector.createItem(sessionContext, info); - + assertThrows( + org.onap.sdc.common.zusammen.services.exceptions.ZusammenException.class, + () -> zusammenConnector.createItem(sessionContext, info) + ); } - @Test public void testDeleteItem() { ItemAdaptor itemAdaptor = mock(ItemAdaptor.class); @@ -284,7 +283,6 @@ public class ZusammenConnectorTest { Response<ItemVersion> response = new Response<>(null); response.setValue(itemVersion); when(itemAdaptor.get(sessionContext, Space.PRIVATE, id, id)).thenReturn(response); - ItemVersion version = zusammenConnector.getVersion(sessionContext, id, id); assertEquals(id.getValue(), itemVersion.getId().getValue()); } diff --git a/zusammen-lib/src/test/java/org/onap/sdc/common/zusammen/services/impl/ZusammenAdaptorImplTest.java b/zusammen-lib/src/test/java/org/onap/sdc/common/zusammen/services/impl/ZusammenAdaptorImplTest.java index 3ac4e26..4fc4b97 100644 --- a/zusammen-lib/src/test/java/org/onap/sdc/common/zusammen/services/impl/ZusammenAdaptorImplTest.java +++ b/zusammen-lib/src/test/java/org/onap/sdc/common/zusammen/services/impl/ZusammenAdaptorImplTest.java @@ -21,6 +21,7 @@ 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.assertThrows; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.verify; @@ -37,12 +38,12 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Optional; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.InjectMocks; -import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.onap.sdc.common.zusammen.persistence.ZusammenConnector; @@ -52,17 +53,16 @@ public class ZusammenAdaptorImplTest { private static final ElementContext ELEMENT_CONTEXT = new ElementContext(); private static final Id ELEMENT_ID = new Id("elementId 0"); private static final List<ElementInfo> ELEMENTS = - Arrays.asList(createElementInfo("elementId1", "element1"), createElementInfo("elementId2", "element2"), - createElementInfo("elementId3", "element3")); + Arrays.asList(createElementInfo("elementId1", "element1"), createElementInfo("elementId2", "element2"), + createElementInfo("elementId3", "element3")); - @Mock - private ZusammenConnector connector; + private final ZusammenConnector connector = Mockito.mock(ZusammenConnector.class); @InjectMocks private ZusammenAdaptorImpl zusammenAdaptor; @Captor private ArgumentCaptor<Element> savedElementArg; - @Before + @BeforeEach public void setUp() { MockitoAnnotations.initMocks(this); } @@ -72,7 +72,7 @@ public class ZusammenAdaptorImplTest { doReturn(ELEMENTS).when(connector).listElements(CONTEXT, ELEMENT_CONTEXT, ELEMENT_ID); Optional<Element> element = - zusammenAdaptor.getElementByName(CONTEXT, ELEMENT_CONTEXT, ELEMENT_ID, "nonExistingName"); + zusammenAdaptor.getElementByName(CONTEXT, ELEMENT_CONTEXT, ELEMENT_ID, "nonExistingName"); assertFalse(element.isPresent()); } @@ -82,7 +82,7 @@ public class ZusammenAdaptorImplTest { doReturn(ELEMENTS).when(connector).listElements(CONTEXT, ELEMENT_CONTEXT, ELEMENT_ID); Optional<ElementInfo> elementInfo = - zusammenAdaptor.getElementInfoByName(CONTEXT, ELEMENT_CONTEXT, ELEMENT_ID, "nonExistingName"); + zusammenAdaptor.getElementInfoByName(CONTEXT, ELEMENT_CONTEXT, ELEMENT_ID, "nonExistingName"); assertFalse(elementInfo.isPresent()); } @@ -104,7 +104,7 @@ public class ZusammenAdaptorImplTest { doReturn(ELEMENTS).when(connector).listElements(CONTEXT, ELEMENT_CONTEXT, ELEMENT_ID); Optional<ElementInfo> elementInfo = - zusammenAdaptor.getElementInfoByName(CONTEXT, ELEMENT_CONTEXT, ELEMENT_ID, "element2"); + zusammenAdaptor.getElementInfoByName(CONTEXT, ELEMENT_CONTEXT, ELEMENT_ID, "element2"); assertTrue(elementInfo.isPresent()); assertEquals(ELEMENTS.get(1), elementInfo.get()); @@ -116,7 +116,7 @@ public class ZusammenAdaptorImplTest { doReturn(ELEMENTS).when(connector).listElements(CONTEXT, ELEMENT_CONTEXT, ELEMENT_ID); List<ZusammenElement> returnedElements = - Arrays.asList(new ZusammenElement(), new ZusammenElement(), new ZusammenElement()); + Arrays.asList(new ZusammenElement(), new ZusammenElement(), new ZusammenElement()); doReturn(returnedElements.get(0)).when(connector).getElement(CONTEXT, ELEMENT_CONTEXT, ELEMENTS.get(0).getId()); doReturn(returnedElements.get(1)).when(connector).getElement(CONTEXT, ELEMENT_CONTEXT, ELEMENTS.get(1).getId()); doReturn(returnedElements.get(2)).when(connector).getElement(CONTEXT, ELEMENT_CONTEXT, ELEMENTS.get(2).getId()); @@ -131,7 +131,7 @@ public class ZusammenAdaptorImplTest { doReturn(ELEMENTS).when(connector).listElements(CONTEXT, ELEMENT_CONTEXT, ELEMENT_ID); Collection<ElementInfo> elements = - zusammenAdaptor.listElementsByName(CONTEXT, ELEMENT_CONTEXT, ELEMENT_ID, "nonExistingName"); + zusammenAdaptor.listElementsByName(CONTEXT, ELEMENT_CONTEXT, ELEMENT_ID, "nonExistingName"); assertTrue(elements.isEmpty()); } @@ -144,14 +144,17 @@ public class ZusammenAdaptorImplTest { doReturn(returnedElements).when(connector).listElements(CONTEXT, ELEMENT_CONTEXT, ELEMENTS.get(1).getId()); Collection<ElementInfo> elements = - zusammenAdaptor.listElementsByName(CONTEXT, ELEMENT_CONTEXT, ELEMENT_ID, "element2"); + zusammenAdaptor.listElementsByName(CONTEXT, ELEMENT_CONTEXT, ELEMENT_ID, "element2"); assertEquals(returnedElements, elements); } - @Test(expected = IllegalArgumentException.class) + @Test public void failWhenSavingElementWithoutIdNameOrAction() { - zusammenAdaptor.saveElement(CONTEXT, ELEMENT_CONTEXT, new ZusammenElement(), "Illegal element save"); + assertThrows( + IllegalArgumentException.class, + () -> zusammenAdaptor.saveElement(CONTEXT, ELEMENT_CONTEXT, new ZusammenElement(), "Illegal element save") + ); } @Test |