diff --git a/pom.xml b/pom.xml index c11e283..7f182d4 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ The Apache Software License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0.txt + https://www.apache.org/licenses/LICENSE-2.0.txt repo A business-friendly OSS license @@ -31,27 +31,27 @@ Mark Berner markb@tikalk.com Tikal Knowledge - http://tikalk.com + https://tikalk.com hagzag Haggai Philip Zagury hagzag@tikalk.com Tikal Knowledge - http://tikalk.com + https://tikalk.com evgenyg Evgeny Goldin evgenyg@gmail.com AKQA - http://akqa.com + https://akqa.com cohencil Chen Cohen chenc@tikalk.com - http://tikalk.com + https://tikalk.com @@ -109,7 +109,6 @@ org.jenkins-ci.plugins s3 - 496.v320cdd5a_1f65 true @@ -135,15 +134,9 @@ token-macro true - - net.sf.ezmorph - ezmorph - 1.0.6 - test - org.mockito - mockito-core + mockito-junit-jupiter test diff --git a/src/test/java/com/tikal/hudson/plugins/notification/PhaseTest.java b/src/test/java/com/tikal/hudson/plugins/notification/PhaseTest.java index 04f2b41..2162bf2 100644 --- a/src/test/java/com/tikal/hudson/plugins/notification/PhaseTest.java +++ b/src/test/java/com/tikal/hudson/plugins/notification/PhaseTest.java @@ -2,7 +2,7 @@ import static com.tikal.hudson.plugins.notification.UrlType.PUBLIC; import static com.tikal.hudson.plugins.notification.UrlType.SECRET; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyBoolean; import static org.mockito.Mockito.anyInt; @@ -27,14 +27,14 @@ import java.lang.reflect.Method; import java.util.List; import jenkins.model.Jenkins; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.MockedStatic; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) -public class PhaseTest { +@ExtendWith(MockitoExtension.class) +class PhaseTest { @Mock private Run run; @@ -63,115 +63,115 @@ public class PhaseTest { private Jenkins jenkins; @Test - public void testIsRun() throws ReflectiveOperationException { + void testIsRun() throws ReflectiveOperationException { Endpoint endPoint = new Endpoint(null); Method isRunMethod = Phase.class.getDeclaredMethod("isRun", Endpoint.class, Result.class, Result.class); isRunMethod.setAccessible(true); assertEquals( - "returns true for null endpoint event", + Boolean.TRUE, isRunMethod.invoke(Phase.QUEUED, endPoint, null, null), - Boolean.TRUE); + "returns true for null endpoint event"); endPoint.setEvent("all"); for (Phase phaseValue : Phase.values()) { assertEquals( - "all Event returns true for Phase " + phaseValue.toString(), + Boolean.TRUE, isRunMethod.invoke(phaseValue, endPoint, null, null), - Boolean.TRUE); + "all Event returns true for Phase " + phaseValue.toString()); } endPoint.setEvent("queued"); assertEquals( - "queued Event returns true for Phase Queued", + Boolean.TRUE, isRunMethod.invoke(Phase.QUEUED, endPoint, null, null), - Boolean.TRUE); + "queued Event returns true for Phase Queued"); assertEquals( - "queued Event returns false for Phase Started", + Boolean.FALSE, isRunMethod.invoke(Phase.STARTED, endPoint, null, null), - Boolean.FALSE); + "queued Event returns false for Phase Started"); endPoint.setEvent("started"); assertEquals( - "started Event returns true for Phase Started", + Boolean.TRUE, isRunMethod.invoke(Phase.STARTED, endPoint, null, null), - Boolean.TRUE); + "started Event returns true for Phase Started"); assertEquals( - "started Event returns false for Phase Completed", + Boolean.FALSE, isRunMethod.invoke(Phase.COMPLETED, endPoint, null, null), - Boolean.FALSE); + "started Event returns false for Phase Completed"); endPoint.setEvent("completed"); assertEquals( - "completed Event returns true for Phase Completed", + Boolean.TRUE, isRunMethod.invoke(Phase.COMPLETED, endPoint, null, null), - Boolean.TRUE); + "completed Event returns true for Phase Completed"); assertEquals( - "completed Event returns false for Phase Finalized", + Boolean.FALSE, isRunMethod.invoke(Phase.FINALIZED, endPoint, null, null), - Boolean.FALSE); + "completed Event returns false for Phase Finalized"); endPoint.setEvent("finalized"); assertEquals( - "finalized Event returns true for Phase Finalized", + Boolean.TRUE, isRunMethod.invoke(Phase.FINALIZED, endPoint, null, null), - Boolean.TRUE); + "finalized Event returns true for Phase Finalized"); assertEquals( - "finalized Event returns true for Phase Queued", + Boolean.FALSE, isRunMethod.invoke(Phase.QUEUED, endPoint, null, null), - Boolean.FALSE); + "finalized Event returns true for Phase Queued"); endPoint.setEvent("failed"); assertEquals( - "failed Event returns false for Phase Finalized and no status", + Boolean.FALSE, isRunMethod.invoke(Phase.FINALIZED, endPoint, null, null), - Boolean.FALSE); + "failed Event returns false for Phase Finalized and no status"); assertEquals( - "failed Event returns false for Phase Finalized and success status", + Boolean.FALSE, isRunMethod.invoke(Phase.FINALIZED, endPoint, Result.SUCCESS, null), - Boolean.FALSE); + "failed Event returns false for Phase Finalized and success status"); assertEquals( - "failed Event returns true for Phase Finalized and success failure", + Boolean.TRUE, isRunMethod.invoke(Phase.FINALIZED, endPoint, Result.FAILURE, null), - Boolean.TRUE); + "failed Event returns true for Phase Finalized and success failure"); assertEquals( - "failed Event returns false for Phase not Finalized and success failure", + Boolean.FALSE, isRunMethod.invoke(Phase.COMPLETED, endPoint, Result.FAILURE, null), - Boolean.FALSE); + "failed Event returns false for Phase not Finalized and success failure"); endPoint.setEvent("failedAndFirstSuccess"); assertEquals( - "failedAndFirstSuccess Event returns false for Phase Finalized and no status", + Boolean.FALSE, isRunMethod.invoke(Phase.FINALIZED, endPoint, null, null), - Boolean.FALSE); + "failedAndFirstSuccess Event returns false for Phase Finalized and no status"); assertEquals( - "failedAndFirstSuccess Event returns false for Phase Finalized and no previous status", + Boolean.FALSE, isRunMethod.invoke(Phase.FINALIZED, endPoint, Result.SUCCESS, null), - Boolean.FALSE); + "failedAndFirstSuccess Event returns false for Phase Finalized and no previous status"); assertEquals( - "failedAndFirstSuccess Event returns true for Phase Finalized and no previous status and failed status", + Boolean.TRUE, isRunMethod.invoke(Phase.FINALIZED, endPoint, Result.FAILURE, null), - Boolean.TRUE); + "failedAndFirstSuccess Event returns true for Phase Finalized and no previous status and failed status"); assertEquals( - "failedAndFirstSuccess Event returns true for Phase Finalized and failed status", + Boolean.TRUE, isRunMethod.invoke(Phase.FINALIZED, endPoint, Result.FAILURE, Result.FAILURE), - Boolean.TRUE); + "failedAndFirstSuccess Event returns true for Phase Finalized and failed status"); assertEquals( - "failedAndFirstSuccess Event returns true for Phase Finalized and success status with previous status of failure", + Boolean.TRUE, isRunMethod.invoke(Phase.FINALIZED, endPoint, Result.SUCCESS, Result.FAILURE), - Boolean.TRUE); + "failedAndFirstSuccess Event returns true for Phase Finalized and success status with previous status of failure"); assertEquals( - "failedAndFirstSuccess Event returns false for Phase Finalized and success status with previous status of success", + Boolean.FALSE, isRunMethod.invoke(Phase.FINALIZED, endPoint, Result.SUCCESS, Result.SUCCESS), - Boolean.FALSE); + "failedAndFirstSuccess Event returns false for Phase Finalized and success status with previous status of success"); assertEquals( - "failedAndFirstSuccess Event returns false for Phase not Finalized", + Boolean.FALSE, isRunMethod.invoke(Phase.COMPLETED, endPoint, Result.SUCCESS, Result.FAILURE), - Boolean.FALSE); + "failedAndFirstSuccess Event returns false for Phase not Finalized"); } @Test - public void testRunNoProperty() { + void testRunNoProperty() { when(run.getParent()).thenReturn(job); Phase.STARTED.handle(run, listener, 0L); @@ -181,7 +181,7 @@ public void testRunNoProperty() { } @Test - public void testRunNoPreviousRunUrlNull() { + void testRunNoPreviousRunUrlNull() { when(run.getParent()).thenReturn(job); when(job.getProperty(HudsonNotificationProperty.class)).thenReturn(property); when(property.getEndpoints()).thenReturn(List.of(endpoint)); @@ -194,7 +194,7 @@ public void testRunNoPreviousRunUrlNull() { } @Test - public void testRunNoPreviousRunUrlTypePublicUnresolvedUrl() throws IOException, InterruptedException { + void testRunNoPreviousRunUrlTypePublicUnresolvedUrl() throws IOException, InterruptedException { when(run.getParent()).thenReturn(job); when(job.getProperty(HudsonNotificationProperty.class)).thenReturn(property); when(property.getEndpoints()).thenReturn(List.of(endpoint)); @@ -212,7 +212,7 @@ public void testRunNoPreviousRunUrlTypePublicUnresolvedUrl() throws IOException, } @Test - public void testRunPreviousRunUrlTypePublic() throws IOException, InterruptedException { + void testRunPreviousRunUrlTypePublic() throws IOException, InterruptedException { byte[] data = "data".getBytes(); try (MockedStatic jenkinsMockedStatic = mockStatic(Jenkins.class)) { jenkinsMockedStatic.when(Jenkins::getInstanceOrNull).thenReturn(jenkins); @@ -251,7 +251,7 @@ public void testRunPreviousRunUrlTypePublic() throws IOException, InterruptedExc } @Test - public void testRunPreviousRunUrlTypeSecret() throws IOException, InterruptedException { + void testRunPreviousRunUrlTypeSecret() throws IOException, InterruptedException { byte[] data = "data".getBytes(); try (MockedStatic jenkinsMockedStatic = mockStatic(Jenkins.class); MockedStatic utilsMockedStatic = mockStatic(Utils.class)) { diff --git a/src/test/java/com/tikal/hudson/plugins/notification/ProtocolTest.java b/src/test/java/com/tikal/hudson/plugins/notification/ProtocolTest.java index 71dba4c..001b74a 100644 --- a/src/test/java/com/tikal/hudson/plugins/notification/ProtocolTest.java +++ b/src/test/java/com/tikal/hudson/plugins/notification/ProtocolTest.java @@ -23,6 +23,9 @@ */ package com.tikal.hudson.plugins.notification; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; + import com.google.common.base.MoreObjects; import com.sun.net.httpserver.HttpExchange; import com.sun.net.httpserver.HttpHandler; @@ -40,12 +43,14 @@ import java.util.Objects; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingQueue; -import junit.framework.TestCase; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * @author Kohsuke Kawaguchi */ -public class ProtocolTest extends TestCase { +class ProtocolTest { static class Request { private final String url; @@ -79,10 +84,9 @@ public int hashCode() { @Override public boolean equals(Object obj) { - if (!(obj instanceof Request)) { + if (!(obj instanceof Request other)) { return false; } - Request other = (Request) obj; return Objects.equals(url, other.url) && Objects.equals(method, other.method) && Objects.equals(body, other.body); @@ -191,19 +195,20 @@ public String getUrl(String path) { }; } - @Override - public void setUp() { + @BeforeEach + void setUp() { servers = new LinkedList<>(); } - @Override - public void tearDown() { + @AfterEach + void tearDown() { for (HttpServer server : servers) { server.stop(1); } } - public void testHttpPost() throws Exception { + @Test + void testHttpPost() throws Exception { BlockingQueue requests = new LinkedBlockingQueue<>(); UrlFactory urlFactory = startServer(new RecordingServlet(requests), "/realpath"); @@ -217,7 +222,8 @@ public void testHttpPost() throws Exception { assertTrue(requests.isEmpty()); } - public void testHttpPostWithBasicAuth() throws Exception { + @Test + void testHttpPostWithBasicAuth() throws Exception { BlockingQueue requests = new LinkedBlockingQueue<>(); UrlFactory urlFactory = startSecureServer(new RecordingServlet(requests), "/realpath", "fred:foo"); @@ -232,7 +238,8 @@ public void testHttpPostWithBasicAuth() throws Exception { assertEquals(new Request(uri, "POST", "Hello").getUrl(), theRequest.getUrlWithAuthority()); } - public void testHttpPostWithRedirects() throws Exception { + @Test + void testHttpPostWithRedirects() throws Exception { BlockingQueue requests = new LinkedBlockingQueue<>(); UrlFactory urlFactory = startServer(new RecordingServlet(requests), "/realpath"); diff --git a/src/test/java/com/tikal/hudson/plugins/notification/test/HostnamePortTest.java b/src/test/java/com/tikal/hudson/plugins/notification/test/HostnamePortTest.java index c1ed4f2..0e75168 100644 --- a/src/test/java/com/tikal/hudson/plugins/notification/test/HostnamePortTest.java +++ b/src/test/java/com/tikal/hudson/plugins/notification/test/HostnamePortTest.java @@ -13,22 +13,24 @@ */ package com.tikal.hudson.plugins.notification.test; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; + import com.tikal.hudson.plugins.notification.HostnamePort; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; -public class HostnamePortTest { +class HostnamePortTest { @Test - public void parseUrlTest() { + void parseUrlTest() { HostnamePort hnp = HostnamePort.parseUrl("111"); - Assert.assertNull(hnp); + assertNull(hnp); hnp = HostnamePort.parseUrl(null); - Assert.assertNull(hnp); + assertNull(hnp); hnp = HostnamePort.parseUrl("localhost:123"); - Assert.assertEquals("localhost", hnp.hostname); - Assert.assertEquals(123, hnp.port); + assertEquals("localhost", hnp.hostname); + assertEquals(123, hnp.port); hnp = HostnamePort.parseUrl("localhost:123456"); - Assert.assertEquals(12345, hnp.port); + assertEquals(12345, hnp.port); } }