Skip to content

Commit

Permalink
[java] Fixing a test since the returned code changed
Browse files Browse the repository at this point in the history
  • Loading branch information
diemol committed Aug 24, 2021
1 parent 8b70122 commit d548975
Showing 1 changed file with 22 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

package com.thoughtworks.selenium;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
Expand Down Expand Up @@ -54,7 +54,7 @@ public void testCanStopTheSeleneseSessionWhenASessionIsInProgress() {
@Override
public String doCommand(String commandName, String[] args) {
assertEquals("testComplete", commandName);
assertNull(args);
assertArrayEquals(args, new String[0]);
return null;
}
};
Expand Down Expand Up @@ -113,6 +113,23 @@ public void testResourcesClosedWhenNoIoes() {
}
}

@Test
public void testGetBooleanArray() {
HttpCommandProcessor processor =
new HttpCommandProcessor("localhost", 4444, "*chrome", "http://www.openqa.org");
processor = spy(processor);

String[] cmdArgs = new String[] {"1", "2"};
String[] cmdResults = new String[] {"true", "false"};
boolean[] boolCmdResults = new boolean[] {true, false};

doReturn(cmdResults).when(processor).getStringArray("command", cmdArgs);

boolean[] methodResults = processor.getBooleanArray("command", cmdArgs);
assertEquals(boolCmdResults[0], methodResults[0]);
assertEquals(boolCmdResults[1], methodResults[1]);
}

/**
* Inner class to help mock out the network and pipe connections to verify that they are closed
* regardless of where IOExceptions occur.
Expand All @@ -121,14 +138,13 @@ public void testResourcesClosedWhenNoIoes() {
*/
private class IOEThrowingHttpCommandProcessor extends HttpCommandProcessor {

private HttpURLConnection closedConn;
private Writer closedWriter;
private Reader closedReader;

protected String responseString = "normal response";
protected boolean throwIoeOnGetConnection = false;
protected boolean throwIoeOnGetInputStream = false;
protected boolean throwIoeOnGetOutputStream = false;
private HttpURLConnection closedConn;
private Writer closedWriter;
private Reader closedReader;

public IOEThrowingHttpCommandProcessor(String serverHost,
int serverPort, String browserStartCommand, String browserURL) {
Expand Down Expand Up @@ -184,21 +200,4 @@ protected boolean verifyClosedResources(boolean connNotNull,

}

@Test
public void testGetBooleanArray() {
HttpCommandProcessor processor =
new HttpCommandProcessor("localhost", 4444, "*chrome", "http://www.openqa.org");
processor = spy(processor);

String[] cmdArgs = new String[] {"1", "2"};
String[] cmdResults = new String[] {"true", "false"};
boolean[] boolCmdResults = new boolean[] {true, false};

doReturn(cmdResults).when(processor).getStringArray("command", cmdArgs);

boolean[] methodResults = processor.getBooleanArray("command", cmdArgs);
assertEquals(boolCmdResults[0], methodResults[0]);
assertEquals(boolCmdResults[1], methodResults[1]);
}

}

0 comments on commit d548975

Please sign in to comment.