diff --git a/pom.xml b/pom.xml index ac1aa47..e6f76c2 100644 --- a/pom.xml +++ b/pom.xml @@ -182,42 +182,6 @@ - - com.github.tomakehurst - wiremock - 2.26.2 - test - - - org.slf4j - slf4j-api - - - org.apache.commons - commons-lang3 - - - com.fasterxml.jackson.core - jackson-databind - - - com.fasterxml.jackson.core - jackson-annotations - - - com.fasterxml.jackson.core - jackson-core - - - junit - junit - - - org.ow2.asm - asm - - - org.ow2.asm asm diff --git a/src/test/java/jpushover/MockServer.java b/src/test/java/jpushover/MockServer.java deleted file mode 100644 index c1cd26a..0000000 --- a/src/test/java/jpushover/MockServer.java +++ /dev/null @@ -1,29 +0,0 @@ -package jpushover; - -import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; - -import com.github.tomakehurst.wiremock.WireMockServer; - -/** - * - * @author svenkubiak - * - */ -public final class MockServer { - private static WireMockServer wireMockServer; - private static boolean started; - - public MockServer() { - } - - public static void start() { - if (!started) { - System.setProperty("mode", "test"); - wireMockServer = new WireMockServer(options() - .bindAddress("127.0.0.1") - ); - wireMockServer.start(); - started = true; - } - } -} \ No newline at end of file diff --git a/src/test/java/jpushover/apis/GlanceTest.java b/src/test/java/jpushover/apis/GlanceTest.java deleted file mode 100644 index d6f3051..0000000 --- a/src/test/java/jpushover/apis/GlanceTest.java +++ /dev/null @@ -1,78 +0,0 @@ -package jpushover.apis; - -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.post; -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; -import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import java.io.IOException; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import de.svenkubiak.jpushover.JPushover; -import de.svenkubiak.jpushover.http.PushoverResponse; -import jpushover.MockServer; - -/** - * - * @author svenkubiak - * - */ -public class GlanceTest { - private static final String URL = "http://127.0.0.1:8080/1/glances.json"; - private static final String APPLICATION_JSON = "application/json; charset=utf-8"; - private static final String CONTENT_TYPE = "Content-Type"; - - private GlanceTest () { - MockServer.start(); - } - - @Test() - public void testTokenRequired() throws IOException, InterruptedException { - stubFor(post(urlEqualTo(URL)) - .willReturn(aResponse() - .withStatus(400) - .withHeader(CONTENT_TYPE, APPLICATION_JSON))); - - Assertions.assertThrows(NullPointerException.class, () -> { - JPushover.newGlance().push(); - }); - } - - @Test() - public void testUserRequired() throws IOException, InterruptedException { - stubFor(post(urlEqualTo(URL)) - .willReturn(aResponse() - .withStatus(400) - .withHeader(CONTENT_TYPE, APPLICATION_JSON))); - - Assertions.assertThrows(NullPointerException.class, () -> { - JPushover.newGlance().withToken("token").push(); - }); - } - - @Test() - public void testPushWithoutContent() throws IOException, InterruptedException { - stubFor(post(urlEqualTo(URL)) - .willReturn(aResponse() - .withStatus(400) - .withHeader(CONTENT_TYPE, APPLICATION_JSON))); - - PushoverResponse response = JPushover.newGlance().withToken("token").withUser("user").push(); - assertFalse(response.isSuccessful()); - } - - @Test - public void testPush() throws IOException, InterruptedException { - stubFor(post(urlEqualTo(URL)) - .willReturn(aResponse() - .withStatus(200) - .withHeader(CONTENT_TYPE, APPLICATION_JSON))); - - PushoverResponse response = JPushover.newGlance().withToken("foo").withUser("bla").withText("foobar").push(); - assertTrue(response.isSuccessful()); - } -} \ No newline at end of file diff --git a/src/test/java/jpushover/apis/MessageTest.java b/src/test/java/jpushover/apis/MessageTest.java index 9d23b2c..ad6f80a 100644 --- a/src/test/java/jpushover/apis/MessageTest.java +++ b/src/test/java/jpushover/apis/MessageTest.java @@ -1,25 +1,16 @@ package jpushover.apis; -import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; -import static com.github.tomakehurst.wiremock.client.WireMock.post; -import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; -import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; import java.io.IOException; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import de.svenkubiak.jpushover.JPushover; import de.svenkubiak.jpushover.apis.Message; import de.svenkubiak.jpushover.enums.Priority; import de.svenkubiak.jpushover.enums.Sound; -import de.svenkubiak.jpushover.http.PushoverResponse; -import jpushover.MockServer; /** * @@ -27,71 +18,6 @@ import jpushover.MockServer; * */ public class MessageTest { - private static final String URL = "https://api.pushover.net/1/messages.json"; - private static final String APPLICATION_JSON = "application/json; charset=utf-8"; - private static final String CONTENT_TYPE = "Content-Type"; - - private MessageTest () { - MockServer.start(); - } - - @Test() - public void testTokenRequired() throws IOException, InterruptedException { - stubFor(post(urlEqualTo(URL)) - .willReturn(aResponse() - .withStatus(400) - .withHeader(CONTENT_TYPE, APPLICATION_JSON))); - - Assertions.assertThrows(NullPointerException.class, () -> { - JPushover.newMessage().push(); - }); - } - - @Test() - public void testUserRequired() throws IOException, InterruptedException { - stubFor(post(urlEqualTo(URL)) - .willReturn(aResponse() - .withStatus(400) - .withHeader(CONTENT_TYPE, APPLICATION_JSON))); - - Assertions.assertThrows(NullPointerException.class, () -> { - JPushover.newMessage().withToken("token").push(); - }); - } - - @Test() - public void testMessageRequired() throws IOException, InterruptedException { - stubFor(post(urlEqualTo(URL)) - .willReturn(aResponse() - .withStatus(400) - .withHeader(CONTENT_TYPE, APPLICATION_JSON))); - - Assertions.assertThrows(NullPointerException.class, () -> { - JPushover.newMessage().withToken("token").withUser("user").push(); - }); - } - - @Test() - public void testPushWithoutContent() throws IOException, InterruptedException { - stubFor(post(urlEqualTo(URL)) - .willReturn(aResponse() - .withStatus(400) - .withHeader(CONTENT_TYPE, APPLICATION_JSON))); - - PushoverResponse response = JPushover.newMessage().withToken("token").withUser("user").withMessage("").push(); - assertFalse(response.isSuccessful()); - } - - @Test - public void testPush() throws IOException, InterruptedException { - stubFor(post(urlEqualTo(URL)) - .willReturn(aResponse() - .withStatus(200) - .withHeader(CONTENT_TYPE, APPLICATION_JSON))); - - PushoverResponse response = JPushover.newMessage().withToken("foo").withUser("bla").withMessage("foobar").push(); - assertTrue(response.isSuccessful()); - } @Test public void testConstruct() throws IOException, InterruptedException {