Skip to content

Commit

Permalink
Merge pull request #18 from greghaskins/core-refactor
Browse files Browse the repository at this point in the history
Refactor Spectrum core for simplicity
  • Loading branch information
greghaskins committed Feb 1, 2016
2 parents 9ea54dc + 0e88033 commit e5424fe
Show file tree
Hide file tree
Showing 14 changed files with 281 additions and 256 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ repositories {
}

dependencies {
compile group: 'junit', name: 'junit', version: '4.11'
compile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'org.hamcrest', name: 'hamcrest-library', version: '1.3'
testCompile group: 'org.mockito', name: 'mockito-core', version: '1.10.8'
testCompile group: 'org.mockito', name: 'mockito-core', version: '1.10.19'
}

compileJava {
Expand All @@ -37,7 +37,7 @@ jacocoTestReport {
}

task wrapper(type: Wrapper) {
gradleVersion = '2.3'
gradleVersion = '2.10'
}

task sourcesJar(type: Jar, dependsOn: classes) {
Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
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 src/main/java/com/greghaskins/spectrum/BlockExecutable.java

This file was deleted.

19 changes: 12 additions & 7 deletions src/main/java/com/greghaskins/spectrum/CompositeBlock.java
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);
}

}
100 changes: 0 additions & 100 deletions src/main/java/com/greghaskins/spectrum/Context.java

This file was deleted.

9 changes: 0 additions & 9 deletions src/main/java/com/greghaskins/spectrum/EmptyBlock.java

This file was deleted.

7 changes: 0 additions & 7 deletions src/main/java/com/greghaskins/spectrum/Executable.java

This file was deleted.

38 changes: 38 additions & 0 deletions src/main/java/com/greghaskins/spectrum/IdempotentBlock.java
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() {
}
}

}
24 changes: 0 additions & 24 deletions src/main/java/com/greghaskins/spectrum/RunOnceBlock.java

This file was deleted.

43 changes: 43 additions & 0 deletions src/main/java/com/greghaskins/spectrum/Spec.java
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;
}

}
Loading

0 comments on commit e5424fe

Please sign in to comment.