Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

GROOVY-5409: Improve error message for shouldFailWithCause

  • Loading branch information...
commit 137815750b59792846e9b260a645b6a450070a89 1 parent 5b5bbfc
@paulk-asert paulk-asert authored
Showing with 34 additions and 6 deletions.
  1. +34 −6 src/test/groovy/mock/interceptor/StubCallSequenceTest.groovy
View
40 src/test/groovy/mock/interceptor/StubCallSequenceTest.groovy
@@ -1,12 +1,28 @@
+/*
+ * Copyright 2003-2012 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package groovy.mock.interceptor
import junit.framework.AssertionFailedError
/**
- Testing Groovy Stub support for multiple calls to the Collaborator with
- demanding one or two methods multiple and and various ranges.
- @author Dierk Koenig
-*/
+ * Testing Groovy Stub support for multiple calls to the Collaborator with
+ * demanding one or two methods multiple and and various ranges.
+ *
+ * @author Dierk Koenig
+ */
class StubCallSequenceTest extends GroovyTestCase {
StubFor stub
@@ -31,6 +47,7 @@ class StubCallSequenceTest extends GroovyTestCase {
shouldFail(AssertionFailedError.class) { caller.collaborateOne() }
}
}
+
void testOneDemandedDefaultRange() {
stub.demand.one(1..1) { 1 }
stub.use {
@@ -38,6 +55,7 @@ class StubCallSequenceTest extends GroovyTestCase {
assertEquals 1, caller.collaborateOne()
}
}
+
void testOneDemandedExactRange() {
stub.demand.one(2..2) { 1 }
stub.use {
@@ -47,6 +65,7 @@ class StubCallSequenceTest extends GroovyTestCase {
shouldFail(AssertionFailedError.class) { caller.collaborateOne() }
}
}
+
void testOneDemandedRealRange() {
stub.demand.one(1..2) { 1 }
stub.use {
@@ -56,6 +75,7 @@ class StubCallSequenceTest extends GroovyTestCase {
shouldFail(AssertionFailedError.class) { caller.collaborateOne() }
}
}
+
void testOneDemandedOptionalRange() {
stub.demand.one(0..2) { 1 }
stub.use {
@@ -65,6 +85,7 @@ class StubCallSequenceTest extends GroovyTestCase {
shouldFail(AssertionFailedError.class) { caller.collaborateOne() }
}
}
+
void testTwoDemandedNoRange() {
stub.demand.one() { 1 }
stub.demand.two() { 2 }
@@ -75,6 +96,7 @@ class StubCallSequenceTest extends GroovyTestCase {
shouldFail(AssertionFailedError.class) { caller.collaborateTwo() }
}
}
+
void testTwoDemandedFirstRangeExploited() {
stub.demand.one(1..2) { 1 }
stub.demand.two() { 2 }
@@ -86,6 +108,7 @@ class StubCallSequenceTest extends GroovyTestCase {
shouldFail(AssertionFailedError.class) { caller.collaborateTwo() }
}
}
+
void testTwoDemandedFirstRangeNotExploited() {
stub.demand.one(1..2) { 1 }
stub.demand.two() { 2 }
@@ -96,6 +119,7 @@ class StubCallSequenceTest extends GroovyTestCase {
shouldFail(AssertionFailedError.class) { caller.collaborateTwo() }
}
}
+
void testTwoDemandedFirstOptionalOmitted() {
stub.demand.one(0..2) { 1 }
stub.demand.two() { 2 }
@@ -105,6 +129,7 @@ class StubCallSequenceTest extends GroovyTestCase {
shouldFail(AssertionFailedError.class) { caller.collaborateTwo() }
}
}
+
void testMixedDemandedMinimumOutOfSequence() {
stub.demand.one(0..1) { 1 }
stub.demand.two() { 2 }
@@ -122,6 +147,7 @@ class StubCallSequenceTest extends GroovyTestCase {
}
stub.expect.verify()
}
+
void testMixedDemandedMaximum() {
stub.demand.one(0..1) { 1 }
stub.demand.two() { 2 }
@@ -143,13 +169,14 @@ class StubCallSequenceTest extends GroovyTestCase {
shouldFail(AssertionFailedError.class) { caller.collaborateOne() }
}
}
+
void testMixedDemandedOutOfSequenceFailsEarly() {
stub.demand.one(0..1) { 1 }
stub.demand.two() { 2 }
stub.demand.one() { 1 }
stub.demand.two(0..2) { 2 }
stub.demand.one() { 1 }
- shouldFail(AssertionFailedError.class) { // fails on verify
+ shouldFail(AssertionError) { // fails on verify
stub.use {
def caller = new Caller()
assertEquals 1, caller.collaborateOne()
@@ -158,6 +185,7 @@ class StubCallSequenceTest extends GroovyTestCase {
}
}
}
+
void testRangeDemandedOutOfSequenceCalls() {
stub.demand.one(0..3) { 1 }
stub.demand.two(0..3) { 2 }
@@ -180,7 +208,6 @@ class StubCallSequenceTest extends GroovyTestCase {
shouldFail(AssertionFailedError.class) { stub.expect.verify() }
}
-
void testRangeDemandedButNotExploitedFailsOnVerify() {
stub.demand.one(2..4) { 1 }
shouldFail(AssertionFailedError.class) { // fails on verify
@@ -191,6 +218,7 @@ class StubCallSequenceTest extends GroovyTestCase {
stub.expect.verify()
}
}
+
void testReversedRangesNotAllowed() {
shouldFail(IllegalArgumentException.class) { stub.demand.one(1..0) { 1 } }
}
Please sign in to comment.
Something went wrong with that request. Please try again.