Skip to content

Commit b1f4a5a

Browse files
committed
use suppress exception to show the original data row location
1 parent b1ab99c commit b1f4a5a

11 files changed

Lines changed: 82 additions & 40 deletions

File tree

libs/expectations/src/main/java/builders/dsl/expectations/dsl/DataTable1.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package builders.dsl.expectations.dsl;
1919

2020
import builders.dsl.expectations.Expectations;
21+
import builders.dsl.expectations.source.SourceLocationInfo;
2122
import org.junit.jupiter.api.DynamicTest;
2223
import org.opentest4j.AssertionFailedError;
2324

@@ -86,17 +87,19 @@ Stream<DynamicTest> generateTests(String template, Assertion1<A> verification) {
8687
return DynamicTest.dynamicTest(
8788
title,
8889
() -> {
89-
boolean verified = false;
90-
Throwable throwable = null;
90+
boolean verified;
9191

9292
try {
9393
verified = verification.verify(row.getA());
9494
} catch (Throwable e) {
95-
throwable = e;
95+
e.addSuppressed(new SourceLocationInfo(row.getLocation()));
96+
throw e;
9697
}
9798

9899
if (!verified) {
99-
throw new AssertionFailedError("Verification failed for " + title + " with values " + headers.getA() + "=" + row.getA() + " " + row.getLocation(), throwable);
100+
AssertionFailedError assertionFailedError = new AssertionFailedError("Verification failed for " + title + " with values " + headers.getA() + "=" + row.getA());
101+
assertionFailedError.addSuppressed(new SourceLocationInfo(row.getLocation()));
102+
throw assertionFailedError;
100103
}
101104
}
102105
);

libs/expectations/src/main/java/builders/dsl/expectations/dsl/DataTable10.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package builders.dsl.expectations.dsl;
1919

2020
import builders.dsl.expectations.Expectations;
21+
import builders.dsl.expectations.source.SourceLocationInfo;
2122
import org.junit.jupiter.api.DynamicTest;
2223
import org.opentest4j.AssertionFailedError;
2324

@@ -115,17 +116,19 @@ Stream<DynamicTest> generateTests(String template, Assertion10<A, B, C, D, E, F,
115116
return DynamicTest.dynamicTest(
116117
finalTitle,
117118
() -> {
118-
boolean verified = false;
119-
Throwable throwable = null;
119+
boolean verified;
120120

121121
try {
122122
verified = verification.verify(row.getA(), row.getB(), row.getC(), row.getD(), row.getE(), row.getF(), row.getG(), row.getH(), row.getI(), row.getJ());
123123
} catch (Throwable e) {
124-
throwable = e;
124+
e.addSuppressed(new SourceLocationInfo(row.getLocation()));
125+
throw e;
125126
}
126127

127128
if (!verified) {
128-
throw new AssertionFailedError("Verification failed for " + finalTitle + " with values " + headers.getA() + "=" + row.getA() + ", " + headers.getB() + "=" + row.getB() + ", " + headers.getC() + "=" + row.getC() + ", " + headers.getD() + "=" + row.getD() + ", " + headers.getE() + "=" + row.getE() + ", " + headers.getF() + "=" + row.getF() + ", " + headers.getG() + "=" + row.getG() + ", " + headers.getH() + "=" + row.getH() + ", " + headers.getI() + "=" + row.getI() + ", " + headers.getJ() + "=" + row.getJ() + " " + row.getLocation(), throwable);
129+
AssertionFailedError assertionFailedError = new AssertionFailedError("Verification failed for " + finalTitle + " with values " + headers.getA() + "=" + row.getA() + ", " + headers.getB() + "=" + row.getB() + ", " + headers.getC() + "=" + row.getC() + ", " + headers.getD() + "=" + row.getD() + ", " + headers.getE() + "=" + row.getE() + ", " + headers.getF() + "=" + row.getF() + ", " + headers.getG() + "=" + row.getG() + ", " + headers.getH() + "=" + row.getH() + ", " + headers.getI() + "=" + row.getI() + ", " + headers.getJ() + "=" + row.getJ());
130+
assertionFailedError.addSuppressed(new SourceLocationInfo(row.getLocation()));
131+
throw assertionFailedError;
129132
}
130133
});
131134
});

