Skip to content

Commit

Permalink
Gradle and checkstyle have done their worst.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashley Frieze committed Nov 30, 2016
1 parent 9cce2ab commit 04cfc75
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 24 deletions.
12 changes: 6 additions & 6 deletions src/main/java/com/greghaskins/spectrum/SpecDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
*/
@FunctionalInterface
public interface SpecDefinition {
/**
* The prototype for methods like {@link Spectrum#describe(String, Block)}.
* @param context the name of the item in the spec definition
* @param block the code to execute for that
*/
void define(final String context, final Block block);
/**
* The prototype for methods like {@link Spectrum#describe(String, Block)}.
* @param context the name of the item in the spec definition
* @param block the code to execute for that
*/
void define(final String context, final Block block);
}
8 changes: 4 additions & 4 deletions src/main/java/com/greghaskins/spectrum/Spectrum.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ static void compositeSpec(final String context, final com.greghaskins.spectrum.B
* toString of the item to provide a description
* @param whatToDefine a lambda or function reference to methods like
* {{@link #describe(String, com.greghaskins.spectrum.Block)}}
* @param context the name of the block - this will be postfixed with each parameter's name
* @param parameterizedBlock a consumer of the value from items which is a block of execution
* or definition
* @param <T> the type of item
*/
public static <T> void allOf(final Stream<T> items, final SpecDefinition whatToDefine,
final String context, final Consumer<T> parameterizedBlock) {
items.forEach(item ->
whatToDefine.define(context + " " + item,
() -> parameterizedBlock.accept(item)));
final String context, final Consumer<T> parameterizedBlock) {
items.forEach(item -> whatToDefine.define(context + " " + item,
() -> parameterizedBlock.accept(item)));
}

/**
Expand Down
31 changes: 17 additions & 14 deletions src/test/java/specs/ParameterizedSpecs.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,28 @@
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;

import java.util.stream.Stream;

import com.greghaskins.spectrum.Spectrum;

import org.junit.runner.RunWith;

import java.util.stream.Stream;

/**
* Demonstration of how to use a general purpose parameterized Spec definition.
*/
@RunWith(Spectrum.class)
public class ParameterizedSpecs {{
allOf(Stream.of("a", "b", "c"),
Spectrum::describe, "Suite test", parameter -> {
it("Can process " + parameter, () -> {
assertNotNull(parameter);
});
public class ParameterizedSpecs {
{
allOf(Stream.of("a", "b", "c"),
Spectrum::describe, "Suite test", parameter -> {
it("Can process " + parameter, () -> {
assertNotNull(parameter);
});

allOf(Stream.of("d","e","f"),
Spectrum::it, "Can also process", subItem -> {
assertNotEquals(parameter, subItem);
});
});
}}
allOf(Stream.of("d", "e", "f"),
Spectrum::it, "Can also process", subItem -> {
assertNotEquals(parameter, subItem);
});
});
}
}

0 comments on commit 04cfc75

Please sign in to comment.