Skip to content

Commit

Permalink
fluent example
Browse files Browse the repository at this point in the history
  • Loading branch information
musketyr committed May 30, 2024
1 parent b4484b1 commit ce0006b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ static <A, B, C> Where3<A, B, C> forEach(Headers3 headers, Row3<A, B, C> first,
return new Where3<>(headers, first, Arrays.asList(rest));
}

static Headers3 given(String headerA, String headerB, String headerC) {
return new Headers3(headerA, headerB, headerC);
}

static <A, B, C> Where3<A, B, C> forEach(
String headerA,
Iterable<A> valuesA,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.agorapulse.testing.where4j.dsl;

import java.util.ArrayList;
import java.util.List;

public class Headers3 {

private final String a;
Expand All @@ -24,4 +27,10 @@ public String getC() {
return c;
}

public <A, B, C> Where3<A, B, C> are(A a, B b, C c) {
List<Row3<A, B, C>> rows = new ArrayList<>();
rows.add(new Row3<>(a, b, c));
return new Where3<>(this, rows);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public Expectations verify(String template, Verifcation3<A, B, C> verification)
});
}

public Where3<A, B, C> and(A a, B b, C c) {
data.add(new Row3<>(a, b, c));
return this;
}

Stream<DynamicTest> generateTests(String template, Assertion3<A, B, C> verification) {
return data.stream().map(row -> {
String title = template.replace("#" + headers.getA(), String.valueOf(row.getA()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ Expectations basicTestWithThreeVariablesAndExplicitEvaluation() {
);
}

@TestFactory
Expectations basicTestFluent() {
Calculator calculator = new Calculator();

return given("a", "b", "c")
.are(2, 3, 5)
.and(3, 5, 8)
.and(4, 7, 11)
.expect("#a + #b = #c", (a, b, c) -> calculator.add(a, b) == c);
}

@TestFactory
Expectations basicTestWithStreams() {
Calculator calculator = new Calculator();
Expand Down

0 comments on commit ce0006b

Please sign in to comment.