libs/expectations/src/main/java/builders/dsl/expectations/dsl/DataTable2.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package builders.dsl.expectations.dsl;
1919

2020
import builders.dsl.expectations.Expectations;
21+
import builders.dsl.expectations.source.SourceLocationInfo;
2122
import org.junit.jupiter.api.DynamicTest;
2223
import org.opentest4j.AssertionFailedError;
2324

@@ -86,17 +87,19 @@ Stream<DynamicTest> generateTests(String template, Assertion2<A, B> verification
8687
return DynamicTest.dynamicTest(
8788
finalTitle,
8889
() -> {
89-
boolean verified = false;
90-
Throwable throwable = null;
90+
boolean verified;
9191

9292
try {
9393
verified = verification.verify(row.getA(), row.getB());
9494
} catch (Throwable e) {
95-
throwable = e;
95+
e.addSuppressed(new SourceLocationInfo(row.getLocation()));
96+
throw e;
9697
}
9798

9899
if (!verified) {
99-
throw new AssertionFailedError("Verification failed for " + finalTitle + " with values " + headers.getA() + "=" + row.getA() + ", " + headers.getB() + "=" + row.getB() + " " + row.getLocation(), throwable);
100+
AssertionFailedError assertionFailedError = new AssertionFailedError("Verification failed for " + finalTitle + " with values " + headers.getA() + "=" + row.getA() + ", " + headers.getB() + "=" + row.getB());
101+
assertionFailedError.addSuppressed(new SourceLocationInfo(row.getLocation()));
102+
throw assertionFailedError;
100103
}
101104
}
102105
);

libs/expectations/src/main/java/builders/dsl/expectations/dsl/DataTable3.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package builders.dsl.expectations.dsl;
1919

2020
import builders.dsl.expectations.Expectations;
21+
import builders.dsl.expectations.source.SourceLocationInfo;
2122
import org.junit.jupiter.api.DynamicTest;
2223
import org.opentest4j.AssertionFailedError;
2324

@@ -90,17 +91,19 @@ Stream<DynamicTest> generateTests(String template, Assertion3<A, B, C> verificat
9091
return DynamicTest.dynamicTest(
9192
finalTitle,
9293
() -> {
93-
boolean verified = false;
94-
Throwable throwable = null;
94+
boolean verified;
9595

9696
try {
9797
verified = verification.verify(row.getA(), row.getB(), row.getC());
9898
} catch (Throwable e) {
99-
throwable = e;
99+
e.addSuppressed(new SourceLocationInfo(row.getLocation()));
100+
throw e;
100101
}
101102

102103
if (!verified) {
103-
throw new AssertionFailedError("Verification failed for " + finalTitle + " with values " + headers.getA() + "=" + row.getA() + ", " + headers.getB() + "=" + row.getB() + ", " + headers.getC() + "=" + row.getC() + " " + row.getLocation(), throwable);
104+
AssertionFailedError assertionFailedError = new AssertionFailedError("Verification failed for " + finalTitle + " with values " + headers.getA() + "=" + row.getA() + ", " + headers.getB() + "=" + row.getB() + ", " + headers.getC() + "=" + row.getC());
105+
assertionFailedError.addSuppressed(new SourceLocationInfo(row.getLocation()));
106+
throw assertionFailedError;
104107
}
105108
}
106109
);

libs/expectations/src/main/java/builders/dsl/expectations/dsl/DataTable4.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package builders.dsl.expectations.dsl;
1919

2020
import builders.dsl.expectations.Expectations;
21+
import builders.dsl.expectations.source.SourceLocationInfo;
2122
import org.junit.jupiter.api.DynamicTest;
2223
import org.opentest4j.AssertionFailedError;
2324

@@ -97,17 +98,19 @@ Stream<DynamicTest> generateTests(String template, Assertion4<A, B, C, D> verifi
9798
return DynamicTest.dynamicTest(
9899
finalTitle,
99100
() -> {
100-
boolean verified = false;
101-
Throwable throwable = null;
101+
boolean verified;
102102

103103
try {
104104
verified = verification.verify(row.getA(), row.getB(), row.getC(), row.getD());
105105
} catch (Throwable e) {
106-
throwable = e;
106+
e.addSuppressed(new SourceLocationInfo(row.getLocation()));
107+
throw e;
107108
}
108109

109110
if (!verified) {
110-
throw new AssertionFailedError("Verification failed for " + finalTitle + " with values " + headers.getA() + "=" + row.getA() + ", " + headers.getB() + "=" + row.getB() + ", " + headers.getC() + "=" + row.getC() + ", " + headers.getD() + "=" + row.getD() + " " + row.getLocation(), throwable);
111+
AssertionFailedError assertionFailedError = new AssertionFailedError("Verification failed for " + finalTitle + " with values " + headers.getA() + "=" + row.getA() + ", " + headers.getB() + "=" + row.getB() + ", " + headers.getC() + "=" + row.getC() + ", " + headers.getD() + "=" + row.getD());
112+
assertionFailedError.addSuppressed(new SourceLocationInfo(row.getLocation()));
113+
throw assertionFailedError;
111114
}
112115
}
113116
);

libs/expectations/src/main/java/builders/dsl/expectations/dsl/DataTable5.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package builders.dsl.expectations.dsl;
1919

2020
import builders.dsl.expectations.Expectations;
21+
import builders.dsl.expectations.source.SourceLocationInfo;
2122
import org.junit.jupiter.api.DynamicTest;
2223
import org.opentest4j.AssertionFailedError;
2324

@@ -100,17 +101,19 @@ Stream<DynamicTest> generateTests(String template, Assertion5<A, B, C, D, E> ver
100101
return DynamicTest.dynamicTest(
101102
finalTitle,
102103
() -> {
103-
boolean verified = false;
104-
Throwable throwable = null;
104+
boolean verified;
105105

106106
try {
107107
verified = verification.verify(row.getA(), row.getB(), row.getC(), row.getD(), row.getE());
108108
} catch (Throwable e) {
109-
throwable = e;
109+
e.addSuppressed(new SourceLocationInfo(row.getLocation()));
110+
throw e;
110111
}
111112

112113
if (!verified) {
113-
throw new AssertionFailedError("Verification failed for " + finalTitle + " with values " + headers.getA() + "=" + row.getA() + ", " + headers.getB() + "=" + row.getB() + ", " + headers.getC() + "=" + row.getC() + ", " + headers.getD() + "=" + row.getD() + ", " + headers.getE() + "=" + row.getE() + " " + row.getLocation(), throwable);
114+
AssertionFailedError assertionFailedError = new AssertionFailedError("Verification failed for " + finalTitle + " with values " + headers.getA() + "=" + row.getA() + ", " + headers.getB() + "=" + row.getB() + ", " + headers.getC() + "=" + row.getC() + ", " + headers.getD() + "=" + row.getD() + ", " + headers.getE() + "=" + row.getE());
115+
assertionFailedError.addSuppressed(new SourceLocationInfo(row.getLocation()));
116+
throw assertionFailedError;
114117
}
115118
});
116119
});

libs/expectations/src/main/java/builders/dsl/expectations/dsl/DataTable6.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package builders.dsl.expectations.dsl;
1919

2020
import builders.dsl.expectations.Expectations;
21+
import builders.dsl.expectations.source.SourceLocationInfo;
2122
import org.junit.jupiter.api.DynamicTest;
2223
import org.opentest4j.AssertionFailedError;
2324

@@ -103,17 +104,19 @@ Stream<DynamicTest> generateTests(String template, Assertion6<A, B, C, D, E, F>
103104
return DynamicTest.dynamicTest(
104105
finalTitle,
105106
() -> {
106-
boolean verified = false;
107-
Throwable throwable = null;
107+
boolean verified;
108108

109109
try {
110110
verified = verification.verify(row.getA(), row.getB(), row.getC(), row.getD(), row.getE(), row.getF());
111111
} catch (Throwable e) {
112-
throwable = e;
112+
e.addSuppressed(new SourceLocationInfo(row.getLocation()));
113+
throw e;
113114
}
114115

115116
if (!verified) {
116-
throw new AssertionFailedError("Verification failed for " + finalTitle + " with values " + headers.getA() + "=" + row.getA() + ", " + headers.getB() + "=" + row.getB() + ", " + headers.getC() + "=" + row.getC() + ", " + headers.getD() + "=" + row.getD() + ", " + headers.getE() + "=" + row.getE() + ", " + headers.getF() + "=" + row.getF() + " " + row.getLocation(), throwable);
117+
AssertionFailedError assertionFailedError = new AssertionFailedError("Verification failed for " + finalTitle + " with values " + headers.getA() + "=" + row.getA() + ", " + headers.getB() + "=" + row.getB() + ", " + headers.getC() + "=" + row.getC() + ", " + headers.getD() + "=" + row.getD() + ", " + headers.getE() + "=" + row.getE() + ", " + headers.getF() + "=" + row.getF());
118+
assertionFailedError.addSuppressed(new SourceLocationInfo(row.getLocation()));
119+
throw assertionFailedError;
117120
}
118121
});
119122
});

libs/expectations/src/main/java/builders/dsl/expectations/dsl/DataTable7.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package builders.dsl.expectations.dsl;
1919

2020
import builders.dsl.expectations.Expectations;
21+
import builders.dsl.expectations.source.SourceLocationInfo;
2122
import org.junit.jupiter.api.DynamicTest;
2223
import org.opentest4j.AssertionFailedError;
2324

@@ -101,17 +102,19 @@ Stream<DynamicTest> generateTests(String template, Assertion7<A, B, C, D, E, F,
101102
return DynamicTest.dynamicTest(
102103
finalTitle,
103104
() -> {
104-
boolean verified = false;
105-
Throwable throwable = null;
105+
boolean verified;
106106

107107
try {
108108
verified = verification.verify(row.getA(), row.getB(), row.getC(), row.getD(), row.getE(), row.getF(), row.getG());
109109
} catch (Throwable e) {
110-
throwable = e;
110+
e.addSuppressed(new SourceLocationInfo(row.getLocation()));
111+
throw e;
111112
}
112113

113114
if (!verified) {
114-
throw new AssertionFailedError("Verification failed for " + finalTitle + " with values " + headers.getA() + "=" + row.getA() + ", " + headers.getB() + "=" + row.getB() + ", " + headers.getC() + "=" + row.getC() + ", " + headers.getD() + "=" + row.getD() + ", " + headers.getE() + "=" + row.getE() + ", " + headers.getF() + "=" + row.getF() + ", " + headers.getG() + "=" + row.getG() + " " + row.getLocation(), throwable);
115+
AssertionFailedError assertionFailedError = new AssertionFailedError("Verification failed for " + finalTitle + " with values " + headers.getA() + "=" + row.getA() + ", " + headers.getB() + "=" + row.getB() + ", " + headers.getC() + "=" + row.getC() + ", " + headers.getD() + "=" + row.getD() + ", " + headers.getE() + "=" + row.getE() + ", " + headers.getF() + "=" + row.getF() + ", " + headers.getG() + "=" + row.getG());
116+
assertionFailedError.addSuppressed(new SourceLocationInfo(row.getLocation()));
117+
throw assertionFailedError;
115118
}
116119
});
117120
});

