@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
/ *
* Copyright 2002 - 2020 the original author or authors .
* Copyright 2002 - 2021 the original author or authors .
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
@ -18,6 +18,8 @@ package org.springframework.test.web.client;
@@ -18,6 +18,8 @@ package org.springframework.test.web.client;
import java.io.IOException ;
import java.net.URI ;
import java.time.Duration ;
import java.time.Instant ;
import java.util.ArrayList ;
import java.util.Collection ;
import java.util.Collections ;
@ -144,25 +146,42 @@ public abstract class AbstractRequestExpectationManager implements RequestExpect
@@ -144,25 +146,42 @@ public abstract class AbstractRequestExpectationManager implements RequestExpect
@Override
public void verify ( ) {
if ( this . expectations . isEmpty ( ) ) {
return ;
}
int count = 0 ;
for ( RequestExpectation expectation : this . expectations ) {
if ( ! expectation . isSatisfied ( ) ) {
count + + ;
}
}
int count = verifyInternal ( ) ;
if ( count > 0 ) {
String message = "Further request(s) expected leaving " + count + " unsatisfied expectation(s).\n" ;
throw new AssertionError ( message + getRequestDetails ( ) ) ;
}
}
@Override
public void verify ( Duration timeout ) {
Instant endTime = Instant . now ( ) . plus ( timeout ) ;
do {
if ( verifyInternal ( ) = = 0 ) {
return ;
}
}
while ( Instant . now ( ) . isBefore ( endTime ) ) ;
verify ( ) ;
}
private int verifyInternal ( ) {
if ( this . expectations . isEmpty ( ) ) {
return 0 ;
}
if ( ! this . requestFailures . isEmpty ( ) ) {
throw new AssertionError ( "Some requests did not execute successfully.\n" +
this . requestFailures . entrySet ( ) . stream ( )
. map ( entry - > "Failed request:\n" + entry . getKey ( ) + "\n" + entry . getValue ( ) )
. collect ( Collectors . joining ( "\n" , "\n" , "" ) ) ) ;
}
int count = 0 ;
for ( RequestExpectation expectation : this . expectations ) {
if ( ! expectation . isSatisfied ( ) ) {
count + + ;
}
}
return count ;
}
/ * *