Skip to content

Commit

Permalink
[Weld] Clean up code style
Browse files Browse the repository at this point in the history
  • Loading branch information
mpkorstanje committed Feb 8, 2019
1 parent c5256c3 commit ff4b9c8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 71 deletions.
45 changes: 15 additions & 30 deletions weld/src/main/java/cucumber/runtime/java/weld/WeldFactory.java
Expand Up @@ -5,38 +5,23 @@
import org.jboss.weld.environment.se.Weld;
import org.jboss.weld.environment.se.WeldContainer;

public class WeldFactory
implements ObjectFactory {
public class WeldFactory implements ObjectFactory {

protected static final String LINE_SEPARATOR = System.lineSeparator();
static final String START_EXCEPTION_MESSAGE = "\n" +
"It looks like you're running on a single-core machine, and Weld doesn't like that. See:\n" +
"* http://in.relation.to/Bloggers/Weld200Alpha2Released\n" +
"* https://issues.jboss.org/browse/WELD-1119\n" +
"\n" +
"The workaround is to add enabled=false to a org.jboss.weld.executor.properties file on\n" +
"your CLASSPATH. Beware that this will trigger another Weld bug - startup will now work,\n" +
"but shutdown will fail with a NullPointerException. This exception will be printed and\n" +
"not rethrown. It's the best Cucumber-JVM can do until this bug is fixed in Weld.\n" +
"\n";

protected static final String START_EXCEPTION_MESSAGE = "" +
LINE_SEPARATOR +
"It looks like you're running on a single-core machine, and Weld doesn't like that. See:" +
LINE_SEPARATOR +
"* http://in.relation.to/Bloggers/Weld200Alpha2Released" +
LINE_SEPARATOR +
"* https://issues.jboss.org/browse/WELD-1119" +
LINE_SEPARATOR +
LINE_SEPARATOR +
"The workaround is to add enabled=false to a org.jboss.weld.executor.properties file on" +
LINE_SEPARATOR +
"your CLASSPATH. Beware that this will trigger another Weld bug - startup will now work," +
LINE_SEPARATOR +
"but shutdown will fail with a NullPointerException. This exception will be printed and" +
LINE_SEPARATOR +
"not rethrown. It's the best Cucumber-JVM can do until this bug is fixed in Weld." +
LINE_SEPARATOR +
LINE_SEPARATOR;

protected static final String STOP_EXCEPTION_MESSAGE = "" +
LINE_SEPARATOR +
"If you have set enabled=false in org.jboss.weld.executor.properties and you are seeing" +
LINE_SEPARATOR +
"this message, it means your weld container didn't shut down properly. It's a Weld bug" +
LINE_SEPARATOR +
"and we can't do much to fix it in Cucumber-JVM." +
LINE_SEPARATOR;
static final String STOP_EXCEPTION_MESSAGE = "\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";

private WeldContainer containerInstance;

Expand Down
52 changes: 11 additions & 41 deletions weld/src/test/java/cucumber/runtime/java/weld/WeldFactoryTest.java
@@ -1,11 +1,8 @@
package cucumber.runtime.java.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;
Expand All @@ -27,24 +24,6 @@ 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() {

Expand All @@ -66,7 +45,7 @@ public void shouldGiveUsNewInstancesForEachScenario() {
}

@Test
public void startstopCalledWithoutStart() {
public void startStopCalledWithoutStart() {

final Weld weld = mock(Weld.class);
when(weld.initialize())
Expand All @@ -82,24 +61,15 @@ public void startstopCalledWithoutStart() {

@Test
public void stopCalledWithoutStart() {

final ObjectFactory factory = new WeldFactory();

factory.stop();

final String expectedErrOutput = WeldFactory.LINE_SEPARATOR +
"If you have set enabled=false in org.jboss.weld.executor.properties and you are seeing" +
WeldFactory.LINE_SEPARATOR +
"this message, it means your weld container didn't shut down properly. It's a Weld bug" +
WeldFactory.LINE_SEPARATOR +
"and we can't do much to fix it in Cucumber-JVM." +
WeldFactory.LINE_SEPARATOR +
WeldFactory.LINE_SEPARATOR +
"java.lang.NullPointerException" +
WeldFactory.LINE_SEPARATOR +
"\tat cucumber.runtime.java.weld.WeldFactory.stop";

assertThat(this.errContent.toString(), is(startsWith(expectedErrOutput)));
PrintStream originalErr = System.err;
try {
ByteArrayOutputStream errContent = new ByteArrayOutputStream();
System.setErr(new PrintStream(errContent));
ObjectFactory factory = new WeldFactory();
factory.stop();
assertThat(errContent.toString(), startsWith(WeldFactory.STOP_EXCEPTION_MESSAGE));
} finally {
System.setErr(originalErr);
}
}

}

0 comments on commit ff4b9c8

Please sign in to comment.