Add ExpectedCount#never()

Issue: SPR-15168
This commit is contained in:
Rossen Stoyanchev
2017-01-20 17:11:09 -05:00
parent f07a23e63d
commit bc884023e4
3 changed files with 44 additions and 3 deletions

View File

@@ -137,6 +137,7 @@ public class DefaultRequestExpectation implements RequestExpectation {
}
public boolean isSatisfied() {
// Only validate min count since max count is checked on every request...
return (getMatchedRequestCount() >= getExpectedCount().getMinCount());
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2017 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.
@@ -32,6 +32,7 @@ import org.springframework.util.Assert;
* min(2)
* max(4)
* between(2, 4)
* never()
* </pre>
*
* @author Rossen Stoyanchev
@@ -49,7 +50,7 @@ public class ExpectedCount {
* See static factory methods in this class.
*/
private ExpectedCount(int minCount, int maxCount) {
Assert.isTrue(minCount >= 1, "minCount >= 0 is required");
Assert.isTrue(minCount >= 0, "minCount >= 0 is required");
Assert.isTrue(maxCount >= minCount, "maxCount >= minCount is required");
this.minCount = minCount;
this.maxCount = maxCount;
@@ -116,6 +117,14 @@ public class ExpectedCount {
return new ExpectedCount(1, max);
}
/**
* No calls expected at all, i.e. min=0 and max=0.
* @since 4.3.6
*/
public static ExpectedCount never() {
return new ExpectedCount(0, 0);
}
/**
* Between {@code min} and {@code max} number of times.
*/