Skip to content

Commit

Permalink
Include header support
Browse files Browse the repository at this point in the history
  • Loading branch information
deepuvsdeepu committed Sep 17, 2024
1 parent 22fd9d6 commit c4a45fb
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.github.pgullah.jsr.conversion;

import java.util.Collection;

public interface MethodArgsConverter extends TypeConverter<String[], Object[]> {

/**
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/io/github/pgullah/jsr/model/TestSpec.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ public record TestSpec(String path, Class<?> sourceClass, String method,
Optional<Class<? extends MethodArgsConverter>> argsConverter,
Optional<Class<? extends TypeConverter<String, ?>>> 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);
}
Expand Down Expand Up @@ -53,5 +63,4 @@ public TestSpec build() {
Optional.ofNullable(resultConverter));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,22 @@
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
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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions src/test/resources/specs/simple-with-header.spec
Original file line number Diff line number Diff line change
@@ -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]"

0 comments on commit c4a45fb

Please sign in to comment.