Skip to content

Commit

Permalink
Avoid using singletons in tests.
Browse files Browse the repository at this point in the history
I've seen test failures because of the use of statics in the
grid tests, and this contains a test that's flaky on travis.
  • Loading branch information
shs96c committed Oct 4, 2016
1 parent 5cf66fe commit 49cc3ae
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.HttpClient;
import org.junit.BeforeClass;
import org.junit.Before;
import org.junit.Test;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
Expand Down Expand Up @@ -134,11 +134,11 @@ public Integer answer(InvocationOnMock invocation) {
}
}

static RegistrationRequest req = null;
static Map<String, Object> app1 = new HashMap<>();
private RegistrationRequest req = null;
private Map<String, Object> app1 = new HashMap<>();

@BeforeClass
public static void prepare() {
@Before
public void prepare() {
app1.put(CapabilityType.APPLICATION_NAME, "app1");
GridNodeConfiguration config = new GridNodeConfiguration();
config.capabilities.add(new DesiredCapabilities(app1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

import org.junit.BeforeClass;
import org.junit.Before;
import org.junit.Test;
import org.openqa.grid.common.RegistrationRequest;
import org.openqa.grid.internal.DetachedRemoteProxy;
Expand All @@ -43,7 +43,17 @@

public class SessionListenerTest {

static class MyRemoteProxy extends DetachedRemoteProxy implements TestSessionListener {
private RegistrationRequest req = null;
private Map<String, Object> app1 = new HashMap<>();

@Before
public void prepare() {
app1.put(CapabilityType.APPLICATION_NAME, "app1");
req = new RegistrationRequest();
req.getConfiguration().capabilities.add(new DesiredCapabilities(app1));
}

private static class MyRemoteProxy extends DetachedRemoteProxy implements TestSessionListener {

public MyRemoteProxy(RegistrationRequest request, Registry registry) {
super(request, registry);
Expand All @@ -59,16 +69,6 @@ public void beforeSession(TestSession session) {
}
}

static RegistrationRequest req = null;
static Map<String, Object> app1 = new HashMap<>();

@BeforeClass
public static void prepare() {
app1.put(CapabilityType.APPLICATION_NAME, "app1");
req = new RegistrationRequest();
req.getConfiguration().capabilities.add(new DesiredCapabilities(app1));
}

@Test
public void beforeAfterRan() {
Registry registry = Registry.newInstance();
Expand Down Expand Up @@ -278,5 +278,4 @@ public void doubleRelease() throws InterruptedException {
}

}

}

0 comments on commit 49cc3ae

Please sign in to comment.