-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Use ServiceLoader for ObjectFactory #1463
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
nhojpatrick
wants to merge
5
commits into
cucumber:develop-v5
from
nhojpatrick:develop-v5_1450_service-locator
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
88d3e74
Use ServiceLoader for ObjectFactory
nhojpatrick 07121b3
Clean up my auto bad habbit of auto code formatting
nhojpatrick 0741ed2
Clean up my auto bad habbit of auto code formatting
nhojpatrick f7594f3
new line as like other spi files
nhojpatrick ee089c9
Merge remote-tracking branch 'upstream/master' into develop-v5_1450_s…
nhojpatrick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
339 changes: 339 additions & 0 deletions
339
core/src/test/java/cucumber/runtime/model/CucumberFeatureTest.java
Large diffs are not rendered by default.
Oops, something went wrong.
1 change: 1 addition & 0 deletions
1
guice/src/main/resources/META-INF/services/cucumber.api.java.ObjectFactory
This file contains hidden or 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 @@ | ||
io.cucumber.guice.impl.GuiceFactory |
This file contains hidden or 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 hidden or 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
1 change: 1 addition & 0 deletions
1
needle/src/main/resources/META-INF/services/cucumber.api.java.ObjectFactory
This file contains hidden or 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 @@ | ||
io.cucumber.needle.NeedleFactory |
1 change: 1 addition & 0 deletions
1
openejb/src/main/resources/META-INF/services/cucumber.api.java.ObjectFactory
This file contains hidden or 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 @@ | ||
io.cucumber.openejb.OpenEJBObjectFactory |
1 change: 1 addition & 0 deletions
1
picocontainer/src/main/resources/META-INF/services/cucumber.api.java.ObjectFactory
This file contains hidden or 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 @@ | ||
io.cucumber.picocontainer.PicoFactory |
1 change: 1 addition & 0 deletions
1
spring/src/main/resources/META-INF/services/cucumber.api.java.ObjectFactory
This file contains hidden or 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 @@ | ||
io.cucumber.spring.SpringFactory |
This file contains hidden or 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 hidden or 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
1 change: 1 addition & 0 deletions
1
weld/src/main/resources/META-INF/services/cucumber.api.java.ObjectFactory
This file contains hidden or 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 @@ | ||
io.cucumber.weld.WeldFactory |
This file contains hidden or 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 |
---|---|---|
@@ -1,29 +1,101 @@ | ||
package io.cucumber.weld; | ||
|
||
import cucumber.api.java.ObjectFactory; | ||
import cucumber.api.junit.Cucumber; | ||
import cucumber.runtime.CucumberException; | ||
import org.jboss.weld.environment.se.Weld; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.ExpectedException; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.PrintStream; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.core.Is.is; | ||
import static org.hamcrest.core.IsEqual.equalTo; | ||
import static org.hamcrest.core.StringStartsWith.startsWith; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertNotSame; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class WeldFactoryTest { | ||
|
||
@Rule | ||
public ExpectedException expectedException = ExpectedException.none(); | ||
|
||
private static final PrintStream ORIGINAL_OUT = System.out; | ||
private static final PrintStream ORIGINAL_ERR = System.err; | ||
|
||
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); | ||
private final ByteArrayOutputStream errContent = new ByteArrayOutputStream(); | ||
|
||
@Before | ||
public void setUpStreams() { | ||
System.setOut(new PrintStream(outContent)); | ||
System.setErr(new PrintStream(errContent)); | ||
} | ||
|
||
@After | ||
public void restoreStreams() { | ||
System.setOut(ORIGINAL_OUT); | ||
System.setErr(ORIGINAL_ERR); | ||
} | ||
|
||
@Test | ||
public void shouldGiveUsNewInstancesForEachScenario() { | ||
ObjectFactory factory = new WeldFactory(); | ||
|
||
final ObjectFactory factory = new WeldFactory(); | ||
factory.addClass(BellyStepdefs.class); | ||
|
||
// Scenario 1 | ||
factory.start(); | ||
BellyStepdefs o1 = factory.getInstance(BellyStepdefs.class); | ||
final BellyStepdefs o1 = factory.getInstance(BellyStepdefs.class); | ||
factory.stop(); | ||
|
||
// Scenario 2 | ||
factory.start(); | ||
BellyStepdefs o2 = factory.getInstance(BellyStepdefs.class); | ||
final BellyStepdefs o2 = factory.getInstance(BellyStepdefs.class); | ||
factory.stop(); | ||
|
||
assertNotNull(o1); | ||
assertNotSame(o1, o2); | ||
} | ||
|
||
@Test | ||
public void startstopCalledWithoutStart() { | ||
|
||
final Weld weld = mock(Weld.class); | ||
when(weld.initialize()) | ||
.thenThrow(new IllegalArgumentException()); | ||
|
||
final WeldFactory factory = new WeldFactory(); | ||
|
||
this.expectedException.expect(CucumberException.class); | ||
this.expectedException.expectMessage(is(equalTo(WeldFactory.START_EXCEPTION_MESSAGE))); | ||
|
||
factory.start(weld); | ||
} | ||
|
||
@Test | ||
public void stopCalledWithoutStart() { | ||
|
||
final ObjectFactory factory = new WeldFactory(); | ||
|
||
factory.stop(); | ||
|
||
final String expectedErrOutput = "\n" + | ||
"If you have set enabled=false in org.jboss.weld.executor.properties and you are seeing\n" + | ||
"this message, it means your weld container didn't shut down properly. It's a Weld bug\n" + | ||
"and we can't do much to fix it in Cucumber-JVM.\n" + | ||
"\n" + | ||
"java.lang.NullPointerException\n" + | ||
"\tat cucumber.runtime.java.weld.WeldFactory.stop"; | ||
|
||
assertThat(this.errContent.toString(), is(startsWith(expectedErrOutput))); | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The service loader is not safe for use by multiple concurrent threads. Runners are executed in parallel and each runner will create it's own backends with object factory. You can either make all fields and methods non-static or move this field into the method.