Skip to content

Commit

Permalink
ToothPickRule should reset after test method is finished
Browse files Browse the repository at this point in the history
  • Loading branch information
dlemures committed Nov 8, 2016
1 parent 47f6326 commit 9be9aab
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
Expand Up @@ -35,11 +35,7 @@ public void setScopeName(Object scopeName) {

@Override
public Statement apply(Statement base, Description description) {
try {
return base;
} finally {
Toothpick.reset();
}
return new ToothPickStatement(base);
}

public ToothPickTestModule getTestModule() {
Expand Down
@@ -0,0 +1,22 @@
package toothpick.testing;

import org.junit.runners.model.Statement;
import toothpick.Toothpick;

class ToothPickStatement extends Statement {

private final Statement base;

ToothPickStatement(Statement base) {
this.base = base;
}

@Override
public void evaluate() throws Throwable {
try {
base.evaluate();
} finally {
Toothpick.reset();
}
}
}
Expand Up @@ -25,6 +25,11 @@ public void testSetScopeName_shouldFail_whenScopeNameWasAlreadySet() throws Exce
toothPickRule.setScopeName("Bar");
}

@Test(expected = IllegalStateException.class)
public void testSetScopeName_shouldFail_whenScopeNameAlreadyContainsATestModule() throws Exception {
toothPickRuleWithoutScopeName.setScopeName("Foo");
}

@Test
public void testScopeNameSetByConstruction() throws Exception {
assertThat(toothPickRule.getScope(), notNullValue());
Expand All @@ -34,9 +39,9 @@ public void testScopeNameSetByConstruction() throws Exception {

@Test
public void testSetScopeName() throws Exception {
toothPickRuleWithoutScopeName.setScopeName("Foo");
toothPickRuleWithoutScopeName.setScopeName("Bar");
assertThat(toothPickRuleWithoutScopeName.getScope(), notNullValue());
assertThat(toothPickRuleWithoutScopeName.getScope().getName(), is((Object) "Foo"));
assertThat(toothPickRule.getTestModule(), notNullValue());
assertThat(toothPickRuleWithoutScopeName.getScope().getName(), is((Object) "Bar"));
assertThat(toothPickRuleWithoutScopeName.getTestModule(), notNullValue());
}
}

0 comments on commit 9be9aab

Please sign in to comment.