Refactorings
This commit is contained in:
parent
0b3c5e865f
commit
324bee7965
36
pom.xml
36
pom.xml
@ -182,42 +182,6 @@
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.tomakehurst</groupId>
|
||||
<artifactId>wiremock</artifactId>
|
||||
<version>2.26.2</version>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-annotations</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-core</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>org.ow2.asm</groupId>
|
||||
<artifactId>asm</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.ow2.asm</groupId>
|
||||
<artifactId>asm</artifactId>
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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());
|
||||
}
|
||||
}
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user