|
|
2f0e58 |
diff -r d382aea89c3d easymock/src/main/java/org/easymock/EasyMock.java
|
|
|
2f0e58 |
--- a/easymock/src/main/java/org/easymock/EasyMock.java Thu Feb 23 10:32:43 2012 +0100
|
|
|
2f0e58 |
+++ b/easymock/src/main/java/org/easymock/EasyMock.java Thu Feb 23 11:25:46 2012 +0100
|
|
|
2f0e58 |
@@ -1452,81 +1452,200 @@
|
|
|
2f0e58 |
|
|
|
2f0e58 |
/**
|
|
|
2f0e58 |
* Expect any object but captures it for later use.
|
|
|
2f0e58 |
- *
|
|
|
2f0e58 |
- * @param <T> Type of the captured object
|
|
|
2f0e58 |
- * @param captured Where the parameter is captured
|
|
|
2f0e58 |
+ *
|
|
|
2f0e58 |
+ * @param <T>
|
|
|
2f0e58 |
+ * Type of the captured object
|
|
|
2f0e58 |
+ * @param captured
|
|
|
2f0e58 |
+ * Where the parameter is captured
|
|
|
2f0e58 |
* @return null
|
|
|
2f0e58 |
*/
|
|
|
2f0e58 |
- public static <T> T capture(Capture<T> captured) {
|
|
|
2f0e58 |
+ public static <T> T capture(final Capture<T> captured) {
|
|
|
2f0e58 |
reportMatcher(new Captures<T>(captured));
|
|
|
2f0e58 |
return null;
|
|
|
2f0e58 |
}
|
|
|
2f0e58 |
-
|
|
|
2f0e58 |
+
|
|
|
2f0e58 |
+ /**
|
|
|
2f0e58 |
+ * Expect any boolean but captures it for later use.
|
|
|
2f0e58 |
+ *
|
|
|
2f0e58 |
+ * @param captured
|
|
|
2f0e58 |
+ * Where the parameter is captured
|
|
|
2f0e58 |
+ * @return false
|
|
|
2f0e58 |
+ */
|
|
|
2f0e58 |
+ public static boolean captureBoolean(final Capture<Boolean> captured) {
|
|
|
2f0e58 |
+ reportMatcher(new Captures<Boolean>(captured));
|
|
|
2f0e58 |
+ return false;
|
|
|
2f0e58 |
+ }
|
|
|
2f0e58 |
+
|
|
|
2f0e58 |
+// /**
|
|
|
2f0e58 |
+// * Expect any boolean but captures it for later use.
|
|
|
2f0e58 |
+// *
|
|
|
2f0e58 |
+// * @param captured
|
|
|
2f0e58 |
+// * Where the parameter is captured
|
|
|
2f0e58 |
+// * @return 0
|
|
|
2f0e58 |
+// *
|
|
|
2f0e58 |
+// * @deprecated Because of harder erasure enforcement, doesn't compile in
|
|
|
2f0e58 |
+// * Java 7
|
|
|
2f0e58 |
+// */
|
|
|
2f0e58 |
+// @Deprecated
|
|
|
2f0e58 |
+// public static boolean capture(final Capture<Boolean> captured) {
|
|
|
2f0e58 |
+// return captureBoolean(captured);
|
|
|
2f0e58 |
+// }
|
|
|
2f0e58 |
+
|
|
|
2f0e58 |
/**
|
|
|
2f0e58 |
* Expect any int but captures it for later use.
|
|
|
2f0e58 |
- *
|
|
|
2f0e58 |
- * @param captured Where the parameter is captured
|
|
|
2f0e58 |
+ *
|
|
|
2f0e58 |
+ * @param captured
|
|
|
2f0e58 |
+ * Where the parameter is captured
|
|
|
2f0e58 |
* @return 0
|
|
|
2f0e58 |
*/
|
|
|
2f0e58 |
- public static int capture(Capture<Integer> captured) {
|
|
|
2f0e58 |
+ public static int captureInt(final Capture<Integer> captured) {
|
|
|
2f0e58 |
reportMatcher(new Captures<Integer>(captured));
|
|
|
2f0e58 |
return 0;
|
|
|
2f0e58 |
}
|
|
|
2f0e58 |
-
|
|
|
2f0e58 |
+// /**
|
|
|
2f0e58 |
+// * Expect any int but captures it for later use.
|
|
|
2f0e58 |
+// *
|
|
|
2f0e58 |
+// * @param captured
|
|
|
2f0e58 |
+// * Where the parameter is captured
|
|
|
2f0e58 |
+// * @return 0
|
|
|
2f0e58 |
+// *
|
|
|
2f0e58 |
+// * @deprecated Because of harder erasure enforcement, doesn't compile in
|
|
|
2f0e58 |
+// * Java 7
|
|
|
2f0e58 |
+// */
|
|
|
2f0e58 |
+// @Deprecated
|
|
|
2f0e58 |
+// public static int capture(final Capture<Integer> captured) {
|
|
|
2f0e58 |
+// return captureInt(captured);
|
|
|
2f0e58 |
+// }
|
|
|
2f0e58 |
+
|
|
|
2f0e58 |
/**
|
|
|
2f0e58 |
* Expect any long but captures it for later use.
|
|
|
2f0e58 |
- *
|
|
|
2f0e58 |
- * @param captured Where the parameter is captured
|
|
|
2f0e58 |
+ *
|
|
|
2f0e58 |
+ * @param captured
|
|
|
2f0e58 |
+ * Where the parameter is captured
|
|
|
2f0e58 |
* @return 0
|
|
|
2f0e58 |
*/
|
|
|
2f0e58 |
- public static long capture(Capture<Long> captured) {
|
|
|
2f0e58 |
+ public static long captureLong(final Capture<Long> captured) {
|
|
|
2f0e58 |
reportMatcher(new Captures<Long>(captured));
|
|
|
2f0e58 |
return 0;
|
|
|
2f0e58 |
}
|
|
|
2f0e58 |
-
|
|
|
2f0e58 |
+// /**
|
|
|
2f0e58 |
+// * Expect any long but captures it for later use.
|
|
|
2f0e58 |
+// *
|
|
|
2f0e58 |
+// * @param captured
|
|
|
2f0e58 |
+// * Where the parameter is captured
|
|
|
2f0e58 |
+// * @return 0
|
|
|
2f0e58 |
+// *
|
|
|
2f0e58 |
+// * @deprecated Because of harder erasure enforcement, doesn't compile in
|
|
|
2f0e58 |
+// * Java 7
|
|
|
2f0e58 |
+// */
|
|
|
2f0e58 |
+// @Deprecated
|
|
|
2f0e58 |
+// public static long capture(final Capture<Long> captured) {
|
|
|
2f0e58 |
+// return captureLong(captured);
|
|
|
2f0e58 |
+// }
|
|
|
2f0e58 |
+
|
|
|
2f0e58 |
/**
|
|
|
2f0e58 |
* Expect any float but captures it for later use.
|
|
|
2f0e58 |
- *
|
|
|
2f0e58 |
- * @param captured Where the parameter is captured
|
|
|
2f0e58 |
+ *
|
|
|
2f0e58 |
+ * @param captured
|
|
|
2f0e58 |
+ * Where the parameter is captured
|
|
|
2f0e58 |
* @return 0
|
|
|
2f0e58 |
*/
|
|
|
2f0e58 |
- public static float capture(Capture<Float> captured) {
|
|
|
2f0e58 |
+ public static float captureFloat(final Capture<Float> captured) {
|
|
|
2f0e58 |
reportMatcher(new Captures<Float>(captured));
|
|
|
2f0e58 |
return 0;
|
|
|
2f0e58 |
}
|
|
|
2f0e58 |
-
|
|
|
2f0e58 |
+// /**
|
|
|
2f0e58 |
+// * Expect any float but captures it for later use.
|
|
|
2f0e58 |
+// *
|
|
|
2f0e58 |
+// * @param captured
|
|
|
2f0e58 |
+// * Where the parameter is captured
|
|
|
2f0e58 |
+// * @return 0
|
|
|
2f0e58 |
+// *
|
|
|
2f0e58 |
+// * @deprecated Because of harder erasure enforcement, doesn't compile in
|
|
|
2f0e58 |
+// * Java 7
|
|
|
2f0e58 |
+// */
|
|
|
2f0e58 |
+// @Deprecated
|
|
|
2f0e58 |
+// public static float capture(final Capture<Float> captured) {
|
|
|
2f0e58 |
+// return captureFloat(captured);
|
|
|
2f0e58 |
+// }
|
|
|
2f0e58 |
+
|
|
|
2f0e58 |
/**
|
|
|
2f0e58 |
* Expect any double but captures it for later use.
|
|
|
2f0e58 |
- *
|
|
|
2f0e58 |
- * @param captured Where the parameter is captured
|
|
|
2f0e58 |
+ *
|
|
|
2f0e58 |
+ * @param captured
|
|
|
2f0e58 |
+ * Where the parameter is captured
|
|
|
2f0e58 |
* @return 0
|
|
|
2f0e58 |
*/
|
|
|
2f0e58 |
- public static double capture(Capture<Double> captured) {
|
|
|
2f0e58 |
+ public static double captureDouble(final Capture<Double> captured) {
|
|
|
2f0e58 |
reportMatcher(new Captures<Double>(captured));
|
|
|
2f0e58 |
return 0;
|
|
|
2f0e58 |
}
|
|
|
2f0e58 |
+// /**
|
|
|
2f0e58 |
+// * Expect any double but captures it for later use.
|
|
|
2f0e58 |
+// *
|
|
|
2f0e58 |
+// * @param captured
|
|
|
2f0e58 |
+// * Where the parameter is captured
|
|
|
2f0e58 |
+// * @return 0
|
|
|
2f0e58 |
+// *
|
|
|
2f0e58 |
+// * @deprecated Because of harder erasure enforcement, doesn't compile in
|
|
|
2f0e58 |
+// * Java 7
|
|
|
2f0e58 |
+// */
|
|
|
2f0e58 |
+// @Deprecated
|
|
|
2f0e58 |
+// public static double capture(final Capture<Double> captured) {
|
|
|
2f0e58 |
+// return captureDouble(captured);
|
|
|
2f0e58 |
+// }
|
|
|
2f0e58 |
|
|
|
2f0e58 |
/**
|
|
|
2f0e58 |
* Expect any byte but captures it for later use.
|
|
|
2f0e58 |
- *
|
|
|
2f0e58 |
- * @param captured Where the parameter is captured
|
|
|
2f0e58 |
+ *
|
|
|
2f0e58 |
+ * @param captured
|
|
|
2f0e58 |
+ * Where the parameter is captured
|
|
|
2f0e58 |
* @return 0
|
|
|
2f0e58 |
*/
|
|
|
2f0e58 |
- public static byte capture(Capture<Byte> captured) {
|
|
|
2f0e58 |
+ public static byte captureByte(final Capture<Byte> captured) {
|
|
|
2f0e58 |
reportMatcher(new Captures<Byte>(captured));
|
|
|
2f0e58 |
return 0;
|
|
|
2f0e58 |
}
|
|
|
2f0e58 |
-
|
|
|
2f0e58 |
+// /**
|
|
|
2f0e58 |
+// * Expect any byte but captures it for later use.
|
|
|
2f0e58 |
+// *
|
|
|
2f0e58 |
+// * @param captured
|
|
|
2f0e58 |
+// * Where the parameter is captured
|
|
|
2f0e58 |
+// * @return 0
|
|
|
2f0e58 |
+// *
|
|
|
2f0e58 |
+// * @deprecated Because of harder erasure enforcement, doesn't compile in
|
|
|
2f0e58 |
+// * Java 7
|
|
|
2f0e58 |
+// */
|
|
|
2f0e58 |
+// @Deprecated
|
|
|
2f0e58 |
+// public static byte capture(final Capture<Byte> captured) {
|
|
|
2f0e58 |
+// return captureByte(captured);
|
|
|
2f0e58 |
+// }
|
|
|
2f0e58 |
+
|
|
|
2f0e58 |
/**
|
|
|
2f0e58 |
* Expect any char but captures it for later use.
|
|
|
2f0e58 |
- *
|
|
|
2f0e58 |
- * @param captured Where the parameter is captured
|
|
|
2f0e58 |
+ *
|
|
|
2f0e58 |
+ * @param captured
|
|
|
2f0e58 |
+ * Where the parameter is captured
|
|
|
2f0e58 |
* @return 0
|
|
|
2f0e58 |
*/
|
|
|
2f0e58 |
- public static char capture(Capture<Character> captured) {
|
|
|
2f0e58 |
+ public static char captureChar(final Capture<Character> captured) {
|
|
|
2f0e58 |
reportMatcher(new Captures<Character>(captured));
|
|
|
2f0e58 |
return 0;
|
|
|
2f0e58 |
}
|
|
|
2f0e58 |
+// /**
|
|
|
2f0e58 |
+// * Expect any char but captures it for later use.
|
|
|
2f0e58 |
+// *
|
|
|
2f0e58 |
+// * @param captured
|
|
|
2f0e58 |
+// * Where the parameter is captured
|
|
|
2f0e58 |
+// * @return 0
|
|
|
2f0e58 |
+// *
|
|
|
2f0e58 |
+// * @deprecated Because of harder erasure enforcement, doesn't compile in
|
|
|
2f0e58 |
+// * Java 7
|
|
|
2f0e58 |
+// */
|
|
|
2f0e58 |
+// @Deprecated
|
|
|
2f0e58 |
+// public static char capture(final Capture<Character> captured) {
|
|
|
2f0e58 |
+// return captureChar(captured);
|
|
|
2f0e58 |
+// }
|
|
|
2f0e58 |
|
|
|
2f0e58 |
/**
|
|
|
2f0e58 |
* Switches the given mock objects (more exactly: the controls of the mock
|
|
|
2f0e58 |
diff -r d382aea89c3d easymock/src/test/java/org/easymock/tests2/CaptureTest.java
|
|
|
2f0e58 |
--- a/easymock/src/test/java/org/easymock/tests2/CaptureTest.java Thu Feb 23 10:32:43 2012 +0100
|
|
|
2f0e58 |
+++ b/easymock/src/test/java/org/easymock/tests2/CaptureTest.java Thu Feb 23 11:25:46 2012 +0100
|
|
|
2f0e58 |
@@ -1,12 +1,12 @@
|
|
|
2f0e58 |
-/*
|
|
|
2f0e58 |
- * Copyright 2003-2009 OFFIS, Henri Tremblay
|
|
|
2f0e58 |
- *
|
|
|
2f0e58 |
+/**
|
|
|
2f0e58 |
+ * Copyright 2001-2011 the original author or authors.
|
|
|
2f0e58 |
+ *
|
|
|
2f0e58 |
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
2f0e58 |
* you may not use this file except in compliance with the License.
|
|
|
2f0e58 |
* You may obtain a copy of the License at
|
|
|
2f0e58 |
- *
|
|
|
2f0e58 |
+ *
|
|
|
2f0e58 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
2f0e58 |
- *
|
|
|
2f0e58 |
+ *
|
|
|
2f0e58 |
* Unless required by applicable law or agreed to in writing, software
|
|
|
2f0e58 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
2f0e58 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
2f0e58 |
@@ -27,10 +27,13 @@
|
|
|
2f0e58 |
import org.junit.Before;
|
|
|
2f0e58 |
import org.junit.Test;
|
|
|
2f0e58 |
|
|
|
2f0e58 |
+/**
|
|
|
2f0e58 |
+ * @author Henri Tremblay
|
|
|
2f0e58 |
+ */
|
|
|
2f0e58 |
public class CaptureTest {
|
|
|
2f0e58 |
|
|
|
2f0e58 |
public static class A {
|
|
|
2f0e58 |
- public String foo(IMethods methods) {
|
|
|
2f0e58 |
+ public String foo(final IMethods methods) {
|
|
|
2f0e58 |
return methods.oneArg(2);
|
|
|
2f0e58 |
}
|
|
|
2f0e58 |
}
|
|
|
2f0e58 |
@@ -42,16 +45,16 @@
|
|
|
2f0e58 |
@After
|
|
|
2f0e58 |
public void tearDown() throws Exception {
|
|
|
2f0e58 |
}
|
|
|
2f0e58 |
-
|
|
|
2f0e58 |
- private Capture<Integer> testCaptureType(CaptureType type) {
|
|
|
2f0e58 |
- IMethods mock = createMock(IMethods.class);
|
|
|
2f0e58 |
- Capture<Integer> captured = new Capture<Integer>(type);
|
|
|
2f0e58 |
-
|
|
|
2f0e58 |
- expect(mock.oneArg(capture(captured))).andReturn("1");
|
|
|
2f0e58 |
+
|
|
|
2f0e58 |
+ private Capture<Integer> testCaptureType(final CaptureType type) {
|
|
|
2f0e58 |
+ final IMethods mock = createMock(IMethods.class);
|
|
|
2f0e58 |
+ final Capture<Integer> captured = new Capture<Integer>(type);
|
|
|
2f0e58 |
+
|
|
|
2f0e58 |
+ expect(mock.oneArg(captureInt(captured))).andReturn("1");
|
|
|
2f0e58 |
expect(mock.oneArg(anyInt())).andReturn("1");
|
|
|
2f0e58 |
- expect(mock.oneArg(capture(captured))).andReturn("2").times(2);
|
|
|
2f0e58 |
- mock.twoArgumentMethod(capture(captured), eq(5));
|
|
|
2f0e58 |
- mock.twoArgumentMethod(capture(captured), capture(captured));
|
|
|
2f0e58 |
+ expect(mock.oneArg(captureInt(captured))).andReturn("2").times(2);
|
|
|
2f0e58 |
+ mock.twoArgumentMethod(captureInt(captured), eq(5));
|
|
|
2f0e58 |
+ mock.twoArgumentMethod(captureInt(captured), captureInt(captured));
|
|
|
2f0e58 |
|
|
|
2f0e58 |
replay(mock);
|
|
|
2f0e58 |
|
|
|
2f0e58 |
@@ -66,28 +69,28 @@
|
|
|
2f0e58 |
|
|
|
2f0e58 |
return captured;
|
|
|
2f0e58 |
}
|
|
|
2f0e58 |
-
|
|
|
2f0e58 |
+
|
|
|
2f0e58 |
@Test
|
|
|
2f0e58 |
public void testCaptureFirst() {
|
|
|
2f0e58 |
- Capture<Integer> captured = testCaptureType(CaptureType.FIRST);
|
|
|
2f0e58 |
+ final Capture<Integer> captured = testCaptureType(CaptureType.FIRST);
|
|
|
2f0e58 |
assertEquals(0, (int) captured.getValue());
|
|
|
2f0e58 |
}
|
|
|
2f0e58 |
|
|
|
2f0e58 |
@Test
|
|
|
2f0e58 |
public void testCaptureLast() {
|
|
|
2f0e58 |
- Capture<Integer> captured = testCaptureType(CaptureType.LAST);
|
|
|
2f0e58 |
+ final Capture<Integer> captured = testCaptureType(CaptureType.LAST);
|
|
|
2f0e58 |
assertEquals(7, (int) captured.getValue());
|
|
|
2f0e58 |
}
|
|
|
2f0e58 |
|
|
|
2f0e58 |
@Test
|
|
|
2f0e58 |
public void testCaptureAll() {
|
|
|
2f0e58 |
- Capture<Integer> captured = testCaptureType(CaptureType.ALL);
|
|
|
2f0e58 |
+ final Capture<Integer> captured = testCaptureType(CaptureType.ALL);
|
|
|
2f0e58 |
assertEquals(Arrays.asList(0, 2, 3, 4, 6, 7), captured.getValues());
|
|
|
2f0e58 |
}
|
|
|
2f0e58 |
|
|
|
2f0e58 |
@Test
|
|
|
2f0e58 |
public void testCaptureNone() {
|
|
|
2f0e58 |
- Capture<Integer> captured = testCaptureType(CaptureType.NONE);
|
|
|
2f0e58 |
+ final Capture<Integer> captured = testCaptureType(CaptureType.NONE);
|
|
|
2f0e58 |
assertFalse(captured.hasCaptured());
|
|
|
2f0e58 |
}
|
|
|
2f0e58 |
|
|
|
2f0e58 |
@@ -96,11 +99,10 @@
|
|
|
2f0e58 |
|
|
|
2f0e58 |
@Test
|
|
|
2f0e58 |
public void testCaptureRightOne() {
|
|
|
2f0e58 |
- Capture<String> captured = new Capture<String>();
|
|
|
2f0e58 |
- IMethods mock = createMock(IMethods.class);
|
|
|
2f0e58 |
+ final Capture<String> captured = new Capture<String>();
|
|
|
2f0e58 |
+ final IMethods mock = createMock(IMethods.class);
|
|
|
2f0e58 |
|
|
|
2f0e58 |
- expect(mock.oneArg(and(eq("test"), capture(captured)))).andReturn(
|
|
|
2f0e58 |
- "answer1");
|
|
|
2f0e58 |
+ expect(mock.oneArg(and(eq("test"), capture(captured)))).andReturn("answer1");
|
|
|
2f0e58 |
expect(mock.oneArg("a")).andReturn("answer2");
|
|
|
2f0e58 |
|
|
|
2f0e58 |
replay(mock);
|
|
|
2f0e58 |
@@ -114,10 +116,11 @@
|
|
|
2f0e58 |
verify(mock);
|
|
|
2f0e58 |
}
|
|
|
2f0e58 |
|
|
|
2f0e58 |
+ @SuppressWarnings("deprecation")
|
|
|
2f0e58 |
@Test
|
|
|
2f0e58 |
public void testPrimitiveVsObject() {
|
|
|
2f0e58 |
- Capture<Integer> capture = new Capture<Integer>();
|
|
|
2f0e58 |
- IMethods mock = createMock(IMethods.class);
|
|
|
2f0e58 |
+ final Capture<Integer> capture = new Capture<Integer>();
|
|
|
2f0e58 |
+ final IMethods mock = createMock(IMethods.class);
|
|
|
2f0e58 |
|
|
|
2f0e58 |
expect(mock.oneArg(capture(capture))).andReturn("answer");
|
|
|
2f0e58 |
expect(mock.oneArg((Integer) capture(capture))).andReturn("answer");
|
|
|
2f0e58 |
@@ -135,11 +138,10 @@
|
|
|
2f0e58 |
|
|
|
2f0e58 |
@Test
|
|
|
2f0e58 |
public void testAnd() {
|
|
|
2f0e58 |
- Capture<String> captured = new Capture<String>();
|
|
|
2f0e58 |
- IMethods mock = createMock(IMethods.class);
|
|
|
2f0e58 |
+ final Capture<String> captured = new Capture<String>();
|
|
|
2f0e58 |
+ final IMethods mock = createMock(IMethods.class);
|
|
|
2f0e58 |
|
|
|
2f0e58 |
- expect(mock.oneArg(and(capture(captured), eq("test")))).andReturn(
|
|
|
2f0e58 |
- "answer");
|
|
|
2f0e58 |
+ expect(mock.oneArg(and(capture(captured), eq("test")))).andReturn("answer");
|
|
|
2f0e58 |
|
|
|
2f0e58 |
replay(mock);
|
|
|
2f0e58 |
|
|
|
2f0e58 |
@@ -148,17 +150,19 @@
|
|
|
2f0e58 |
|
|
|
2f0e58 |
verify(mock);
|
|
|
2f0e58 |
}
|
|
|
2f0e58 |
-
|
|
|
2f0e58 |
+
|
|
|
2f0e58 |
+ @SuppressWarnings("deprecation")
|
|
|
2f0e58 |
@Test
|
|
|
2f0e58 |
- public void testPrimitive() {
|
|
|
2f0e58 |
- Capture<Integer> captureI = new Capture<Integer>();
|
|
|
2f0e58 |
- Capture<Long> captureL = new Capture<Long>();
|
|
|
2f0e58 |
- Capture<Float> captureF = new Capture<Float>();
|
|
|
2f0e58 |
- Capture<Double> captureD = new Capture<Double>();
|
|
|
2f0e58 |
- Capture<Byte> captureB = new Capture<Byte>();
|
|
|
2f0e58 |
- Capture<Character> captureC = new Capture<Character>();
|
|
|
2f0e58 |
+ public void testPrimitiveDeprecated() {
|
|
|
2f0e58 |
+ final Capture<Integer> captureI = new Capture<Integer>();
|
|
|
2f0e58 |
+ final Capture<Long> captureL = new Capture<Long>();
|
|
|
2f0e58 |
+ final Capture<Float> captureF = new Capture<Float>();
|
|
|
2f0e58 |
+ final Capture<Double> captureD = new Capture<Double>();
|
|
|
2f0e58 |
+ final Capture<Byte> captureB = new Capture<Byte>();
|
|
|
2f0e58 |
+ final Capture<Character> captureC = new Capture<Character>();
|
|
|
2f0e58 |
+ final Capture<Boolean> captureBool = new Capture<Boolean>();
|
|
|
2f0e58 |
|
|
|
2f0e58 |
- IMethods mock = createMock(IMethods.class);
|
|
|
2f0e58 |
+ final IMethods mock = createMock(IMethods.class);
|
|
|
2f0e58 |
|
|
|
2f0e58 |
expect(mock.oneArg(capture(captureI))).andReturn("answerI");
|
|
|
2f0e58 |
expect(mock.oneArg(capture(captureL))).andReturn("answerL");
|
|
|
2f0e58 |
@@ -166,6 +170,7 @@
|
|
|
2f0e58 |
expect(mock.oneArg(capture(captureD))).andReturn("answerD");
|
|
|
2f0e58 |
expect(mock.oneArg(capture(captureB))).andReturn("answerB");
|
|
|
2f0e58 |
expect(mock.oneArg(capture(captureC))).andReturn("answerC");
|
|
|
2f0e58 |
+ expect(mock.oneArg(capture(captureBool))).andReturn("answerZ");
|
|
|
2f0e58 |
|
|
|
2f0e58 |
replay(mock);
|
|
|
2f0e58 |
|
|
|
2f0e58 |
@@ -175,6 +180,7 @@
|
|
|
2f0e58 |
assertEquals("answerD", mock.oneArg(4.0));
|
|
|
2f0e58 |
assertEquals("answerB", mock.oneArg((byte) 5));
|
|
|
2f0e58 |
assertEquals("answerC", mock.oneArg((char) 6));
|
|
|
2f0e58 |
+ assertEquals("answerZ", mock.oneArg(true));
|
|
|
2f0e58 |
|
|
|
2f0e58 |
assertEquals(1, captureI.getValue().intValue());
|
|
|
2f0e58 |
assertEquals(2l, captureL.getValue().longValue());
|
|
|
2f0e58 |
@@ -182,19 +188,60 @@
|
|
|
2f0e58 |
assertEquals(4.0, captureD.getValue().doubleValue(), 0.0);
|
|
|
2f0e58 |
assertEquals((byte) 5, captureB.getValue().byteValue());
|
|
|
2f0e58 |
assertEquals((char) 6, captureC.getValue().charValue());
|
|
|
2f0e58 |
-
|
|
|
2f0e58 |
+ assertEquals(true, captureBool.getValue().booleanValue());
|
|
|
2f0e58 |
+
|
|
|
2f0e58 |
verify(mock);
|
|
|
2f0e58 |
}
|
|
|
2f0e58 |
-
|
|
|
2f0e58 |
+
|
|
|
2f0e58 |
+ @Test
|
|
|
2f0e58 |
+ public void testPrimitive() {
|
|
|
2f0e58 |
+ final Capture<Integer> captureI = new Capture<Integer>();
|
|
|
2f0e58 |
+ final Capture<Long> captureL = new Capture<Long>();
|
|
|
2f0e58 |
+ final Capture<Float> captureF = new Capture<Float>();
|
|
|
2f0e58 |
+ final Capture<Double> captureD = new Capture<Double>();
|
|
|
2f0e58 |
+ final Capture<Byte> captureB = new Capture<Byte>();
|
|
|
2f0e58 |
+ final Capture<Character> captureC = new Capture<Character>();
|
|
|
2f0e58 |
+ final Capture<Boolean> captureBool = new Capture<Boolean>();
|
|
|
2f0e58 |
+
|
|
|
2f0e58 |
+ final IMethods mock = createMock(IMethods.class);
|
|
|
2f0e58 |
+
|
|
|
2f0e58 |
+ expect(mock.oneArg(captureInt(captureI))).andReturn("answerI");
|
|
|
2f0e58 |
+ expect(mock.oneArg(captureLong(captureL))).andReturn("answerL");
|
|
|
2f0e58 |
+ expect(mock.oneArg(captureFloat(captureF))).andReturn("answerF");
|
|
|
2f0e58 |
+ expect(mock.oneArg(captureDouble(captureD))).andReturn("answerD");
|
|
|
2f0e58 |
+ expect(mock.oneArg(captureByte(captureB))).andReturn("answerB");
|
|
|
2f0e58 |
+ expect(mock.oneArg(captureChar(captureC))).andReturn("answerC");
|
|
|
2f0e58 |
+ expect(mock.oneArg(captureBoolean(captureBool))).andReturn("answerZ");
|
|
|
2f0e58 |
+
|
|
|
2f0e58 |
+ replay(mock);
|
|
|
2f0e58 |
+
|
|
|
2f0e58 |
+ assertEquals("answerI", mock.oneArg(1));
|
|
|
2f0e58 |
+ assertEquals("answerL", mock.oneArg(2l));
|
|
|
2f0e58 |
+ assertEquals("answerF", mock.oneArg(3.0f));
|
|
|
2f0e58 |
+ assertEquals("answerD", mock.oneArg(4.0));
|
|
|
2f0e58 |
+ assertEquals("answerB", mock.oneArg((byte) 5));
|
|
|
2f0e58 |
+ assertEquals("answerC", mock.oneArg((char) 6));
|
|
|
2f0e58 |
+ assertEquals("answerZ", mock.oneArg(true));
|
|
|
2f0e58 |
+
|
|
|
2f0e58 |
+ assertEquals(1, captureI.getValue().intValue());
|
|
|
2f0e58 |
+ assertEquals(2l, captureL.getValue().longValue());
|
|
|
2f0e58 |
+ assertEquals(3.0f, captureF.getValue().floatValue(), 0.0);
|
|
|
2f0e58 |
+ assertEquals(4.0, captureD.getValue().doubleValue(), 0.0);
|
|
|
2f0e58 |
+ assertEquals((byte) 5, captureB.getValue().byteValue());
|
|
|
2f0e58 |
+ assertEquals((char) 6, captureC.getValue().charValue());
|
|
|
2f0e58 |
+ assertEquals(true, captureBool.getValue().booleanValue());
|
|
|
2f0e58 |
+
|
|
|
2f0e58 |
+ verify(mock);
|
|
|
2f0e58 |
+ }
|
|
|
2f0e58 |
+
|
|
|
2f0e58 |
@Test
|
|
|
2f0e58 |
public void testCapture() {
|
|
|
2f0e58 |
- Capture<String> capture = new Capture<String>();
|
|
|
2f0e58 |
+ final Capture<String> capture = new Capture<String>();
|
|
|
2f0e58 |
assertFalse(capture.hasCaptured());
|
|
|
2f0e58 |
try {
|
|
|
2f0e58 |
capture.getValue();
|
|
|
2f0e58 |
fail("Should not be allowed");
|
|
|
2f0e58 |
- }
|
|
|
2f0e58 |
- catch(AssertionError e) {
|
|
|
2f0e58 |
+ } catch (final AssertionError e) {
|
|
|
2f0e58 |
assertEquals("Nothing captured yet", e.getMessage());
|
|
|
2f0e58 |
}
|
|
|
2f0e58 |
assertEquals("Nothing captured yet", capture.toString());
|
|
|
2f0e58 |
@@ -207,29 +254,26 @@
|
|
|
2f0e58 |
try {
|
|
|
2f0e58 |
capture.getValue();
|
|
|
2f0e58 |
fail();
|
|
|
2f0e58 |
- }
|
|
|
2f0e58 |
- catch(AssertionError e) {
|
|
|
2f0e58 |
+ } catch (final AssertionError e) {
|
|
|
2f0e58 |
assertEquals("Nothing captured yet", e.getMessage());
|
|
|
2f0e58 |
}
|
|
|
2f0e58 |
-
|
|
|
2f0e58 |
+
|
|
|
2f0e58 |
capture.setValue(null);
|
|
|
2f0e58 |
assertTrue(capture.hasCaptured());
|
|
|
2f0e58 |
assertNull(capture.getValue());
|
|
|
2f0e58 |
assertEquals("null", capture.toString());
|
|
|
2f0e58 |
}
|
|
|
2f0e58 |
-
|
|
|
2f0e58 |
+
|
|
|
2f0e58 |
@Test
|
|
|
2f0e58 |
public void testCaptureMultiple() {
|
|
|
2f0e58 |
- Capture<String> capture = new Capture<String>(CaptureType.ALL);
|
|
|
2f0e58 |
+ final Capture<String> capture = new Capture<String>(CaptureType.ALL);
|
|
|
2f0e58 |
capture.setValue("a");
|
|
|
2f0e58 |
capture.setValue("b");
|
|
|
2f0e58 |
try {
|
|
|
2f0e58 |
capture.getValue();
|
|
|
2f0e58 |
fail();
|
|
|
2f0e58 |
- } catch (AssertionError e) {
|
|
|
2f0e58 |
- assertEquals(
|
|
|
2f0e58 |
- "More than one value captured: " + capture.getValues(), e
|
|
|
2f0e58 |
- .getMessage());
|
|
|
2f0e58 |
+ } catch (final AssertionError e) {
|
|
|
2f0e58 |
+ assertEquals("More than one value captured: " + capture.getValues(), e.getMessage());
|
|
|
2f0e58 |
}
|
|
|
2f0e58 |
assertEquals(Arrays.asList("a", "b"), capture.getValues());
|
|
|
2f0e58 |
}
|
|
|
2f0e58 |
@@ -237,30 +281,26 @@
|
|
|
2f0e58 |
@Test
|
|
|
2f0e58 |
public void testCapture_2617107() {
|
|
|
2f0e58 |
|
|
|
2f0e58 |
- IMethods mock = createMock(IMethods.class);
|
|
|
2f0e58 |
+ final IMethods mock = createMock(IMethods.class);
|
|
|
2f0e58 |
|
|
|
2f0e58 |
- Capture<String> cap1 = new Capture<String>();
|
|
|
2f0e58 |
- Capture<String> cap2 = new Capture<String>();
|
|
|
2f0e58 |
- Capture<String> cap3 = new Capture<String>();
|
|
|
2f0e58 |
- Capture<String> cap4 = new Capture<String>();
|
|
|
2f0e58 |
+ final Capture<String> cap1 = new Capture<String>();
|
|
|
2f0e58 |
+ final Capture<String> cap2 = new Capture<String>();
|
|
|
2f0e58 |
+ final Capture<String> cap3 = new Capture<String>();
|
|
|
2f0e58 |
+ final Capture<String> cap4 = new Capture<String>();
|
|
|
2f0e58 |
|
|
|
2f0e58 |
- mock.simpleMethodWithArgument(and(isA(String.class),
|
|
|
2f0e58 |
- capture(cap1)));
|
|
|
2f0e58 |
- mock.simpleMethodWithArgument(and(isA(String.class),
|
|
|
2f0e58 |
- capture(cap2)));
|
|
|
2f0e58 |
- mock.simpleMethodWithArgument(and(isA(String.class),
|
|
|
2f0e58 |
- capture(cap3)));
|
|
|
2f0e58 |
- mock.simpleMethodWithArgument(and(isA(String.class),
|
|
|
2f0e58 |
- capture(cap4)));
|
|
|
2f0e58 |
+ mock.simpleMethodWithArgument(and(isA(String.class), capture(cap1)));
|
|
|
2f0e58 |
+ mock.simpleMethodWithArgument(and(isA(String.class), capture(cap2)));
|
|
|
2f0e58 |
+ mock.simpleMethodWithArgument(and(isA(String.class), capture(cap3)));
|
|
|
2f0e58 |
+ mock.simpleMethodWithArgument(and(isA(String.class), capture(cap4)));
|
|
|
2f0e58 |
|
|
|
2f0e58 |
replay(mock);
|
|
|
2f0e58 |
|
|
|
2f0e58 |
final String[] s = { "one", "two", "three", "four" };
|
|
|
2f0e58 |
|
|
|
2f0e58 |
- for (int i = 0; i < s.length; i++) {
|
|
|
2f0e58 |
- mock.simpleMethodWithArgument(s[i]);
|
|
|
2f0e58 |
+ for (final String element : s) {
|
|
|
2f0e58 |
+ mock.simpleMethodWithArgument(element);
|
|
|
2f0e58 |
}
|
|
|
2f0e58 |
-
|
|
|
2f0e58 |
+
|
|
|
2f0e58 |
assertEquals("one", cap1.getValue());
|
|
|
2f0e58 |
assertEquals("two", cap2.getValue());
|
|
|
2f0e58 |
assertEquals("three", cap3.getValue());
|
|
|
2f0e58 |
@@ -268,7 +308,7 @@
|
|
|
2f0e58 |
|
|
|
2f0e58 |
verify(mock);
|
|
|
2f0e58 |
}
|
|
|
2f0e58 |
-
|
|
|
2f0e58 |
+
|
|
|
2f0e58 |
@Test
|
|
|
2f0e58 |
public void testCaptureNonStrictControl_2133741() {
|
|
|
2f0e58 |
testCaptureHelper(createMock(IMethods.class));
|
|
|
2f0e58 |
@@ -279,9 +319,9 @@
|
|
|
2f0e58 |
testCaptureHelper(createStrictMock(IMethods.class));
|
|
|
2f0e58 |
}
|
|
|
2f0e58 |
|
|
|
2f0e58 |
- protected void testCaptureHelper(IMethods mock) {
|
|
|
2f0e58 |
- Capture<String> capture1 = new Capture<String>();
|
|
|
2f0e58 |
- Capture<String> capture2 = new Capture<String>();
|
|
|
2f0e58 |
+ protected void testCaptureHelper(final IMethods mock) {
|
|
|
2f0e58 |
+ final Capture<String> capture1 = new Capture<String>();
|
|
|
2f0e58 |
+ final Capture<String> capture2 = new Capture<String>();
|
|
|
2f0e58 |
|
|
|
2f0e58 |
mock.simpleMethodWithArgument(capture(capture1));
|
|
|
2f0e58 |
mock.simpleMethodWithArgument(capture(capture2));
|
|
|
2f0e58 |
@@ -294,25 +334,25 @@
|
|
|
2f0e58 |
assertTrue(capture1.hasCaptured());
|
|
|
2f0e58 |
assertTrue(capture2.hasCaptured());
|
|
|
2f0e58 |
assertFalse(capture1.getValue() == capture2.getValue());
|
|
|
2f0e58 |
- }
|
|
|
2f0e58 |
-
|
|
|
2f0e58 |
+ }
|
|
|
2f0e58 |
+
|
|
|
2f0e58 |
@Test
|
|
|
2f0e58 |
public void testCapture1_2446744() {
|
|
|
2f0e58 |
- Capture<String> capture1 = new Capture<String>();
|
|
|
2f0e58 |
- Capture<String> capture2 = new Capture<String>();
|
|
|
2f0e58 |
- Capture<String> capture3 = new Capture<String>();
|
|
|
2f0e58 |
- IMethods mock = createMock(IMethods.class);
|
|
|
2f0e58 |
+ final Capture<String> capture1 = new Capture<String>();
|
|
|
2f0e58 |
+ final Capture<String> capture2 = new Capture<String>();
|
|
|
2f0e58 |
+ final Capture<String> capture3 = new Capture<String>();
|
|
|
2f0e58 |
+ final IMethods mock = createMock(IMethods.class);
|
|
|
2f0e58 |
expect(mock.oneArg(capture(capture1))).andReturn("1").once();
|
|
|
2f0e58 |
expect(mock.oneArg(capture(capture2))).andReturn("2").once();
|
|
|
2f0e58 |
expect(mock.oneArg(capture(capture3))).andReturn("3").once();
|
|
|
2f0e58 |
-
|
|
|
2f0e58 |
+
|
|
|
2f0e58 |
replay(mock);
|
|
|
2f0e58 |
-
|
|
|
2f0e58 |
+
|
|
|
2f0e58 |
for (int i = 0; i < 3; i++) {
|
|
|
2f0e58 |
- String string = "Run" + (i + 1);
|
|
|
2f0e58 |
+ final String string = "Run" + (i + 1);
|
|
|
2f0e58 |
mock.oneArg(string);
|
|
|
2f0e58 |
}
|
|
|
2f0e58 |
-
|
|
|
2f0e58 |
+
|
|
|
2f0e58 |
assertEquals("Run3", capture3.getValue());
|
|
|
2f0e58 |
assertEquals("Run2", capture2.getValue());
|
|
|
2f0e58 |
assertEquals("Run1", capture1.getValue());
|
|
|
2f0e58 |
@@ -320,16 +360,16 @@
|
|
|
2f0e58 |
|
|
|
2f0e58 |
@Test
|
|
|
2f0e58 |
public void testCapture2_2446744() {
|
|
|
2f0e58 |
- Capture<String> capture = new Capture<String>(CaptureType.ALL);
|
|
|
2f0e58 |
- IMethods mock = createMock(IMethods.class);
|
|
|
2f0e58 |
+ final Capture<String> capture = new Capture<String>(CaptureType.ALL);
|
|
|
2f0e58 |
+ final IMethods mock = createMock(IMethods.class);
|
|
|
2f0e58 |
expect(mock.oneArg(capture(capture))).andReturn("1").once();
|
|
|
2f0e58 |
expect(mock.oneArg(capture(capture))).andReturn("2").once();
|
|
|
2f0e58 |
expect(mock.oneArg(capture(capture))).andReturn("3").once();
|
|
|
2f0e58 |
-
|
|
|
2f0e58 |
+
|
|
|
2f0e58 |
replay(mock);
|
|
|
2f0e58 |
-
|
|
|
2f0e58 |
+
|
|
|
2f0e58 |
for (int i = 0; i < 3; i++) {
|
|
|
2f0e58 |
- String string = "Run" + (i + 1);
|
|
|
2f0e58 |
+ final String string = "Run" + (i + 1);
|
|
|
2f0e58 |
mock.oneArg(string);
|
|
|
2f0e58 |
}
|
|
|
2f0e58 |
|
|
|
2f0e58 |
@@ -338,8 +378,8 @@
|
|
|
2f0e58 |
|
|
|
2f0e58 |
@Test
|
|
|
2f0e58 |
public void testCaptureFromStub() {
|
|
|
2f0e58 |
- Capture<String> capture = new Capture<String>(CaptureType.ALL);
|
|
|
2f0e58 |
- IMethods mock = createMock(IMethods.class);
|
|
|
2f0e58 |
+ final Capture<String> capture = new Capture<String>(CaptureType.ALL);
|
|
|
2f0e58 |
+ final IMethods mock = createMock(IMethods.class);
|
|
|
2f0e58 |
expect(mock.oneArg(capture(capture))).andStubReturn("1");
|
|
|
2f0e58 |
|
|
|
2f0e58 |
replay(mock);
|