-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test for GroovyBackend to ensure the ThreadLocal is in place
- Loading branch information
Bradley Hart
committed
Jun 9, 2014
1 parent
6fbe602
commit b2ef05c
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
groovy/src/test/java/cucumber/runtime/groovy/ParallelTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package cucumber.runtime.groovy; | ||
|
||
import cucumber.runtime.io.ResourceLoader; | ||
import groovy.lang.Closure; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
|
||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class ParallelTest { | ||
@Mock | ||
ResourceLoader resourceLoader; | ||
@Mock | ||
Closure closure; | ||
|
||
@Test(expected = RuntimeException.class) | ||
public void exception_throw_when_world_already_set_on_same_thread() { | ||
GroovyBackend groovyBackend = new GroovyBackend(resourceLoader); | ||
groovyBackend.registerWorld(closure); | ||
groovyBackend.registerWorld(closure); | ||
} | ||
|
||
@Test | ||
public void can_have_a_new_backend_on_a_different_thread() { | ||
new GroovyBackend(resourceLoader); | ||
Thread interactWithBackendThread = new Thread(new Runnable(){ | ||
@Override | ||
public void run() { | ||
try { | ||
GroovyBackend.getInstance().registerWorld(closure); | ||
} catch (NullPointerException e){ | ||
// This is what we want as there should be no GroovyBackend on this thread | ||
} | ||
} | ||
}); | ||
runAndWait(interactWithBackendThread); | ||
GroovyBackend.getInstance().registerWorld(closure); | ||
} | ||
|
||
private void runAndWait(Thread interactWithBackendThread) { | ||
interactWithBackendThread.start(); | ||
try { | ||
interactWithBackendThread.join(); | ||
} catch (InterruptedException e) { | ||
throw new RuntimeException("Doh"); | ||
} | ||
} | ||
|
||
} |