adding some unit tests.

This commit is contained in:
Ikram ulhaq 2017-06-10 23:23:32 -07:00
parent 7d014da700
commit 0ed91f953a
4 changed files with 22 additions and 2 deletions

View file

@ -7,7 +7,7 @@ public class ShutdownRequestedMessage extends Message {
/** /**
* The name used for the action field in {@link Message}. * The name used for the action field in {@link Message}.
*/ */
public static final String ACTION = "shutdownrequested"; public static final String ACTION = "shutdownRequested";
/** /**
* Convenience constructor. * Convenience constructor.

View file

@ -113,6 +113,16 @@ public class MessageWriterTest {
Mockito.verify(this.stream, Mockito.atLeastOnce()).flush(); Mockito.verify(this.stream, Mockito.atLeastOnce()).flush();
} }
@Test
public void writeShutdownRequestedMessageTest() throws IOException, InterruptedException, ExecutionException {
Future<Boolean> future = this.messageWriter.writeShutdownRequestedMessage();
future.get();
Mockito.verify(this.stream, Mockito.atLeastOnce()).write(Mockito.any(byte[].class), Mockito.anyInt(),
Mockito.anyInt());
Mockito.verify(this.stream, Mockito.atLeastOnce()).flush();
}
@Test @Test
public void streamIOExceptionTest() throws IOException, InterruptedException, ExecutionException { public void streamIOExceptionTest() throws IOException, InterruptedException, ExecutionException {
Mockito.doThrow(IOException.class).when(stream).flush(); Mockito.doThrow(IOException.class).when(stream).flush();

View file

@ -114,6 +114,16 @@ public class MultiLangProtocolTest {
assertThat(protocol.shutdown(null, ShutdownReason.ZOMBIE), equalTo(true)); assertThat(protocol.shutdown(null, ShutdownReason.ZOMBIE), equalTo(true));
} }
@Test
public void shutdownRequestedTest() {
when(messageWriter.writeShutdownRequestedMessage()).thenReturn(buildFuture(true));
when(messageReader.getNextMessageFromSTDOUT()).thenReturn(buildFuture(new StatusMessage("shutdownRequested"), Message.class));
Mockito.doReturn(buildFuture(true)).when(messageWriter)
.writeShutdownRequestedMessage();
Mockito.doReturn(buildFuture(new StatusMessage("shutdownRequested"))).when(messageReader).getNextMessageFromSTDOUT();
assertThat(protocol.shutdownRequested(null), equalTo(true));
}
private Answer<Future<Message>> buildMessageAnswers(List<Message> messages) { private Answer<Future<Message>> buildMessageAnswers(List<Message> messages) {
return new Answer<Future<Message>>() { return new Answer<Future<Message>>() {

View file

@ -44,7 +44,7 @@ public class MessageTest {
}); });
} }
})), new ShutdownMessage(ShutdownReason.ZOMBIE), new StatusMessage("processRecords"), })), new ShutdownMessage(ShutdownReason.ZOMBIE), new StatusMessage("processRecords"),
new InitializeMessage(), new ProcessRecordsMessage() }; new InitializeMessage(), new ProcessRecordsMessage(), new ShutdownRequestedMessage() };
for (int i = 0; i < messages.length; i++) { for (int i = 0; i < messages.length; i++) {
Assert.assertTrue("Each message should contain the action field", messages[i].toString().contains("action")); Assert.assertTrue("Each message should contain the action field", messages[i].toString().contains("action"));