libs/expectations/src/main/java/builders/dsl/expectations/dsl/DataTable8.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package builders.dsl.expectations.dsl;
1919

2020
import builders.dsl.expectations.Expectations;
21+
import builders.dsl.expectations.source.SourceLocationInfo;
2122
import org.junit.jupiter.api.DynamicTest;
2223
import org.opentest4j.AssertionFailedError;
2324

@@ -104,17 +105,19 @@ Stream<DynamicTest> generateTests(String template, Assertion8<A, B, C, D, E, F,
104105
return DynamicTest.dynamicTest(
105106
finalTitle,
106107
() -> {
107-
boolean verified = false;
108-
Throwable throwable = null;
108+
boolean verified;
109109

110110
try {
111111
verified = verification.verify(row.getA(), row.getB(), row.getC(), row.getD(), row.getE(), row.getF(), row.getG(), row.getH());
112112
} catch (Throwable e) {
113-
throwable = e;
113+
e.addSuppressed(new SourceLocationInfo(row.getLocation()));
114+
throw e;
114115
}
115116

116117
if (!verified) {
117-
throw new AssertionFailedError("Verification failed for " + finalTitle + " with values " + headers.getA() + "=" + row.getA() + ", " + headers.getB() + "=" + row.getB() + ", " + headers.getC() + "=" + row.getC() + ", " + headers.getD() + "=" + row.getD() + ", " + headers.getE() + "=" + row.getE() + ", " + headers.getF() + "=" + row.getF() + ", " + headers.getG() + "=" + row.getG() + ", " + headers.getH() + "=" + row.getH() + " " + row.getLocation(), throwable);
118+
AssertionFailedError assertionFailedError = new AssertionFailedError("Verification failed for " + finalTitle + " with values " + headers.getA() + "=" + row.getA() + ", " + headers.getB() + "=" + row.getB() + ", " + headers.getC() + "=" + row.getC() + ", " + headers.getD() + "=" + row.getD() + ", " + headers.getE() + "=" + row.getE() + ", " + headers.getF() + "=" + row.getF() + ", " + headers.getG() + "=" + row.getG() + ", " + headers.getH() + "=" + row.getH());
119+
assertionFailedError.addSuppressed(new SourceLocationInfo(row.getLocation()));
120+
throw assertionFailedError;
118121
}
119122
});
120123
});

