diff --git a/src/main/java/io/github/pgullah/jsr/conversion/MethodArgsConverter.java b/src/main/java/io/github/pgullah/jsr/conversion/MethodArgsConverter.java index f6c5813..6065726 100644 --- a/src/main/java/io/github/pgullah/jsr/conversion/MethodArgsConverter.java +++ b/src/main/java/io/github/pgullah/jsr/conversion/MethodArgsConverter.java @@ -1,7 +1,5 @@ package io.github.pgullah.jsr.conversion; -import java.util.Collection; - public interface MethodArgsConverter extends TypeConverter { /** diff --git a/src/main/java/io/github/pgullah/jsr/model/TestSpec.java b/src/main/java/io/github/pgullah/jsr/model/TestSpec.java index f9e545e..4b85f22 100644 --- a/src/main/java/io/github/pgullah/jsr/model/TestSpec.java +++ b/src/main/java/io/github/pgullah/jsr/model/TestSpec.java @@ -10,6 +10,16 @@ public record TestSpec(String path, Class sourceClass, String method, Optional> argsConverter, Optional>> resultConverter) { + public TestSpec { + if (argsConverter.filter(c -> c == MethodArgsConverter.None.class).isPresent()) { + throw new IllegalArgumentException("Method args converter must not be of None type"); + } + + if (resultConverter.filter(c -> c == TypeConverter.None.class).isPresent()) { + throw new IllegalArgumentException("Result converter must not be of None type"); + } + } + public static Builder testSpecBuilderOf(String path, Class sourceClass, String method) { return new Builder(path, sourceClass, method); } @@ -53,5 +63,4 @@ public TestSpec build() { Optional.ofNullable(resultConverter)); } } - } diff --git a/src/main/java/io/github/pgullah/jsr/provider/TestSpecProvider.java b/src/main/java/io/github/pgullah/jsr/provider/TestSpecProvider.java index ad64c1c..a37abf3 100644 --- a/src/main/java/io/github/pgullah/jsr/provider/TestSpecProvider.java +++ b/src/main/java/io/github/pgullah/jsr/provider/TestSpecProvider.java @@ -27,7 +27,11 @@ public Builder addAnnotated(Class... classes) { } public Builder addSimple(String specPath, Class clazz, String method) { - providerList.add(() -> Stream.of(TestSpec.testSpecBuilderOf(specPath, clazz, method).build())); + return addSimple(TestSpec.testSpecBuilderOf(specPath, clazz, method).build()); + } + + public Builder addSimple(TestSpec testSpec) { + providerList.add(() -> Stream.of(testSpec)); return this; } diff --git a/src/test/java/io/github/pgullah/jsr/examples/TestSpecRunner.java b/src/test/java/io/github/pgullah/jsr/examples/TestSpecRunner.java index 5cedfdc..ac12d7c 100644 --- a/src/test/java/io/github/pgullah/jsr/examples/TestSpecRunner.java +++ b/src/test/java/io/github/pgullah/jsr/examples/TestSpecRunner.java @@ -4,8 +4,11 @@ import io.github.pgullah.jsr.examples.sut.FizzBuzz; import io.github.pgullah.jsr.examples.sut.RegexMatching; import io.github.pgullah.jsr.AbstractGenericTestRunner; +import io.github.pgullah.jsr.model.TestSpec; import io.github.pgullah.jsr.provider.TestSpecProvider; +import static io.github.pgullah.jsr.model.TestSpec.testSpecBuilderOf; + public class TestSpecRunner extends AbstractGenericTestRunner { @Override @@ -13,6 +16,10 @@ public TestSpecProvider testSpecProvider() { return TestSpecProvider.builder() .addAnnotated(ClassMethodTaggedWithSpecAnnotation.class) .addSimple("/specs/simple.spec", FizzBuzz.class, "solution") + .addSimple(testSpecBuilderOf("/specs/simple-with-header.spec", FizzBuzz.class, "solution") + .includeHeader(true) + .build() + ) .addSimple("/specs/multi-test-methods.spec", RegexMatching.class, "solution.*") .build(); } diff --git a/src/test/java/io/github/pgullah/jsr/examples/sut/FizzBuzz.java b/src/test/java/io/github/pgullah/jsr/examples/sut/FizzBuzz.java index 64eadde..2cec16c 100644 --- a/src/test/java/io/github/pgullah/jsr/examples/sut/FizzBuzz.java +++ b/src/test/java/io/github/pgullah/jsr/examples/sut/FizzBuzz.java @@ -15,7 +15,7 @@ public String[] solution(int number) { } fizzOrBuzz += "Buzz"; } - objects[i-1] = fizzOrBuzz.isEmpty() ? ""+i : fizzOrBuzz; + objects[i-1] = fizzOrBuzz.isEmpty() ? String.valueOf(i) : fizzOrBuzz; } return objects; } diff --git a/src/test/resources/specs/simple-with-header.spec b/src/test/resources/specs/simple-with-header.spec new file mode 100644 index 0000000..c1038b1 --- /dev/null +++ b/src/test/resources/specs/simple-with-header.spec @@ -0,0 +1,4 @@ +inputNumber,expectedResult +3, "[1,2,Fizz]" +10,"[1,2,Fizz,4,Buzz,Fizz,7,8,Fizz,Buzz]" +20,"[1,2,Fizz,4,Buzz,Fizz,7,8,Fizz,Buzz,11,Fizz,13,14,Fizz Buzz,16,17,Fizz,19,Buzz]" \ No newline at end of file