-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from greghaskins/core-refactor
Refactor Spectrum core for simplicity
- Loading branch information
Showing
14 changed files
with
281 additions
and
256 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Sat Mar 28 13:22:51 EDT 2015 | ||
#Sun Jan 31 16:37:51 EST 2016 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.3-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-bin.zip |
28 changes: 0 additions & 28 deletions
28
src/main/java/com/greghaskins/spectrum/BlockExecutable.java
This file was deleted.
Oops, something went wrong.
19 changes: 12 additions & 7 deletions
19
src/main/java/com/greghaskins/spectrum/CompositeBlock.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 |
---|---|---|
@@ -1,26 +1,31 @@ | ||
package com.greghaskins.spectrum; | ||
|
||
import java.util.Arrays; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.greghaskins.spectrum.Spectrum.Block; | ||
|
||
class CompositeBlock implements Block { | ||
|
||
private final Iterable<? extends Block> blocks; | ||
private final List<Block> blocks; | ||
|
||
public CompositeBlock(final Iterable<? extends Block> blocks) { | ||
public CompositeBlock(final List<Block> blocks) { | ||
this.blocks = blocks; | ||
} | ||
|
||
public CompositeBlock(final Block... blocks) { | ||
this(Arrays.asList(blocks)); | ||
} | ||
public CompositeBlock() { | ||
this(new ArrayList<Block>()); | ||
} | ||
|
||
@Override | ||
public void run() throws Throwable { | ||
for (final Block block : blocks) { | ||
for (final Block block : this.blocks) { | ||
block.run(); | ||
} | ||
} | ||
|
||
public void addBlock(final Block block) { | ||
this.blocks.add(block); | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
38 changes: 38 additions & 0 deletions
38
src/main/java/com/greghaskins/spectrum/IdempotentBlock.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,38 @@ | ||
package com.greghaskins.spectrum; | ||
|
||
import com.greghaskins.spectrum.Spectrum.Block; | ||
|
||
class IdempotentBlock implements Block { | ||
|
||
private final Block block; | ||
private Block result; | ||
|
||
|
||
public IdempotentBlock(final Block block) { | ||
this.block = block; | ||
} | ||
|
||
@Override | ||
public void run() throws Throwable { | ||
if (this.result == null) { | ||
this.result = runBlockOnce(this.block); | ||
} | ||
this.result.run(); | ||
} | ||
|
||
private static Block runBlockOnce(final Block block) { | ||
try { | ||
block.run(); | ||
return new EmptyBlock(); | ||
} catch (final Throwable e) { | ||
return new FailingBlock(e); | ||
} | ||
} | ||
|
||
private static class EmptyBlock implements Block { | ||
@Override | ||
public void run() { | ||
} | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
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,43 @@ | ||
package com.greghaskins.spectrum; | ||
|
||
import org.junit.runner.Description; | ||
import org.junit.runner.Runner; | ||
import org.junit.runner.notification.Failure; | ||
import org.junit.runner.notification.RunNotifier; | ||
|
||
import com.greghaskins.spectrum.Spectrum.Block; | ||
|
||
class Spec extends Runner { | ||
|
||
private final Block block; | ||
private final Description description; | ||
|
||
|
||
public Spec(final Description description, final Block block) { | ||
this.description = description; | ||
this.block = block; | ||
} | ||
|
||
@Override | ||
public Description getDescription() { | ||
return this.description; | ||
} | ||
|
||
@Override | ||
public void run(final RunNotifier notifier) { | ||
notifier.fireTestStarted(this.description); | ||
try { | ||
this.block.run(); | ||
} catch (final Throwable e) { | ||
notifier.fireTestFailure(new Failure(this.description, e)); | ||
} | ||
notifier.fireTestFinished(this.description); | ||
} | ||
|
||
|
||
@Override | ||
public int testCount() { | ||
return 1; | ||
} | ||
|
||
} |
Oops, something went wrong.