2323import org .testingisdocumenting .webtau .data .render .PrettyPrinter ;
2424import org .testingisdocumenting .webtau .expectation .ExpectedValuesAware ;
2525import org .testingisdocumenting .webtau .expectation .ValueMatcher ;
26- import org .testingisdocumenting .webtau .expectation .equality .CompareToComparator ;
27- import org .testingisdocumenting .webtau .expectation .equality .CompareToResult ;
28- import org .testingisdocumenting .webtau .expectation .equality .ValuePathLazyMessageList ;
29- import org .testingisdocumenting .webtau .expectation .equality .ValuePathMessage ;
26+ import org .testingisdocumenting .webtau .expectation .equality .*;
3027import org .testingisdocumenting .webtau .reporter .TokenizedMessage ;
3128
3229import java .util .*;
3330import java .util .stream .Collectors ;
3431import java .util .stream .Stream ;
32+ import java .util .stream .StreamSupport ;
3533
3634import static org .testingisdocumenting .webtau .WebTauCore .*;
3735import static org .testingisdocumenting .webtau .expectation .TokenizedReportUtils .*;
3836
3937public class ContainExactlyMatcher implements ValueMatcher , ExpectedValuesAware , PrettyPrintable {
40- private final Collection <Object > expectedList ;
38+ private final Iterable <Object > expectedList ;
4139 private List <ValuePathWithValue <Object >> actualCopy ;
4240 private List <ValuePathWithValue <Object >> expectedCopy ;
4341
@@ -48,7 +46,7 @@ public class ContainExactlyMatcher implements ValueMatcher, ExpectedValuesAware,
4846
4947 private CompareToComparator comparator ;
5048
51- public ContainExactlyMatcher (Collection <Object > expected ) {
49+ public ContainExactlyMatcher (Iterable <Object > expected ) {
5250 expectedList = expected ;
5351 }
5452
@@ -59,7 +57,7 @@ public ValueConverter valueConverter() {
5957
6058 @ Override
6159 public Stream <Object > expectedValues () {
62- return expectedList .stream ();
60+ return StreamSupport .stream (expectedList . spliterator (), false );
6361 }
6462
6563 @ Override
@@ -157,6 +155,9 @@ private boolean matches(CompareToComparator comparator, ValuePath actualPath, Ob
157155 actualCopy = ValuePathWithValue .listFromIterable (actualPath , ((Iterable <Object >) actualIterable ));
158156 expectedCopy = ValuePathWithValue .listFromIterable (actualPath , expectedList );
159157
158+ CompareToHandler compareToHandlerPrevious = null ;
159+ CompareToHandler compareToHandlerToUse = null ;
160+
160161 Iterator <ValuePathWithValue <Object >> expectedIt = expectedCopy .iterator ();
161162 while (expectedIt .hasNext ()) {
162163 ValuePathWithValue <Object > expected = expectedIt .next ();
@@ -169,7 +170,20 @@ private boolean matches(CompareToComparator comparator, ValuePath actualPath, Ob
169170 boolean found = false ;
170171 while (actualIt .hasNext ()) {
171172 ValuePathWithValue <Object > actual = actualIt .next ();
172- CompareToResult compareToResult = comparator .compareUsingEqualOnly (actual .getPath (), actual .getValue (), expected .getValue ());
173+
174+ // cache compare to handler to use
175+ if (actual .getValue () != null && expected .getValue () != null ) {
176+ if (compareToHandlerPrevious == null ) {
177+ compareToHandlerPrevious = CompareToComparator .findCompareToEqualHandler (actual .getValue (), expected .getValue ());
178+ }
179+
180+ compareToHandlerToUse = compareToHandlerPrevious ;
181+ }
182+
183+ CompareToResult compareToResult = compareToHandlerToUse != null ?
184+ comparator .compareUsingEqualOnly (compareToHandlerToUse , actual .getPath (), actual .getValue (), expected .getValue ()):
185+ comparator .compareUsingEqualOnly (actual .getPath (), actual .getValue (), expected .getValue ());
186+
173187 if (compareToResult .isEqual ()) {
174188 actualIt .remove ();
175189 expectedIt .remove ();
0 commit comments