-
-
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.
Add tests for Runner and Backend suppliers
- Loading branch information
1 parent
59eef86
commit a92d0f1
Showing
5 changed files
with
151 additions
and
4 deletions.
There are no files selected for viewing
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
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
33 changes: 33 additions & 0 deletions
33
core/src/test/java/cucumber/runtime/BackendSupplierTest.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,33 @@ | ||
package cucumber.runtime; | ||
|
||
import cucumber.runtime.io.MultiLoader; | ||
import cucumber.runtime.io.ResourceLoader; | ||
import cucumber.runtime.io.ResourceLoaderClassFinder; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.util.Collections; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.CoreMatchers.notNullValue; | ||
import static org.junit.Assert.assertThat; | ||
|
||
public class BackendSupplierTest { | ||
|
||
private BackendSupplier backendSupplier; | ||
|
||
@Before | ||
public void before() { | ||
ClassLoader classLoader = getClass().getClassLoader(); | ||
RuntimeOptions runtimeOptions = new RuntimeOptions(Collections.<String>emptyList()); | ||
ResourceLoader resourceLoader = new MultiLoader(classLoader); | ||
ClassFinder classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader); | ||
this.backendSupplier = new BackendSupplier(resourceLoader, classFinder, runtimeOptions); | ||
} | ||
|
||
@Test | ||
public void should_create_a_backend() { | ||
assertThat(backendSupplier.get().iterator().next(), is(notNullValue())); | ||
} | ||
|
||
} |
75 changes: 75 additions & 0 deletions
75
core/src/test/java/cucumber/runtime/RunnerSupplierTest.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,75 @@ | ||
package cucumber.runtime; | ||
|
||
|
||
import cucumber.runner.EventBus; | ||
import cucumber.runner.Runner; | ||
import cucumber.runner.TimeService; | ||
import cucumber.runtime.io.MultiLoader; | ||
import cucumber.runtime.io.ResourceLoader; | ||
import cucumber.runtime.io.ResourceLoaderClassFinder; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.util.Collections; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.CoreMatchers.notNullValue; | ||
import static org.junit.Assert.assertNotSame; | ||
import static org.junit.Assert.assertSame; | ||
import static org.junit.Assert.assertThat; | ||
|
||
|
||
public class RunnerSupplierTest { | ||
|
||
private RunnerSupplier runnerSupplier; | ||
|
||
@Before | ||
public void before() { | ||
ClassLoader classLoader = getClass().getClassLoader(); | ||
RuntimeOptions runtimeOptions = new RuntimeOptions(Collections.<String>emptyList()); | ||
ResourceLoader resourceLoader = new MultiLoader(classLoader); | ||
ClassFinder classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader); | ||
BackendSupplier backendSupplier = new BackendSupplier(resourceLoader, classFinder, runtimeOptions); | ||
EventBus eventBus = new EventBus(TimeService.SYSTEM); | ||
RuntimeGlueSupplier glueSupplier = new RuntimeGlueSupplier(); | ||
runnerSupplier = new RunnerSupplier(runtimeOptions, eventBus, backendSupplier, glueSupplier); | ||
} | ||
|
||
|
||
@Test | ||
public void should_create_a_runner() { | ||
assertThat(runnerSupplier.get(), is(notNullValue())); | ||
} | ||
|
||
@Test | ||
public void should_create_a_runner_per_thread() throws InterruptedException { | ||
final Runner[] runners = new Runner[2]; | ||
Thread thread0 = new Thread(new Runnable() { | ||
@Override | ||
public void run() { | ||
runners[0] = runnerSupplier.get(); | ||
} | ||
}); | ||
|
||
Thread thread1 = new Thread(new Runnable() { | ||
@Override | ||
public void run() { | ||
runners[1] = runnerSupplier.get(); | ||
} | ||
}); | ||
|
||
thread0.start(); | ||
thread1.start(); | ||
|
||
thread0.join(); | ||
thread1.join(); | ||
|
||
assertNotSame(runners[0], runners[1]); | ||
} | ||
|
||
@Test | ||
public void should_return_the_same_runner_on_subsequent_calls() { | ||
assertSame(runnerSupplier.get(), runnerSupplier.get()); | ||
} | ||
|
||
} |
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,36 @@ | ||
package cucumber.runtime; | ||
|
||
import cucumber.runtime.io.ResourceLoader; | ||
import cucumber.runtime.snippets.FunctionNameGenerator; | ||
import gherkin.pickles.PickleStep; | ||
import io.cucumber.stepexpression.TypeRegistry; | ||
|
||
import java.util.List; | ||
|
||
public class StubBackend implements Backend { | ||
|
||
@SuppressWarnings("unused") // reflection to create backend | ||
public StubBackend(ResourceLoader resourceLoader, TypeRegistry typeRegistry) { | ||
|
||
} | ||
|
||
@Override | ||
public void loadGlue(Glue glue, List<String> gluePaths) { | ||
|
||
} | ||
|
||
@Override | ||
public void buildWorld() { | ||
|
||
} | ||
|
||
@Override | ||
public void disposeWorld() { | ||
|
||
} | ||
|
||
@Override | ||
public String getSnippet(PickleStep step, String keyword, FunctionNameGenerator functionNameGenerator) { | ||
return null; | ||
} | ||
} |