Skip to content

Commit

Permalink
Add tests for process runner output listening
Browse files Browse the repository at this point in the history
Add test for JSON array as objects
  • Loading branch information
rchodava committed Nov 5, 2016
1 parent 60930df commit ddaadc1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ public void runProcess_PerformsAsExpected_OnSuccessfulCommandExecution() throws
}
}

@Test
public void runProcess_NotifiesListenerOfOutput() throws IOException {
String[] command = new String[] {"java", "-version"};
StringBuilder output = new StringBuilder();
ProcessOutputListener listener = (message, error) -> output.append(message);
ProcessRunner.ExecutionResult executionResult = ProcessRunner.run(command).outputListener(listener).runAndWait();
assertEquals(executionResult.getExitCode(), 0);
assertTrue(output.toString().startsWith("java version "));
}

private static boolean runningOnWindows() {
return System.getProperty("os.name", "generic").toLowerCase(Locale.ENGLISH).contains("win");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public void singleChunkResponseSent() throws Exception {
}

@Test
public void multipeResponseChunksSent() throws Exception {
public void multipleResponseChunksSent() throws Exception {
ExecutorService service = Executors.newSingleThreadExecutor();
ClientToServerChannelHandler handler = new ClientToServerChannelHandler(service, route, null);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package foundation.stack.datamill.json;

import org.junit.Test;

import java.util.List;

import static org.junit.Assert.assertEquals;

/**
* @author Ravi Chodavarapu (rchodava@gmail.com)
*/
public class JsonArrayTest {
@Test
public void asObjectsTest() throws Exception {
List<JsonObject> objects = new JsonArray("[{\"key\": \"value\"}, {\"key\":\"value\"}]").asJsonObjects();
assertEquals(2, objects.size());
assertEquals("value", objects.get(0).get("key").asString());
}
}

0 comments on commit ddaadc1

Please sign in to comment.