@@ -33,24 +33,36 @@ public static <T extends Throwable> Condition<T> atPosition(
3333
3434 public static <T extends Throwable > Condition <T > atPosition (
3535 Integer startLine , Integer endLine , Integer startColumn , Integer endColumn ) {
36- return new Condition <>(
37- throwable -> {
38- var scriptException = (VtlScriptException ) throwable ;
39- var position = scriptException .getPosition ();
40- return position .startLine ().equals (startLine )
41- && position .endLine ().equals (endLine )
42- && position .startColumn ().equals (startColumn )
43- && position .endColumn ().equals (endColumn );
44- },
45- "at position <%d:%d-%d:%d>" ,
46- startLine ,
47- endLine ,
48- startColumn ,
49- endColumn );
50- }
51-
52- public static <T extends Comparable <T >> Boolean test (T left , T right ) {
53- return true ;
36+ return new Condition <T >() {
37+ @ Override
38+ public boolean matches (T throwable ) {
39+ if (!(throwable instanceof VtlScriptException scriptException )) {
40+ return false ;
41+ }
42+ var position = scriptException .getPosition ();
43+ boolean matches = position .startLine ().equals (startLine )
44+ && position .endLine ().equals (endLine )
45+ && position .startColumn ().equals (startColumn )
46+ && position .endColumn ().equals (endColumn );
47+
48+ // Set description that includes actual position if it doesn't match
49+ if (matches ) {
50+ describedAs ("at position <%d:%d-%d:%d>" , startLine , startColumn , endLine , endColumn );
51+ } else {
52+ describedAs (
53+ "at position <%d:%d-%d:%d> but was <%d:%d-%d:%d>" ,
54+ startLine ,
55+ startColumn ,
56+ endLine ,
57+ endColumn ,
58+ position .startLine (),
59+ position .startColumn (),
60+ position .endLine (),
61+ position .endColumn ());
62+ }
63+ return matches ;
64+ }
65+ };
5466 }
5567
5668 @ BeforeEach
0 commit comments