libs/expectations/src/main/java/builders/dsl/expectations/dsl/DataTable9.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package builders.dsl.expectations.dsl;
1919

2020
import builders.dsl.expectations.Expectations;
21+
import builders.dsl.expectations.source.SourceLocationInfo;
2122
import org.junit.jupiter.api.DynamicTest;
2223
import org.opentest4j.AssertionFailedError;
2324

@@ -112,17 +113,19 @@ Stream<DynamicTest> generateTests(String template, Assertion9<A, B, C, D, E, F,
112113
return DynamicTest.dynamicTest(
113114
finalTitle,
114115
() -> {
115-
boolean verified = false;
116-
Throwable throwable = null;
116+
boolean verified;
117117

118118
try {
119119
verified = verification.verify(row.getA(), row.getB(), row.getC(), row.getD(), row.getE(), row.getF(), row.getG(), row.getH(), row.getI());
120120
} catch (Throwable e) {
121-
throwable = e;
121+
e.addSuppressed(new SourceLocationInfo(row.getLocation()));
122+
throw e;
122123
}
123124

124125
if (!verified) {
125-
throw new AssertionFailedError("Verification failed for " + finalTitle + " with values " + headers.getA() + "=" + row.getA() + ", " + headers.getB() + "=" + row.getB() + ", " + headers.getC() + "=" + row.getC() + ", " + headers.getD() + "=" + row.getD() + ", " + headers.getE() + "=" + row.getE() + ", " + headers.getF() + "=" + row.getF() + ", " + headers.getG() + "=" + row.getG() + ", " + headers.getH() + "=" + row.getH() + ", " + headers.getI() + "=" + row.getI() + " " + row.getLocation(), throwable);
126+
AssertionFailedError assertionFailedError = new AssertionFailedError("Verification failed for " + finalTitle + " with values " + headers.getA() + "=" + row.getA() + ", " + headers.getB() + "=" + row.getB() + ", " + headers.getC() + "=" + row.getC() + ", " + headers.getD() + "=" + row.getD() + ", " + headers.getE() + "=" + row.getE() + ", " + headers.getF() + "=" + row.getF() + ", " + headers.getG() + "=" + row.getG() + ", " + headers.getH() + "=" + row.getH() + ", " + headers.getI() + "=" + row.getI());
127+
assertionFailedError.addSuppressed(new SourceLocationInfo(row.getLocation()));
128+
throw assertionFailedError;
126129
}
127130
});
128131
});

0 commit comments

Comments
 (0)