summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrett Chabot <brettchabot@android.com>2010-02-02 15:28:33 -0800
committerBrett Chabot <brettchabot@android.com>2010-02-02 16:26:07 -0800
commit47d431f63a66505a645f282416659a9758a91f1c (patch)
tree73d43af9738e593a2cbffc8cdd3d54af3d766221
parent350eeebe430dcf196b67e58e1bf4f8cd51793a1a (diff)
downloadeasymock-47d431f63a66505a645f282416659a9758a91f1c.tar.gz
Add EasyMock 2.5.2 source.
-rw-r--r--Android.mk24
-rw-r--r--LICENSE.txt202
-rw-r--r--src/org/easymock/AbstractMatcher.java139
-rw-r--r--src/org/easymock/ArgumentsMatcher.java53
-rw-r--r--src/org/easymock/Capture.java138
-rw-r--r--src/org/easymock/CaptureType.java43
-rw-r--r--src/org/easymock/EasyMock.java1734
-rw-r--r--src/org/easymock/EasyMockSupport.java236
-rw-r--r--src/org/easymock/IAnswer.java34
-rw-r--r--src/org/easymock/IArgumentMatcher.java47
-rw-r--r--src/org/easymock/IExpectationSetters.java151
-rw-r--r--src/org/easymock/IMocksControl.java94
-rw-r--r--src/org/easymock/LogicalOperator.java59
-rw-r--r--src/org/easymock/MockControl.java649
-rw-r--r--src/org/easymock/internal/AlwaysMatcher.java32
-rw-r--r--src/org/easymock/internal/ArgumentToString.java51
-rw-r--r--src/org/easymock/internal/ArrayMatcher.java30
-rw-r--r--src/org/easymock/internal/AssertionErrorWrapper.java31
-rw-r--r--src/org/easymock/internal/EasyMockProperties.java146
-rw-r--r--src/org/easymock/internal/EqualsMatcher.java24
-rw-r--r--src/org/easymock/internal/ErrorMessage.java58
-rw-r--r--src/org/easymock/internal/ExpectedInvocation.java135
-rw-r--r--src/org/easymock/internal/ExpectedInvocationAndResult.java41
-rw-r--r--src/org/easymock/internal/ExpectedInvocationAndResults.java46
-rw-r--r--src/org/easymock/internal/ILegacyMatcherMethods.java27
-rw-r--r--src/org/easymock/internal/ILegacyMethods.java24
-rw-r--r--src/org/easymock/internal/IMocksBehavior.java40
-rw-r--r--src/org/easymock/internal/IMocksControlState.java55
-rw-r--r--src/org/easymock/internal/IProxyFactory.java22
-rw-r--r--src/org/easymock/internal/Invocation.java218
-rw-r--r--src/org/easymock/internal/JavaProxyFactory.java27
-rw-r--r--src/org/easymock/internal/LastControl.java124
-rw-r--r--src/org/easymock/internal/LegacyMatcherProvider.java102
-rw-r--r--src/org/easymock/internal/MethodSerializationWrapper.java81
-rw-r--r--src/org/easymock/internal/MockInvocationHandler.java54
-rw-r--r--src/org/easymock/internal/MocksBehavior.java239
-rw-r--r--src/org/easymock/internal/MocksControl.java315
-rw-r--r--src/org/easymock/internal/ObjectMethodsFilter.java109
-rw-r--r--src/org/easymock/internal/Range.java85
-rw-r--r--src/org/easymock/internal/RecordState.java389
-rw-r--r--src/org/easymock/internal/ReplayState.java165
-rw-r--r--src/org/easymock/internal/Result.java114
-rw-r--r--src/org/easymock/internal/Results.java89
-rw-r--r--src/org/easymock/internal/RuntimeExceptionWrapper.java31
-rw-r--r--src/org/easymock/internal/ThrowableWrapper.java31
-rw-r--r--src/org/easymock/internal/UnorderedBehavior.java113
-rw-r--r--src/org/easymock/internal/matchers/And.java53
-rw-r--r--src/org/easymock/internal/matchers/Any.java39
-rw-r--r--src/org/easymock/internal/matchers/ArrayEquals.java69
-rw-r--r--src/org/easymock/internal/matchers/Captures.java54
-rw-r--r--src/org/easymock/internal/matchers/Compare.java53
-rw-r--r--src/org/easymock/internal/matchers/CompareEqual.java35
-rw-r--r--src/org/easymock/internal/matchers/CompareTo.java49
-rw-r--r--src/org/easymock/internal/matchers/Contains.java40
-rw-r--r--src/org/easymock/internal/matchers/EndsWith.java39
-rw-r--r--src/org/easymock/internal/matchers/Equals.java63
-rw-r--r--src/org/easymock/internal/matchers/EqualsWithDelta.java46
-rw-r--r--src/org/easymock/internal/matchers/Find.java41
-rw-r--r--src/org/easymock/internal/matchers/GreaterOrEqual.java35
-rw-r--r--src/org/easymock/internal/matchers/GreaterThan.java35
-rw-r--r--src/org/easymock/internal/matchers/InstanceOf.java39
-rw-r--r--src/org/easymock/internal/matchers/LessOrEqual.java35
-rw-r--r--src/org/easymock/internal/matchers/LessThan.java35
-rw-r--r--src/org/easymock/internal/matchers/Matches.java40
-rw-r--r--src/org/easymock/internal/matchers/Not.java41
-rw-r--r--src/org/easymock/internal/matchers/NotNull.java39
-rw-r--r--src/org/easymock/internal/matchers/Null.java38
-rw-r--r--src/org/easymock/internal/matchers/Or.java53
-rw-r--r--src/org/easymock/internal/matchers/Same.java42
-rw-r--r--src/org/easymock/internal/matchers/StartsWith.java40
70 files changed, 7704 insertions, 0 deletions
diff --git a/Android.mk b/Android.mk
new file mode 100644
index 0000000..36ce737
--- /dev/null
+++ b/Android.mk
@@ -0,0 +1,24 @@
+# Copyright (C) 2010 The Android Open Source Project
+#
+# 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.
+#
+#
+
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+
+LOCAL_MODULE := easymock
+
+include $(BUILD_HOST_JAVA_LIBRARY)
diff --git a/LICENSE.txt b/LICENSE.txt
new file mode 100644
index 0000000..75b5248
--- /dev/null
+++ b/LICENSE.txt
@@ -0,0 +1,202 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ 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.
diff --git a/src/org/easymock/AbstractMatcher.java b/src/org/easymock/AbstractMatcher.java
new file mode 100644
index 0000000..49c6da2
--- /dev/null
+++ b/src/org/easymock/AbstractMatcher.java
@@ -0,0 +1,139 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock;
+
+import java.io.Serializable;
+
+import org.easymock.internal.ArgumentToString;
+
+/**
+ * A convenience implementation of {@link ArgumentsMatcher}. A subclass that
+ * does not redefine any method will behave like
+ * {@link MockControl#EQUALS_MATCHER}.
+ *
+ * @deprecated Since EasyMock 2.0, <code>ArgumentsMatcher</code>s are only supported
+ * for the legacy <code>MockControl</code>. For mock objects generated by the methods
+ * on <code>EasyMock</code>, there are per-argument matchers available. For more
+ * information, see the EasyMock documentation.
+ */
+@Deprecated
+public abstract class AbstractMatcher implements ArgumentsMatcher, Serializable {
+
+ private static final long serialVersionUID = -5463061331694985383L;
+
+ /**
+ * Checks whether an expected argument matches an actual argument; the method
+ * is used by
+ * {@link AbstractMatcher#matches(Object[], Object[])}. The arguments
+ * provided to this method are always not <code>null</code>.
+ *
+ * @param expected
+ * the expected argument.
+ * @param actual
+ * the actual argument.
+ * @return true if the arguments match, false otherwise.
+ */
+ protected boolean argumentMatches(Object expected, Object actual) {
+ return expected.equals(actual);
+ }
+
+ /**
+ * Converts an argument to a String, used by
+ * {@link AbstractMatcher#toString(Object[])}.
+ *
+ * @param argument
+ * the argument to convert to a String.
+ * @return a <code>String</code> representation of the argument.
+ */
+ protected String argumentToString(Object argument) {
+ StringBuffer result = new StringBuffer();
+ ArgumentToString.appendArgument(argument, result);
+ return result.toString();
+ }
+
+ /**
+ * Checks whether an expected argument array matches an actual argument array.
+ * This convenience implementation uses
+ * <code>argumentMatches(Object, Object)</code> to check whether arguments
+ * pairs match. If all the arguments match, true is returned, otherwise
+ * false. In two cases, <code>argumentMatches(Object, Object)</code> is
+ * not called: If both argument arrays are null, they match; if one and only
+ * one is null, they do not match.
+ *
+ * @param expected
+ * the expected arguments.
+ * @param actual
+ * the actual arguments.
+ * @return true if the arguments match, false otherwise.
+ */
+ public boolean matches(Object[] expected, Object[] actual) {
+ if (expected == actual) {
+ return true;
+ }
+ if (expected == null || actual == null) {
+ return false;
+ }
+ if (expected.length != actual.length) {
+ return false;
+ }
+ for (int i = 0; i < expected.length; i++) {
+ Object expectedObject = expected[i];
+ Object actualObject = actual[i];
+
+ if (expectedObject == null && actualObject == null) {
+ continue;
+ }
+
+ if (expectedObject == null && actualObject != null) {
+ return false;
+ }
+
+ if (expectedObject != null && actualObject == null) {
+ return false;
+ }
+
+ if (!argumentMatches(expectedObject, actualObject)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Returns a string representation of the matcher. This convenience
+ * implementation calls {@link AbstractMatcher#argumentToString(Object)}
+ * for every argument in the given array and returns the string representations
+ * of the arguments separated by commas.
+ *
+ * @param arguments
+ * the arguments to be used in the string representation.
+ * @return a string representation of the matcher.
+ */
+ public String toString(Object[] arguments) {
+ if (arguments == null)
+ arguments = new Object[0];
+
+ StringBuilder result = new StringBuilder();
+
+ for (int i = 0; i < arguments.length; i++) {
+ if (i > 0) {
+ result.append(", ");
+ }
+ result.append(argumentToString(arguments[i]));
+ }
+ return result.toString();
+ }
+}
diff --git a/src/org/easymock/ArgumentsMatcher.java b/src/org/easymock/ArgumentsMatcher.java
new file mode 100644
index 0000000..5ed395b
--- /dev/null
+++ b/src/org/easymock/ArgumentsMatcher.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock;
+
+/**
+ * A comparison function that is used to match arguments.
+ *
+ * @see MockControl#setDefaultMatcher
+ * @see MockControl#setMatcher
+ * @see MockControl#EQUALS_MATCHER
+ * @see MockControl#ARRAY_MATCHER
+ * @see MockControl#ALWAYS_MATCHER
+ *
+ * @deprecated Since EasyMock 2.0, <code>ArgumentsMatcher</code>s are only supported
+ * for the legacy <code>MockControl</code>. For mock objects generated by the methods
+ * on <code>EasyMock</code>, there are per-argument matchers available. For more
+ * information, see the EasyMock documentation.
+ */
+public interface ArgumentsMatcher {
+
+ /**
+ * Matches two arrays of arguments.
+ *
+ * @param expected
+ * the expected arguments.
+ * @param actual
+ * the actual arguments.
+ * @return true if the arguments match, false otherwise.
+ */
+ boolean matches(Object[] expected, Object[] actual);
+
+ /**
+ * Returns a string representation of the arguments.
+ *
+ * @param arguments
+ * the arguments to be used in the string representation.
+ * @return a string representation of the arguments.
+ */
+ String toString(Object[] arguments);
+}
diff --git a/src/org/easymock/Capture.java b/src/org/easymock/Capture.java
new file mode 100644
index 0000000..f9a1b0c
--- /dev/null
+++ b/src/org/easymock/Capture.java
@@ -0,0 +1,138 @@
+/*
+ * Copyright 2003-2009 OFFIS, Henri Tremblay
+ *
+ * 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 org.easymock;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Will contain what was captured by the <code>capture()</code> matcher. Knows
+ * if something was captured or not (allows to capture a null value).
+ *
+ * @param <T>
+ * Type of the captured element
+ */
+public class Capture<T> implements Serializable {
+
+ private static final long serialVersionUID = -4214363692271370781L;
+
+ private CaptureType type;
+
+ private final List<T> values = new ArrayList<T>(2);
+
+ /**
+ * Default constructor. Only the last element will be captured
+ */
+ public Capture() {
+ this(CaptureType.LAST);
+ }
+
+ /**
+ * Constructor allowing to select the capture type
+ *
+ * @param type
+ * capture type
+ */
+ public Capture(CaptureType type) {
+ this.type = type;
+ }
+
+ /**
+ * Will reset capture to a "nothing captured yet" state
+ */
+ public void reset() {
+ values.clear();
+ }
+
+ /**
+ * @return true if something was captured
+ */
+ public boolean hasCaptured() {
+ return !values.isEmpty();
+ }
+
+ /**
+ * Return captured value
+ *
+ * @throws AssertionError
+ * if nothing was captured yet or if more than one value was
+ * captured
+ * @return The last captured value
+ */
+ public T getValue() {
+ if (values.isEmpty()) {
+ throw new AssertionError("Nothing captured yet");
+ }
+ if (values.size() > 1) {
+ throw new AssertionError("More than one value captured: "
+ + getValues());
+ }
+ return values.get(values.size() - 1);
+ }
+
+ /**
+ * Return all captured values. It returns the actual list so you can modify
+ * it's content if needed
+ *
+ * @return The currently captured values
+ */
+ public List<T> getValues() {
+ return values;
+ }
+
+ /**
+ * Used internally by the EasyMock framework to add a new captured value
+ *
+ * @param value
+ * Value captured
+ */
+ public void setValue(T value) {
+ switch (type) {
+ case NONE:
+ break;
+ case ALL:
+ values.add(value);
+ break;
+ case FIRST:
+ if (!hasCaptured()) {
+ values.add(value);
+ }
+ break;
+ case LAST:
+ if (hasCaptured()) {
+ reset();
+ }
+ values.add(value);
+ break;
+ // ///CLOVER:OFF
+ default:
+ throw new IllegalArgumentException("Unknown capture type: " + type);
+ // ///CLOVER:ON
+ }
+ }
+
+ @Override
+ public String toString() {
+ if (values.isEmpty()) {
+ return "Nothing captured yet";
+ }
+ if (values.size() == 1) {
+ return String.valueOf(values.get(0));
+ }
+ return values.toString();
+ }
+}
diff --git a/src/org/easymock/CaptureType.java b/src/org/easymock/CaptureType.java
new file mode 100644
index 0000000..2e921ad
--- /dev/null
+++ b/src/org/easymock/CaptureType.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2003-2009 OFFIS, Henri Tremblay
+ *
+ * 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 org.easymock;
+
+/**
+ * Defines how arguments will be captured by a <tt>Capture</tt> object
+ *
+ * @see Capture
+ */
+public enum CaptureType {
+ /**
+ * Do not capture anything
+ */
+ NONE,
+
+ /**
+ * Will capture the argument of the first matching call
+ */
+ FIRST,
+
+ /**
+ * Will capture the argument of the last matching call
+ */
+ LAST,
+
+ /**
+ * Will capture, in order, the arguments of each matching calls
+ */
+ ALL
+}
diff --git a/src/org/easymock/EasyMock.java b/src/org/easymock/EasyMock.java
new file mode 100644
index 0000000..95138ce
--- /dev/null
+++ b/src/org/easymock/EasyMock.java
@@ -0,0 +1,1734 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock;
+
+import java.lang.reflect.Proxy;
+import java.util.Comparator;
+
+import org.easymock.internal.*;
+import org.easymock.internal.matchers.*;
+
+public class EasyMock {
+
+ /**
+ * Since EasyMock 2.4, by default, a mock wasn't allowed to be called in
+ * multiple threads unless it was made thread-safe (See
+ * {@link #makeThreadSafe(Object, boolean)} method). Since EasyMock 2.5,
+ * this isn't the default anymore. For backward compatibility, this property
+ * can bring EasyMock 2.4 behavior back.
+ */
+ public static final String ENABLE_THREAD_SAFETY_CHECK_BY_DEFAULT = "easymock.enableThreadSafetyCheckByDefault";
+
+ /**
+ * Since EasyMock 2.5, by default a mock is thread-safe. For backward
+ * compatibility, this property can change the default. A given mock still
+ * can be made thread-safe by calling
+ * {@link #makeThreadSafe(Object, boolean)}.
+ */
+ public static final String NOT_THREAD_SAFE_BY_DEFAULT = "easymock.notThreadSafeByDefault";
+
+ /**
+ * Creates a mock object that implements the given interface, order checking
+ * is enabled by default.
+ *
+ * @param <T>
+ * the interface that the mock object should implement.
+ * @param toMock
+ * the class of the interface that the mock object should
+ * implement.
+ * @return the mock object.
+ */
+ public static <T> T createStrictMock(Class<T> toMock) {
+ return createStrictControl().createMock(toMock);
+ }
+
+ /**
+ * Creates a mock object that implements the given interface, order checking
+ * is enabled by default.
+ * @param name the name of the mock object.
+ * @param toMock
+ * the class of the interface that the mock object should
+ * implement.
+ * @param <T>
+ * the interface that the mock object should implement.
+ * @return the mock object.
+ * @throws IllegalArgumentException if the name is not a valid Java identifier.
+ */
+ public static <T> T createStrictMock(String name, Class<T> toMock) {
+ return createStrictControl().createMock(name, toMock);
+ }
+
+ /**
+ * Creates a mock object that implements the given interface, order checking
+ * is disabled by default.
+ *
+ * @param <T>
+ * the interface that the mock object should implement.
+ * @param toMock
+ * the class of the interface that the mock object should
+ * implement.
+ * @return the mock object.
+ */
+ public static <T> T createMock(Class<T> toMock) {
+ return createControl().createMock(toMock);
+ }
+
+ /**
+ * Creates a mock object that implements the given interface, order checking
+ * is disabled by default.
+ * @param name the name of the mock object.
+ * @param toMock
+ * the class of the interface that the mock object should
+ * implement.
+ *
+ * @param <T>
+ * the interface that the mock object should implement.
+ * @return the mock object.
+ * @throws IllegalArgumentException if the name is not a valid Java identifier.
+ */
+ public static <T> T createMock(String name, Class<T> toMock) {
+ return createControl().createMock(name, toMock);
+ }
+
+ /**
+ * Creates a mock object that implements the given interface, order checking
+ * is disabled by default, and the mock object will return <code>0</code>,
+ * <code>null</code> or <code>false</code> for unexpected invocations.
+ *
+ * @param <T>
+ * the interface that the mock object should implement.
+ * @param toMock
+ * the class of the interface that the mock object should
+ * implement.
+ * @return the mock object.
+ */
+ public static <T> T createNiceMock(Class<T> toMock) {
+ return createNiceControl().createMock(toMock);
+ }
+
+ /**
+ * Creates a mock object that implements the given interface, order checking
+ * is disabled by default, and the mock object will return <code>0</code>,
+ * <code>null</code> or <code>false</code> for unexpected invocations.
+ * @param name the name of the mock object.
+ * @param toMock
+ * the class of the interface that the mock object should
+ * implement.
+ *
+ * @param <T>
+ * the interface that the mock object should implement.
+ * @return the mock object.
+ * @throws IllegalArgumentException if the name is not a valid Java identifier.
+ */
+ public static <T> T createNiceMock(String name, Class<T> toMock) {
+ return createNiceControl().createMock(name, toMock);
+ }
+
+ /**
+ * Creates a control, order checking is enabled by default.
+ *
+ * @return the control.
+ */
+ public static IMocksControl createStrictControl() {
+ return new MocksControl(MocksControl.MockType.STRICT);
+ }
+
+ /**
+ * Creates a control, order checking is disabled by default.
+ *
+ * @return the control.
+ */
+ public static IMocksControl createControl() {
+ return new MocksControl(MocksControl.MockType.DEFAULT);
+ }
+
+ /**
+ * Creates a control, order checking is disabled by default, and the mock
+ * objects created by this control will return <code>0</code>,
+ * <code>null</code> or <code>false</code> for unexpected invocations.
+ *
+ * @return the control.
+ */
+ public static IMocksControl createNiceControl() {
+ return new MocksControl(MocksControl.MockType.NICE);
+ }
+
+ /**
+ * Returns the expectation setter for the last expected invocation in the
+ * current thread.
+ *
+ * @param <T> type returned by the expected method
+ * @param value
+ * the parameter is used to transport the type to the
+ * ExpectationSetter. It allows writing the expected call as
+ * argument, i.e.
+ * <code>expect(mock.getName()).andReturn("John Doe")<code>.
+ *
+ * @return the expectation setter.
+ */
+ public static <T> IExpectationSetters<T> expect(T value) {
+ return EasyMock.getControlForLastCall();
+ }
+
+ /**
+ * Returns the expectation setter for the last expected invocation in the
+ * current thread. This method is used for expected invocations on void
+ * methods.
+ *
+ * @param <T> type returned by the expected method
+ * @return the expectation setter.
+ */
+ public static <T> IExpectationSetters<T> expectLastCall() {
+ return getControlForLastCall();
+ }
+
+ @SuppressWarnings("unchecked")
+ private static <T> IExpectationSetters<T> getControlForLastCall() {
+ MocksControl lastControl = LastControl.lastControl();
+ if (lastControl == null) {
+ throw new IllegalStateException("no last call on a mock available");
+ }
+ return (IExpectationSetters<T>) lastControl;
+ }
+
+ /**
+ * Expects any boolean argument. For details, see the EasyMock
+ * documentation.
+ *
+ * @return <code>false</code>.
+ */
+ public static boolean anyBoolean() {
+ reportMatcher(Any.ANY);
+ return false;
+ }
+
+ /**
+ * Expects any byte argument. For details, see the EasyMock documentation.
+ *
+ * @return <code>0</code>.
+ */
+ public static byte anyByte() {
+ reportMatcher(Any.ANY);
+ return 0;
+ }
+
+ /**
+ * Expects any char argument. For details, see the EasyMock documentation.
+ *
+ * @return <code>0</code>.
+ */
+ public static char anyChar() {
+ reportMatcher(Any.ANY);
+ return 0;
+ }
+
+ /**
+ * Expects any int argument. For details, see the EasyMock documentation.
+ *
+ * @return <code>0</code>.
+ */
+ public static int anyInt() {
+ reportMatcher(Any.ANY);
+ return 0;
+ }
+
+ /**
+ * Expects any long argument. For details, see the EasyMock documentation.
+ *
+ * @return <code>0</code>.
+ */
+ public static long anyLong() {
+ reportMatcher(Any.ANY);
+ return 0;
+ }
+
+ /**
+ * Expects any float argument. For details, see the EasyMock documentation.
+ *
+ * @return <code>0</code>.
+ */
+ public static float anyFloat() {
+ reportMatcher(Any.ANY);
+ return 0;
+ }
+
+ /**
+ * Expects any double argument. For details, see the EasyMock documentation.
+ *
+ * @return <code>0</code>.
+ */
+ public static double anyDouble() {
+ reportMatcher(Any.ANY);
+ return 0;
+ }
+
+ /**
+ * Expects any short argument. For details, see the EasyMock documentation.
+ *
+ * @return <code>0</code>.
+ */
+ public static short anyShort() {
+ reportMatcher(Any.ANY);
+ return 0;
+ }
+
+ /**
+ * Expects any Object argument. For details, see the EasyMock documentation.
+ *
+ * @param <T> type of the method argument to match
+ * @return <code>null</code>.
+ */
+ public static <T> T anyObject() {
+ reportMatcher(Any.ANY);
+ return null;
+ }
+
+ /**
+ * Expects a comparable argument greater than or equal the given value. For details, see
+ * the EasyMock documentation.
+ *
+ * @param <T> type of the method argument to match
+ * @param value
+ * the given value.
+ * @return <code>null</code>.
+ */
+ public static <T extends Comparable<T>> T geq(Comparable<T> value) {
+ reportMatcher(new GreaterOrEqual<T>(value));
+ return null;
+ }
+
+ /**
+ * Expects a byte argument greater than or equal to the given value. For
+ * details, see the EasyMock documentation.
+ *
+ * @param value
+ * the given value.
+ * @return <code>0</code>.
+ */
+ public static byte geq(byte value) {
+ reportMatcher(new GreaterOrEqual<Byte>(value));
+ return 0;
+ }
+
+ /**
+ * Expects a double argument greater than or equal to the given value. For
+ * details, see the EasyMock documentation.
+ *
+ * @param value
+ * the given value.
+ * @return <code>0</code>.
+ */
+ public static double geq(double value) {
+ reportMatcher(new GreaterOrEqual<Double>(value));
+ return 0;
+ }
+
+ /**
+ * Expects a float argument greater than or equal to the given value. For
+ * details, see the EasyMock documentation.
+ *
+ * @param value
+ * the given value.
+ * @return <code>0</code>.
+ */
+ public static float geq(float value) {
+ reportMatcher(new GreaterOrEqual<Float>(value));
+ return 0;
+ }
+
+ /**
+ * Expects an int argument greater than or equal to the given value. For
+ * details, see the EasyMock documentation.
+ *
+ * @param value
+ * the given value.
+ * @return <code>0</code>.
+ */
+ public static int geq(int value) {
+ reportMatcher(new GreaterOrEqual<Integer>(value));
+ return 0;
+ }
+
+ /**
+ * Expects a long argument greater than or equal to the given value. For
+ * details, see the EasyMock documentation.
+ *
+ * @param value
+ * the given value.
+ * @return <code>0</code>.
+ */
+ public static long geq(long value) {
+ reportMatcher(new GreaterOrEqual<Long>(value));
+ return 0;
+ }
+
+ /**
+ * Expects a short argument greater than or equal to the given value. For
+ * details, see the EasyMock documentation.
+ *
+ * @param value
+ * the given value.
+ * @return <code>0</code>.
+ */
+ public static short geq(short value) {
+ reportMatcher(new GreaterOrEqual<Short>(value));
+ return 0;
+ }
+
+ /**
+ * Expects a comparable argument less than or equal the given value. For details, see
+ * the EasyMock documentation.
+ *
+ * @param <T> type of the method argument to match
+ * @param value
+ * the given value.
+ * @return <code>null</code>.
+ */
+ public static <T extends Comparable<T>> T leq(Comparable<T> value) {
+ reportMatcher(new LessOrEqual<T>(value));
+ return null;
+ }
+
+ /**
+ * Expects a byte argument less than or equal to the given value. For
+ * details, see the EasyMock documentation.
+ *
+ * @param value
+ * the given value.
+ * @return <code>0</code>.
+ */
+ public static byte leq(byte value) {
+ reportMatcher(new LessOrEqual<Byte>(value));
+ return 0;
+ }
+
+ /**
+ * Expects a double argument less than or equal to the given value. For
+ * details, see the EasyMock documentation.
+ *
+ * @param value
+ * the given value.
+ * @return <code>0</code>.
+ */
+ public static double leq(double value) {
+ reportMatcher(new LessOrEqual<Double>(value));
+ return 0;
+ }
+
+ /**
+ * Expects a float argument less than or equal to the given value. For
+ * details, see the EasyMock documentation.
+ *
+ * @param value
+ * the given value.
+ * @return <code>0</code>.
+ */
+ public static float leq(float value) {
+ reportMatcher(new LessOrEqual<Float>(value));
+ return 0;
+ }
+
+ /**
+ * Expects an int argument less than or equal to the given value. For
+ * details, see the EasyMock documentation.
+ *
+ * @param value
+ * the given value.
+ * @return <code>0</code>.
+ */
+ public static int leq(int value) {
+ reportMatcher(new LessOrEqual<Integer>(value));
+ return 0;
+ }
+
+ /**
+ * Expects a long argument less than or equal to the given value. For
+ * details, see the EasyMock documentation.
+ *
+ * @param value
+ * the given value.
+ * @return <code>0</code>.
+ */
+ public static long leq(long value) {
+ reportMatcher(new LessOrEqual<Long>(value));
+ return 0;
+ }
+
+ /**
+ * Expects a short argument less than or equal to the given value. For
+ * details, see the EasyMock documentation.
+ *
+ * @param value
+ * the given value.
+ * @return <code>0</code>.
+ */
+ public static short leq(short value) {
+ reportMatcher(new LessOrEqual<Short>(value));
+ return 0;
+ }
+
+ /**
+ * Expects a comparable argument greater than the given value. For details, see
+ * the EasyMock documentation.
+ *
+ * @param <T> type of the method argument to match
+ * @param value
+ * the given value.
+ * @return <code>null</code>.
+ */
+ public static <T extends Comparable<T>> T gt(Comparable<T> value) {
+ reportMatcher(new GreaterThan<T>(value));
+ return null;
+ }
+
+ /**
+ * Expects a byte argument greater than the given value. For details, see
+ * the EasyMock documentation.
+ *
+ * @param value
+ * the given value.
+ * @return <code>0</code>.
+ */
+ public static byte gt(byte value) {
+ reportMatcher(new GreaterThan<Byte>(value));
+ return 0;
+ }
+
+ /**
+ * Expects a double argument greater than the given value. For details, see
+ * the EasyMock documentation.
+ *
+ * @param value
+ * the given value.
+ * @return <code>0</code>.
+ */
+ public static double gt(double value) {
+ reportMatcher(new GreaterThan<Double>(value));
+ return 0;
+ }
+
+ /**
+ * Expects a float argument greater than the given value. For details, see
+ * the EasyMock documentation.
+ *
+ * @param value
+ * the given value.
+ * @return <code>0</code>.
+ */
+ public static float gt(float value) {
+ reportMatcher(new GreaterThan<Float>(value));
+ return 0;
+ }
+
+ /**
+ * Expects an int argument greater than the given value. For details, see
+ * the EasyMock documentation.
+ *
+ * @param value
+ * the given value.
+ * @return <code>0</code>.
+ */
+ public static int gt(int value) {
+ reportMatcher(new GreaterThan<Integer>(value));
+ return 0;
+ }
+
+ /**
+ * Expects a long argument greater than the given value. For details, see
+ * the EasyMock documentation.
+ *
+ * @param value
+ * the given value.
+ * @return <code>0</code>.
+ */
+ public static long gt(long value) {
+ reportMatcher(new GreaterThan<Long>(value));
+ return 0;
+ }
+
+ /**
+ * Expects a short argument greater than the given value. For details, see
+ * the EasyMock documentation.
+ *
+ * @param value
+ * the given value.
+ * @return <code>0</code>.
+ */
+ public static short gt(short value) {
+ reportMatcher(new GreaterThan<Short>(value));
+ return 0;
+ }
+
+ /**
+ * Expects a comparable argument less than the given value. For details, see
+ * the EasyMock documentation.
+ *
+ * @param <T> type of the method argument to match
+ * @param value
+ * the given value.
+ * @return <code>null</code>.
+ */
+ public static <T extends Comparable<T>> T lt(Comparable<T> value) {
+ reportMatcher(new LessThan<T>(value));
+ return null;
+ }
+
+ /**
+ * Expects a byte argument less than the given value. For details, see the
+ * EasyMock documentation.
+ *
+ * @param value
+ * the given value.
+ * @return <code>0</code>.
+ */
+ public static byte lt(byte value) {
+ reportMatcher(new LessThan<Byte>(value));
+ return 0;
+ }
+
+ /**
+ * Expects a double argument less than the given value. For details, see the
+ * EasyMock documentation.
+ *
+ * @param value
+ * the given value.
+ * @return <code>0</code>.
+ */
+ public static double lt(double value) {
+ reportMatcher(new LessThan<Double>(value));
+ return 0;
+ }
+
+ /**
+ * Expects a float argument less than the given value. For details, see the
+ * EasyMock documentation.
+ *
+ * @param value
+ * the given value.
+ * @return <code>0</code>.
+ */
+ public static float lt(float value) {
+ reportMatcher(new LessThan<Float>(value));
+ return 0;
+ }
+
+ /**
+ * Expects an int argument less than the given value. For details, see the
+ * EasyMock documentation.
+ *
+ * @param value
+ * the given value.
+ * @return <code>0</code>.
+ */
+ public static int lt(int value) {
+ reportMatcher(new LessThan<Integer>(value));
+ return 0;
+ }
+
+ /**
+ * Expects a long argument less than the given value. For details, see the
+ * EasyMock documentation.
+ *
+ * @param value
+ * the given value.
+ * @return <code>0</code>.
+ */
+ public static long lt(long value) {
+ reportMatcher(new LessThan<Long>(value));
+ return 0;
+ }
+
+ /**
+ * Expects a short argument less than the given value. For details, see the
+ * EasyMock documentation.
+ *
+ * @param value
+ * the given value.
+ * @return <code>0</code>.
+ */
+ public static short lt(short value) {
+ reportMatcher(new LessThan<Short>(value));
+ return 0;
+ }
+
+ /**
+ * Expects an object implementing the given class. For details, see the
+ * EasyMock documentation.
+ *
+ * @param <T>
+ * the accepted type.
+ * @param clazz
+ * the class of the accepted type.
+ * @return <code>null</code>.
+ */
+ public static <T> T isA(Class<T> clazz) {
+ reportMatcher(new InstanceOf(clazz));
+ return null;
+ }
+
+ /**
+ * Expects a string that contains the given substring. For details, see the
+ * EasyMock documentation.
+ *
+ * @param substring
+ * the substring.
+ * @return <code>null</code>.
+ */
+ public static String contains(String substring) {
+ reportMatcher(new Contains(substring));
+ return null;
+ }
+
+ /**
+ * Expects a boolean that matches both given expectations.
+ *
+ * @param first
+ * placeholder for the first expectation.
+ * @param second
+ * placeholder for the second expectation.
+ * @return <code>false</code>.
+ */
+ public static boolean and(boolean first, boolean second) {
+ LastControl.reportAnd(2);
+ return false;
+ }
+
+ /**
+ * Expects a byte that matches both given expectations.
+ *
+ * @param first
+ * placeholder for the first expectation.
+ * @param second
+ * placeholder for the second expectation.
+ * @return <code>0</code>.
+ */
+ public static byte and(byte first, byte second) {
+ LastControl.reportAnd(2);
+ return 0;
+ }
+
+ /**
+ * Expects a char that matches both given expectations.
+ *
+ * @param first
+ * placeholder for the first expectation.
+ * @param second
+ * placeholder for the second expectation.
+ * @return <code>0</code>.
+ */
+ public static char and(char first, char second) {
+ LastControl.reportAnd(2);
+ return 0;
+ }
+
+ /**
+ * Expects a double that matches both given expectations.
+ *
+ * @param first
+ * placeholder for the first expectation.
+ * @param second
+ * placeholder for the second expectation.
+ * @return <code>0</code>.
+ */
+ public static double and(double first, double second) {
+ LastControl.reportAnd(2);
+ return 0;
+ }
+
+ /**
+ * Expects a float that matches both given expectations.
+ *
+ * @param first
+ * placeholder for the first expectation.
+ * @param second
+ * placeholder for the second expectation.
+ * @return <code>0</code>.
+ */
+ public static float and(float first, float second) {
+ LastControl.reportAnd(2);
+ return 0;
+ }
+
+ /**
+ * Expects an int that matches both given expectations.
+ *
+ * @param first
+ * placeholder for the first expectation.
+ * @param second
+ * placeholder for the second expectation.
+ * @return <code>0</code>.
+ */
+ public static int and(int first, int second) {
+ LastControl.reportAnd(2);
+ return 0;
+ }
+
+ /**
+ * Expects a long that matches both given expectations.
+ *
+ * @param first
+ * placeholder for the first expectation.
+ * @param second
+ * placeholder for the second expectation.
+ * @return <code>0</code>.
+ */
+ public static long and(long first, long second) {
+ LastControl.reportAnd(2);
+ return 0;
+ }
+
+ /**
+ * Expects a short that matches both given expectations.
+ *
+ * @param first
+ * placeholder for the first expectation.
+ * @param second
+ * placeholder for the second expectation.
+ * @return <code>0</code>.
+ */
+ public static short and(short first, short second) {
+ LastControl.reportAnd(2);
+ return 0;
+ }
+
+ /**
+ * Expects an Object that matches both given expectations.
+ *
+ * @param <T>
+ * the type of the object, it is passed through to prevent casts.
+ * @param first
+ * placeholder for the first expectation.
+ * @param second
+ * placeholder for the second expectation.
+ * @return <code>null</code>.
+ */
+ public static <T> T and(T first, T second) {
+ LastControl.reportAnd(2);
+ return null;
+ }
+
+ /**
+ * Expects a boolean that matches one of the given expectations.
+ *
+ * @param first
+ * placeholder for the first expectation.
+ * @param second
+ * placeholder for the second expectation.
+ * @return <code>false</code>.
+ */
+ public static boolean or(boolean first, boolean second) {
+ LastControl.reportOr(2);
+ return false;
+ }
+
+ /**
+ * Expects a byte that matches one of the given expectations.
+ *
+ * @param first
+ * placeholder for the first expectation.
+ * @param second
+ * placeholder for the second expectation.
+ * @return <code>0</code>.
+ */
+ public static byte or(byte first, byte second) {
+ LastControl.reportOr(2);
+ return 0;
+ }
+
+ /**
+ * Expects a char that matches one of the given expectations.
+ *
+ * @param first
+ * placeholder for the first expectation.
+ * @param second
+ * placeholder for the second expectation.
+ * @return <code>0</code>.
+ */
+ public static char or(char first, char second) {
+ LastControl.reportOr(2);
+ return 0;
+ }
+
+ /**
+ * Expects a double that matches one of the given expectations.
+ *
+ * @param first
+ * placeholder for the first expectation.
+ * @param second
+ * placeholder for the second expectation.
+ * @return <code>0</code>.
+ */
+ public static double or(double first, double second) {
+ LastControl.reportOr(2);
+ return 0;
+ }
+
+ /**
+ * Expects a float that matches one of the given expectations.
+ *
+ * @param first
+ * placeholder for the first expectation.
+ * @param second
+ * placeholder for the second expectation.
+ * @return <code>0</code>.
+ */
+ public static float or(float first, float second) {
+ LastControl.reportOr(2);
+ return 0;
+ }
+
+ /**
+ * Expects an int that matches one of the given expectations.
+ *
+ * @param first
+ * placeholder for the first expectation.
+ * @param second
+ * placeholder for the second expectation.
+ * @return <code>0</code>.
+ */
+ public static int or(int first, int second) {
+ LastControl.reportOr(2);
+ return first;
+ }
+
+ /**
+ * Expects a long that matches one of the given expectations.
+ *
+ * @param first
+ * placeholder for the first expectation.
+ * @param second
+ * placeholder for the second expectation.
+ * @return <code>0</code>.
+ */
+ public static long or(long first, long second) {
+ LastControl.reportOr(2);
+ return 0;
+ }
+
+ /**
+ * Expects a short that matches one of the given expectations.
+ *
+ * @param first
+ * placeholder for the first expectation.
+ * @param second
+ * placeholder for the second expectation.
+ * @return <code>0</code>.
+ */
+ public static short or(short first, short second) {
+ LastControl.reportOr(2);
+ return 0;
+ }
+
+ /**
+ * Expects an Object that matches one of the given expectations.
+ *
+ * @param <T>
+ * the type of the object, it is passed through to prevent casts.
+ * @param first
+ * placeholder for the first expectation.
+ * @param second
+ * placeholder for the second expectation.
+ * @return <code>null</code>.
+ */
+ public static <T> T or(T first, T second) {
+ LastControl.reportOr(2);
+ return null;
+ }
+
+ /**
+ * Expects a boolean that does not match the given expectation.
+ *
+ * @param first
+ * placeholder for the expectation.
+ * @return <code>false</code>.
+ */
+ public static boolean not(boolean first) {
+ LastControl.reportNot();
+ return false;
+ }
+
+ /**
+ * Expects a byte that does not match the given expectation.
+ *
+ * @param first
+ * placeholder for the expectation.
+ * @return <code>0</code>.
+ */
+ public static byte not(byte first) {
+ LastControl.reportNot();
+ return 0;
+ }
+
+ /**
+ * Expects a char that does not match the given expectation.
+ *
+ * @param first
+ * placeholder for the expectation.
+ * @return <code>0</code>.
+ */
+ public static char not(char first) {
+ LastControl.reportNot();
+ return 0;
+ }
+
+ /**
+ * Expects a double that does not match the given expectation.
+ *
+ * @param first
+ * placeholder for the expectation.
+ * @return <code>0</code>.
+ */
+ public static double not(double first) {
+ LastControl.reportNot();
+ return 0;
+ }
+
+ /**
+ * Expects a float that does not match the given expectation.
+ *
+ * @param first
+ * placeholder for the expectation.
+ * @return <code>0</code>.
+ */
+ public static float not(float first) {
+ LastControl.reportNot();
+ return first;
+ }
+
+ /**
+ * Expects an int that does not match the given expectation.
+ *
+ * @param first
+ * placeholder for the expectation.
+ * @return <code>0</code>.
+ */
+ public static int not(int first) {
+ LastControl.reportNot();
+ return 0;
+ }
+
+ /**
+ * Expects a long that does not match the given expectation.
+ *
+ * @param first
+ * placeholder for the expectation.
+ * @return <code>0</code>.
+ */
+ public static long not(long first) {
+ LastControl.reportNot();
+ return 0;
+ }
+
+ /**
+ * Expects a short that does not match the given expectation.
+ *
+ * @param first
+ * placeholder for the expectation.
+ * @return <code>0</code>.
+ */
+ public static short not(short first) {
+ LastControl.reportNot();
+ return 0;
+ }
+
+ /**
+ * Expects an Object that does not match the given expectation.
+ *
+ * @param <T>
+ * the type of the object, it is passed through to prevent casts.
+ * @param first
+ * placeholder for the expectation.
+ * @return <code>null</code>.
+ */
+ public static <T> T not(T first) {
+ LastControl.reportNot();
+ return null;
+ }
+
+ /**
+ * Expects a boolean that is equal to the given value.
+ *
+ * @param value
+ * the given value.
+ * @return <code>0</code>.
+ */
+ public static boolean eq(boolean value) {
+ reportMatcher(new Equals(value));
+ return false;
+ }
+
+ /**
+ * Expects a byte that is equal to the given value.
+ *
+ * @param value
+ * the given value.
+ * @return <code>0</code>.
+ */
+ public static byte eq(byte value) {
+ reportMatcher(new Equals(value));
+ return 0;
+ }
+
+ /**
+ * Expects a char that is equal to the given value.
+ *
+ * @param value
+ * the given value.
+ * @return <code>0</code>.
+ */
+ public static char eq(char value) {
+ reportMatcher(new Equals(value));
+ return 0;
+ }
+
+ /**
+ * Expects a double that is equal to the given value.
+ *
+ * @param value
+ * the given value.
+ * @return <code>0</code>.
+ */
+ public static double eq(double value) {
+ reportMatcher(new Equals(value));
+ return 0;
+ }
+
+ /**
+ * Expects a float that is equal to the given value.
+ *
+ * @param value
+ * the given value.
+ * @return <code>0</code>.
+ */
+ public static float eq(float value) {
+ reportMatcher(new Equals(value));
+ return 0;
+ }
+
+ /**
+ * Expects an int that is equal to the given value.
+ *
+ * @param value
+ * the given value.
+ * @return <code>0</code>.
+ */
+ public static int eq(int value) {
+ reportMatcher(new Equals(value));
+ return 0;
+ }
+
+ /**
+ * Expects a long that is equal to the given value.
+ *
+ * @param value
+ * the given value.
+ * @return <code>0</code>.
+ */
+ public static long eq(long value) {
+ reportMatcher(new Equals(value));
+ return 0;
+ }
+
+ /**
+ * Expects a short that is equal to the given value.
+ *
+ * @param value
+ * the given value.
+ * @return <code>0</code>.
+ */
+ public static short eq(short value) {
+ reportMatcher(new Equals(value));
+ return 0;
+ }
+
+ /**
+ * Expects an Object that is equal to the given value.
+ *
+ * @param <T> type of the method argument to match
+ * @param value
+ * the given value.
+ * @return <code>null</code>.
+ */
+ public static <T> T eq(T value) {
+ reportMatcher(new Equals(value));
+ return null;
+ }
+
+ /**
+ * Expects a boolean array that is equal to the given array, i.e. it has to
+ * have the same length, and each element has to be equal.
+ *
+ * @param value
+ * the given arry.
+ * @return <code>null</code>.
+ */
+ public static boolean[] aryEq(boolean[] value) {
+ reportMatcher(new ArrayEquals(value));
+ return null;
+ }
+
+ /**
+ * Expects a byte array that is equal to the given array, i.e. it has to
+ * have the same length, and each element has to be equal.
+ *
+ * @param value
+ * the given arry.
+ * @return <code>null</code>.
+ */
+ public static byte[] aryEq(byte[] value) {
+ reportMatcher(new ArrayEquals(value));
+ return null;
+ }
+
+ /**
+ * Expects a char array that is equal to the given array, i.e. it has to
+ * have the same length, and each element has to be equal.
+ *
+ * @param value
+ * the given arry.
+ * @return <code>null</code>.
+ */
+ public static char[] aryEq(char[] value) {
+ reportMatcher(new ArrayEquals(value));
+ return null;
+ }
+
+ /**
+ * Expects a double array that is equal to the given array, i.e. it has to
+ * have the same length, and each element has to be equal.
+ *
+ * @param value
+ * the given arry.
+ * @return <code>null</code>.
+ */
+ public static double[] aryEq(double[] value) {
+ reportMatcher(new ArrayEquals(value));
+ return null;
+ }
+
+ /**
+ * Expects a float array that is equal to the given array, i.e. it has to
+ * have the same length, and each element has to be equal.
+ *
+ * @param value
+ * the given arry.
+ * @return <code>null</code>.
+ */
+ public static float[] aryEq(float[] value) {
+ reportMatcher(new ArrayEquals(value));
+ return null;
+ }
+
+ /**
+ * Expects an int array that is equal to the given array, i.e. it has to
+ * have the same length, and each element has to be equal.
+ *
+ * @param value
+ * the given arry.
+ * @return <code>null</code>.
+ */
+ public static int[] aryEq(int[] value) {
+ reportMatcher(new ArrayEquals(value));
+ return null;
+ }
+
+ /**
+ * Expects a long array that is equal to the given array, i.e. it has to
+ * have the same length, and each element has to be equal.
+ *
+ * @param value
+ * the given arry.
+ * @return <code>null</code>.
+ */
+ public static long[] aryEq(long[] value) {
+ reportMatcher(new ArrayEquals(value));
+ return null;
+ }
+
+ /**
+ * Expects a short array that is equal to the given array, i.e. it has to
+ * have the same length, and each element has to be equal.
+ *
+ * @param value
+ * the given arry.
+ * @return <code>null</code>.
+ */
+ public static short[] aryEq(short[] value) {
+ reportMatcher(new ArrayEquals(value));
+ return null;
+ }
+
+ /**
+ * Expects an Object array that is equal to the given array, i.e. it has to
+ * have the same type, length, and each element has to be equal.
+ *
+ * @param <T>
+ * the type of the array, it is passed through to prevent casts.
+ * @param value
+ * the given arry.
+ * @return <code>null</code>.
+ */
+ public static <T> T[] aryEq(T[] value) {
+ reportMatcher(new ArrayEquals(value));
+ return null;
+ }
+
+ /**
+ * Expects null.
+ *
+ * @param <T> type of the method argument to match
+ * @return <code>null</code>.
+ */
+ public static <T> T isNull() {
+ reportMatcher(Null.NULL);
+ return null;
+ }
+
+ /**
+ * Expects not null.
+ *
+ * @param <T> type of the method argument to match
+ * @return <code>null</code>.
+ */
+ public static <T> T notNull() {
+ reportMatcher(NotNull.NOT_NULL);
+ return null;
+ }
+
+ /**
+ * Expects a string that contains a substring that matches the given regular
+ * expression. For details, see the EasyMock documentation.
+ *
+ * @param regex
+ * the regular expression.
+ * @return <code>null</code>.
+ */
+ public static String find(String regex) {
+ reportMatcher(new Find(regex));
+ return null;
+ }
+
+ /**
+ * Expects a string that matches the given regular expression. For details,
+ * see the EasyMock documentation.
+ *
+ * @param regex
+ * the regular expression.
+ * @return <code>null</code>.
+ */
+ public static String matches(String regex) {
+ reportMatcher(new Matches(regex));
+ return null;
+ }
+
+ /**
+ * Expects a string that starts with the given prefix. For details, see the
+ * EasyMock documentation.
+ *
+ * @param prefix
+ * the prefix.
+ * @return <code>null</code>.
+ */
+ public static String startsWith(String prefix) {
+ reportMatcher(new StartsWith(prefix));
+ return null;
+ }
+
+ /**
+ * Expects a string that ends with the given suffix. For details, see the
+ * EasyMock documentation.
+ *
+ * @param suffix
+ * the suffix.
+ * @return <code>null</code>.
+ */
+ public static String endsWith(String suffix) {
+ reportMatcher(new EndsWith(suffix));
+ return null;
+ }
+
+ /**
+ * Expects a double that has an absolute difference to the given value that
+ * is less than the given delta. For details, see the EasyMock
+ * documentation.
+ *
+ * @param value
+ * the given value.
+ * @param delta
+ * the given delta.
+ * @return <code>0</code>.
+ */
+ public static double eq(double value, double delta) {
+ reportMatcher(new EqualsWithDelta(value, delta));
+ return 0;
+ }
+
+ /**
+ * Expects a float that has an absolute difference to the given value that
+ * is less than the given delta. For details, see the EasyMock
+ * documentation.
+ *
+ * @param value
+ * the given value.
+ * @param delta
+ * the given delta.
+ * @return <code>0</code>.
+ */
+ public static float eq(float value, float delta) {
+ reportMatcher(new EqualsWithDelta(value, delta));
+ return 0;
+ }
+
+ /**
+ * Expects an Object that is the same as the given value. For details, see
+ * the EasyMock documentation.
+ *
+ * @param <T>
+ * the type of the object, it is passed through to prevent casts.
+ * @param value
+ * the given value.
+ * @return <code>null</code>.
+ */
+ public static <T> T same(T value) {
+ reportMatcher(new Same(value));
+ return null;
+ }
+
+ /**
+ * Expects a comparable argument equals to the given value according to their
+ * compareTo method. For details, see the EasMock documentation.
+ *
+ * @param <T> type of the method argument to match
+ * @param value
+ * the given value.
+ * @return <code>null</code>.
+ */
+ public static <T extends Comparable<T>> T cmpEq(Comparable<T> value) {
+ reportMatcher(new CompareEqual<T>(value));
+ return null;
+ }
+
+ /**
+ * Expects an argument that will be compared using the provided comparator.
+ * The following comparison will take place:
+ * <p>
+ * <code>comparator.compare(actual, expected) operator 0</code>
+ * </p>
+ * For details, see the EasyMock documentation.
+ *
+ * @param <T> type of the method argument to match
+ * @param value the given value.
+ * @param comparator Comparator used to compare the actual with expected value.
+ * @param operator The comparison operator.
+ * @return <code>null</code>
+ */
+ public static <T> T cmp(T value, Comparator<? super T> comparator, LogicalOperator operator) {
+ reportMatcher(new Compare<T>(value, comparator, operator));
+ return null;
+ }
+
+
+ /**
+ * Expects a byte that is equal to the given value.
+ *
+ * @param value
+ * the given value.
+ * @return <code>0</code>.
+ */
+
+
+ /**
+ * Expect any object but captures it for later use.
+ *
+ * @param <T> Type of the captured object
+ * @param captured Where the parameter is captured
+ * @return <code>null</code>
+ */
+ public static <T> T capture(Capture<T> captured) {
+ reportMatcher(new Captures<T>(captured));
+ return null;
+ }
+
+ /******************************************************
+ * ANDROID CHANGE - comment out to fix compile error
+ * name clash: capture(org.easymock.Capture<java.lang.Long>) and
+ * <T>capture(org.easymock.Capture<T>) have the same erasure
+ */
+ /**
+ * Expect any int but captures it for later use.
+ *
+ * @param captured Where the parameter is captured
+ * @return <code>0</code>
+ */
+// public static int capture(Capture<Integer> captured) {
+// reportMatcher(new Captures<Integer>(captured));
+// return 0;
+// }
+
+ /**
+ * Expect any long but captures it for later use.
+ *
+ * @param captured Where the parameter is captured
+ * @return <code>0</code>
+ */
+// public static long capture(Capture<Long> captured) {
+// reportMatcher(new Captures<Long>(captured));
+// return 0;
+// }
+
+ /**
+ * Expect any float but captures it for later use.
+ *
+ * @param captured Where the parameter is captured
+ * @return <code>0</code>
+ */
+// public static float capture(Capture<Float> captured) {
+// reportMatcher(new Captures<Float>(captured));
+// return 0;
+// }
+
+ /**
+ * Expect any double but captures it for later use.
+ *
+ * @param captured Where the parameter is captured
+ * @return <code>0</code>
+ */
+// public static double capture(Capture<Double> captured) {
+// reportMatcher(new Captures<Double>(captured));
+// return 0;
+// }
+
+ /**
+ * Expect any byte but captures it for later use.
+ *
+ * @param captured Where the parameter is captured
+ * @return <code>0</code>
+ */
+// public static byte capture(Capture<Byte> captured) {
+// reportMatcher(new Captures<Byte>(captured));
+// return 0;
+// }
+
+ /**
+ * Expect any char but captures it for later use.
+ *
+ * @param captured Where the parameter is captured
+ * @return <code>0</code>
+ */
+// public static char capture(Capture<Character> captured) {
+// reportMatcher(new Captures<Character>(captured));
+// return 0;
+// }
+
+ /********** END ANDROID CHANGE **********/
+
+ /**
+ * Switches the given mock objects (more exactly: the controls of the mock
+ * objects) to replay mode. For details, see the EasyMock documentation.
+ *
+ * @param mocks
+ * the mock objects.
+ */
+ public static void replay(Object... mocks) {
+ for (Object mock : mocks) {
+ getControl(mock).replay();
+ }
+ }
+
+ /**
+ * Resets the given mock objects (more exactly: the controls of the mock
+ * objects). For details, see the EasyMock documentation.
+ *
+ * @param mocks
+ * the mock objects.
+ */
+ public static void reset(Object... mocks) {
+ for (Object mock : mocks) {
+ getControl(mock).reset();
+ }
+ }
+
+ /**
+ * Resets the given mock objects (more exactly: the controls of the mock
+ * objects) and turn them to a mock with nice behavior. For details, see
+ * the EasyMock documentation.
+ *
+ * @param mocks
+ * the mock objects
+ */
+ public static void resetToNice(Object... mocks) {
+ for (Object mock : mocks) {
+ getControl(mock).resetToNice();
+ }
+ }
+
+ /**
+ * Resets the given mock objects (more exactly: the controls of the mock
+ * objects) and turn them to a mock with default behavior. For details, see
+ * the EasyMock documentation.
+ *
+ * @param mocks
+ * the mock objects
+ */
+ public static void resetToDefault(Object... mocks) {
+ for (Object mock : mocks) {
+ getControl(mock).resetToDefault();
+ }
+ }
+
+ /**
+ * Resets the given mock objects (more exactly: the controls of the mock
+ * objects) and turn them to a mock with strict behavior. For details, see
+ * the EasyMock documentation.
+ *
+ * @param mocks
+ * the mock objects
+ */
+ public static void resetToStrict(Object... mocks) {
+ for (Object mock : mocks) {
+ getControl(mock).resetToStrict();
+ }
+ }
+
+ /**
+ * Verifies the given mock objects (more exactly: the controls of the mock
+ * objects).
+ *
+ * @param mocks
+ * the mock objects.
+ */
+ public static void verify(Object... mocks) {
+ for (Object mock : mocks) {
+ getControl(mock).verify();
+ }
+ }
+
+ /**
+ * Switches order checking of the given mock object (more exactly: the
+ * control of the mock object) the on and off. For details, see the EasyMock
+ * documentation.
+ *
+ * @param mock
+ * the mock object.
+ * @param state
+ * <code>true</code> switches order checking on,
+ * <code>false</code> switches it off.
+ */
+ public static void checkOrder(Object mock, boolean state) {
+ getControl(mock).checkOrder(state);
+ }
+
+ /**
+ * Reports an argument matcher. This method is needed to define own argument
+ * matchers. For details, see the EasyMock documentation.
+ *
+ * @param matcher
+ */
+ public static void reportMatcher(IArgumentMatcher matcher) {
+ LastControl.reportMatcher(matcher);
+ }
+
+ private static MocksControl getControl(Object mock) {
+ return ((ObjectMethodsFilter) Proxy
+ .getInvocationHandler(mock)).getDelegate().getControl();
+ }
+
+ /**
+ * Returns the arguments of the current mock method call, if inside an
+ * <code>IAnswer</code> callback - be careful here, reordering parameters of
+ * method changes the semantics of your tests.
+ *
+ * @return the arguments of the current mock method call.
+ * @throws IllegalStateException
+ * if called outside of <code>IAnswer</code> callbacks.
+ */
+ public static Object[] getCurrentArguments() {
+ Invocation result = LastControl.getCurrentInvocation();
+ if (result == null) {
+ throw new IllegalStateException(
+ "current arguments are only available when executing callback methods");
+ }
+ return result.getArguments();
+ }
+
+ /**
+ * By default, a mock is thread safe (unless
+ * {@link #NOT_THREAD_SAFE_BY_DEFAULT} is set). This method can change this
+ * behavior. Two reasons are known for someone to do that: Performance or
+ * dead-locking issues.
+ *
+ * @param mock
+ * the mock to make thread safe
+ * @param threadSafe
+ * If the mock should be thread safe or not
+ */
+ public static void makeThreadSafe(Object mock, boolean threadSafe) {
+ getControl(mock).makeThreadSafe(threadSafe);
+ }
+
+ /**
+ * Tell that the mock should be used in only one thread. An exception will
+ * be thrown if that's not the case. This can be useful when mocking an
+ * object that isn't thread safe to make sure it is used correctly in a
+ * multithreaded environment. By default, no check is done unless
+ * {@link #ENABLE_THREAD_SAFETY_CHECK_BY_DEFAULT} was set to true.
+ *
+ * @param mock
+ * the mock
+ * @param shouldBeUsedInOneThread
+ * If the mock should be used in only one thread
+ */
+ public static void checkIsUsedInOneThread(Object mock,
+ boolean shouldBeUsedInOneThread) {
+ getControl(mock).checkIsUsedInOneThread(shouldBeUsedInOneThread);
+ }
+
+ /**
+ * Get the current value for an EasyMock property
+ *
+ * @param key
+ * key for the property
+ * @return the property value
+ */
+ public static String getEasyMockProperty(String key) {
+ return EasyMockProperties.getInstance().getProperty(key);
+ }
+
+ /**
+ * Set a property to modify the default EasyMock behavior. These properties
+ * can also be set as System properties or in easymock.properties. This
+ * method can then be called to overload them. For details and a list of
+ * available properties see the EasyMock documentation.
+ * <p>
+ * <b>Note:</b> This method is static. Setting a property will change the
+ * entire EasyMock behavior.
+ *
+ * @param key
+ * property key
+ * @param value
+ * property value. A null value will remove the property
+ * @return the previous property value
+ */
+ public static String setEasyMockProperty(String key, String value) {
+ return EasyMockProperties.getInstance().setProperty(key, value);
+ }
+
+ // ///CLOVER:OFF
+ /** Prevent instantiation but allow inheritance */
+ protected EasyMock() {
+ }
+ // ///CLOVER:ON
+}
diff --git a/src/org/easymock/EasyMockSupport.java b/src/org/easymock/EasyMockSupport.java
new file mode 100644
index 0000000..e111fe9
--- /dev/null
+++ b/src/org/easymock/EasyMockSupport.java
@@ -0,0 +1,236 @@
+/*
+ * Copyright 2003-2009 OFFIS, Henri Tremblay
+ *
+ * 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 org.easymock;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Helper class to be used to keep tracks of mocks easily. See EasyMock
+ * documentation and SupportTest sample
+ */
+public class EasyMockSupport {
+
+ /** List of all controls created */
+ protected final List<IMocksControl> controls = new ArrayList<IMocksControl>(
+ 5);
+
+ /**
+ * Creates a mock object that implements the given interface, order checking
+ * is enabled by default.
+ *
+ * @param <T>
+ * the interface that the mock object should implement.
+ * @param toMock
+ * the class of the interface that the mock object should
+ * implement.
+ * @return the mock object.
+ */
+ public <T> T createStrictMock(Class<T> toMock) {
+ return createStrictControl().createMock(toMock);
+ }
+
+ /**
+ * Creates a mock object that implements the given interface, order checking
+ * is enabled by default.
+ *
+ * @param name
+ * the name of the mock object.
+ * @param toMock
+ * the class of the interface that the mock object should
+ * implement.
+ * @param <T>
+ * the interface that the mock object should implement.
+ * @return the mock object.
+ * @throws IllegalArgumentException
+ * if the name is not a valid Java identifier.
+ */
+ public <T> T createStrictMock(String name, Class<T> toMock) {
+ return createStrictControl().createMock(name, toMock);
+ }
+
+ /**
+ * Creates a mock object that implements the given interface, order checking
+ * is disabled by default.
+ *
+ * @param <T>
+ * the interface that the mock object should implement.
+ * @param toMock
+ * the class of the interface that the mock object should
+ * implement.
+ * @return the mock object.
+ */
+ public <T> T createMock(Class<T> toMock) {
+ return createControl().createMock(toMock);
+ }
+
+ /**
+ * Creates a mock object that implements the given interface, order checking
+ * is disabled by default.
+ *
+ * @param name
+ * the name of the mock object.
+ * @param toMock
+ * the class of the interface that the mock object should
+ * implement.
+ *
+ * @param <T>
+ * the interface that the mock object should implement.
+ * @return the mock object.
+ * @throws IllegalArgumentException
+ * if the name is not a valid Java identifier.
+ */
+ public <T> T createMock(String name, Class<T> toMock) {
+ return createControl().createMock(name, toMock);
+ }
+
+ /**
+ * Creates a mock object that implements the given interface, order checking
+ * is disabled by default, and the mock object will return <code>0</code>,
+ * <code>null</code> or <code>false</code> for unexpected invocations.
+ *
+ * @param <T>
+ * the interface that the mock object should implement.
+ * @param toMock
+ * the class of the interface that the mock object should
+ * implement.
+ * @return the mock object.
+ */
+ public <T> T createNiceMock(Class<T> toMock) {
+ return createNiceControl().createMock(toMock);
+ }
+
+ /**
+ * Creates a mock object that implements the given interface, order checking
+ * is disabled by default, and the mock object will return <code>0</code>,
+ * <code>null</code> or <code>false</code> for unexpected invocations.
+ *
+ * @param name
+ * the name of the mock object.
+ * @param toMock
+ * the class of the interface that the mock object should
+ * implement.
+ *
+ * @param <T>
+ * the interface that the mock object should implement.
+ * @return the mock object.
+ * @throws IllegalArgumentException
+ * if the name is not a valid Java identifier.
+ */
+ public <T> T createNiceMock(String name, Class<T> toMock) {
+ return createNiceControl().createMock(name, toMock);
+ }
+
+ /**
+ * Creates a control, order checking is enabled by default.
+ *
+ * @return the control.
+ */
+ public IMocksControl createStrictControl() {
+ IMocksControl ctrl = EasyMock.createStrictControl();
+ controls.add(ctrl);
+ return ctrl;
+ }
+
+ /**
+ * Creates a control, order checking is disabled by default.
+ *
+ * @return the control.
+ */
+ public IMocksControl createControl() {
+ IMocksControl ctrl = EasyMock.createControl();
+ controls.add(ctrl);
+ return ctrl;
+ }
+
+ /**
+ * Creates a control, order checking is disabled by default, and the mock
+ * objects created by this control will return <code>0</code>,
+ * <code>null</code> or <code>false</code> for unexpected invocations.
+ *
+ * @return the control.
+ */
+ public IMocksControl createNiceControl() {
+ IMocksControl ctrl = EasyMock.createNiceControl();
+ controls.add(ctrl);
+ return ctrl;
+ }
+
+ /**
+ * Switches all registered mock objects (more exactly: the controls of the
+ * mock objects) to replay mode. For details, see the EasyMock
+ * documentation.
+ */
+ public void replayAll() {
+ for (IMocksControl c : controls) {
+ c.replay();
+ }
+ }
+
+ /**
+ * Resets all registered mock objects (more exactly: the controls of the
+ * mock objects). For details, see the EasyMock documentation.
+ */
+ public void resetAll() {
+ for (IMocksControl c : controls) {
+ c.reset();
+ }
+ }
+
+ /**
+ * Verifies all registered mock objects (more exactly: the controls of the
+ * mock objects).
+ */
+ public void verifyAll() {
+ for (IMocksControl c : controls) {
+ c.verify();
+ }
+ }
+
+ /**
+ * Resets all registered mock objects (more exactly: the controls of the
+ * mock objects) and turn them to a mock with nice behavior. For details,
+ * see the EasyMock documentation.
+ */
+ public void resetAllToNice() {
+ for (IMocksControl c : controls) {
+ c.resetToNice();
+ }
+ }
+
+ /**
+ * Resets all registered mock objects (more exactly: the controls of the
+ * mock objects) and turn them to a mock with default behavior. For details,
+ * see the EasyMock documentation.
+ */
+ public void resetAllToDefault() {
+ for (IMocksControl c : controls) {
+ c.resetToDefault();
+ }
+ }
+
+ /**
+ * Resets all registered mock objects (more exactly: the controls of the
+ * mock objects) and turn them to a mock with strict behavior. For details,
+ * see the EasyMock documentation.
+ */
+ public void resetAllToStrict() {
+ for (IMocksControl c : controls) {
+ c.resetToStrict();
+ }
+ }
+
+}
diff --git a/src/org/easymock/IAnswer.java b/src/org/easymock/IAnswer.java
new file mode 100644
index 0000000..5560902
--- /dev/null
+++ b/src/org/easymock/IAnswer.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock;
+
+/**
+ * Used to answer expected calls.
+ * @param <T> the type to return.
+ */
+public interface IAnswer<T> {
+ /**
+ * is called by EasyMock to answer an expected call.
+ * The answer may be to return a value, or to throw an exception.
+ * The arguments of the call for which the answer is generated
+ * are available via {@link EasyMock#getCurrentArguments()} - be careful
+ * here, using the arguments is not refactoring-safe.
+ *
+ * @return the value to be returned
+ * @throws Throwable the throwable to be thrown
+ */
+ T answer() throws Throwable;
+}
diff --git a/src/org/easymock/IArgumentMatcher.java b/src/org/easymock/IArgumentMatcher.java
new file mode 100644
index 0000000..4e0af17
--- /dev/null
+++ b/src/org/easymock/IArgumentMatcher.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2001-2006 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock;
+
+/**
+ * Decides whether an actual argument is accepted.
+ */
+public interface IArgumentMatcher {
+
+ /**
+ * Returns whether this matcher accepts the given argument.
+ * <p>
+ * Like Object.equals(), it should be aware that the argument passed might
+ * be null and of any type. So you will usually start the method with an
+ * instanceof and/or null check.
+ * <p>
+ * The method should <b>never</b> assert if the argument doesn't match. It
+ * should only return false. EasyMock will take care of asserting if the
+ * call is really unexpected.
+ *
+ * @param argument the argument
+ * @return whether this matcher accepts the given argument.
+ */
+ boolean matches(Object argument);
+
+ /**
+ * Appends a string representation of this matcher to the given buffer. In case
+ * of failure, the printed message will show this string to allow to know which
+ * matcher was used for the failing call.
+ *
+ * @param buffer the buffer to which the string representation is appended.
+ */
+ void appendTo(StringBuffer buffer);
+}
diff --git a/src/org/easymock/IExpectationSetters.java b/src/org/easymock/IExpectationSetters.java
new file mode 100644
index 0000000..c9d1894
--- /dev/null
+++ b/src/org/easymock/IExpectationSetters.java
@@ -0,0 +1,151 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock;
+
+/**
+ * Allows setting expectations for an associated expected invocation.
+ * Implementations of this interface are returned by
+ * {@link EasyMock#expect(Object)}, and by {@link EasyMock#expectLastCall()}.
+ *
+ * @param <T> type of what should be returned by this expected call
+ */
+public interface IExpectationSetters<T> {
+
+ /**
+ * Sets a return value that will be returned for the expected invocation.
+ *
+ * @param value
+ * the value to return.
+ * @return this object to allow method call chaining.
+ */
+ IExpectationSetters<T> andReturn(T value);
+
+ /**
+ * Sets a throwable that will be thrown for the expected invocation.
+ *
+ * @param throwable
+ * the throwable to throw.
+ * @return this object to allow method call chaining.
+ */
+ IExpectationSetters<T> andThrow(Throwable throwable);
+
+ /**
+ * Sets an object that will be used to calculate the answer for the expected
+ * invocation (either return a value, or throw an exception).
+ *
+ * @param answer
+ * the object used to answer the invocation.
+ * @return this object to allow method call chaining.
+ */
+ IExpectationSetters<T> andAnswer(IAnswer<? extends T> answer);
+
+ /**
+ * Sets an object implementing the same interface as the mock. The expected
+ * method call will be delegated to it with the actual arguments. The answer
+ * returned by this call will then be the answer returned by the mock
+ * (either return a value, or throw an exception).
+ *
+ * @param delegateTo
+ * the object the call is delegated to.
+ * @return the value returned by the delegated call.
+ */
+ IExpectationSetters<T> andDelegateTo(Object delegateTo);
+
+ /**
+ * Sets a stub return value that will be returned for the expected
+ * invocation.
+ *
+ * @param value
+ * the value to return.
+ */
+ void andStubReturn(T value);
+
+ /**
+ * Sets a stub throwable that will be thrown for the expected invocation.
+ *
+ * @param throwable
+ * the throwable to throw.
+ */
+ void andStubThrow(Throwable throwable);
+
+ /**
+ * Sets a stub object that will be used to calculate the answer for the
+ * expected invocation (either return a value, or throw an exception).
+ *
+ * @param answer
+ * the object used to answer the invocation.
+ */
+ void andStubAnswer(IAnswer<? extends T> answer);
+
+ /**
+ * Sets a stub object implementing the same interface as the mock. The
+ * expected method call will be delegated to it with the actual arguments.
+ * The answer returned by this call will then be the answer returned by the
+ * mock (either return a value, or throw an exception).
+ *
+ * @param delegateTo
+ * the object the call is delegated to.
+ */
+ void andStubDelegateTo(Object delegateTo);
+
+ /**
+ * Sets stub behavior for the expected invocation (this is needed for void
+ * methods).
+ */
+ void asStub();
+
+ /**
+ * Expect the last invocation <code>count</code> times.
+ *
+ * @param count
+ * the number of invocations expected.
+ * @return this object to allow method call chaining.
+ */
+ IExpectationSetters<T> times(int count);
+
+ /**
+ * Expect the last invocation between <code>min</code> and
+ * <code>max</code> times.
+ *
+ * @param min
+ * the minimum number of invocations expected.
+ * @param max
+ * the maximum number of invocations expected.
+ * @return this object to allow method call chaining.
+ */
+ IExpectationSetters<T> times(int min, int max);
+
+ /**
+ * Expect the last invocation once. This is default in EasyMock.
+ *
+ * @return this object to allow method call chaining.
+ */
+ IExpectationSetters<T> once();
+
+ /**
+ * Expect the last invocation at least once.
+ *
+ * @return this object to allow method call chaining.
+ */
+ IExpectationSetters<T> atLeastOnce();
+
+ /**
+ * Expect the last invocation any times.
+ *
+ * @return this object to allow method call chaining.
+ */
+ IExpectationSetters<T> anyTimes();
+}
diff --git a/src/org/easymock/IMocksControl.java b/src/org/easymock/IMocksControl.java
new file mode 100644
index 0000000..a1783fc
--- /dev/null
+++ b/src/org/easymock/IMocksControl.java
@@ -0,0 +1,94 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock;
+
+/**
+ * Controls all the mock objects created by it.
+ * For details, see the EasyMock documentation.
+ */
+public interface IMocksControl {
+ /**
+ * Creates a mock object that implements the given interface.
+ * @param <T> the interface that the mock object should implement.
+ * @param toMock the class of the interface that the mock object should implement.
+ * @return the mock object.
+ */
+ <T> T createMock(Class<T> toMock);
+
+ /**
+ * Creates a mock object that implements the given interface.
+ * @param name the name of the mock object .
+ * @param toMock the class of the interface that the mock object should implement.
+ * @param <T> the interface that the mock object should implement.
+ * @return the mock object.
+ * @throws IllegalArgumentException if the name is not a valid Java identifier.
+ */
+ <T> T createMock(String name, Class<T> toMock);
+
+ /**
+ * Removes all expectations for the mock objects of this control.
+ */
+ void reset();
+
+ /**
+ * Removes all expectations for the mock objects of this control and turn
+ * them to nice mocks.
+ */
+ void resetToNice();
+
+ /**
+ * Removes all expectations for the mock objects of this control and turn
+ * them to default mocks.
+ */
+ void resetToDefault();
+
+ /**
+ * Removes all expectations for the mock objects of this control and turn
+ * them to strict mocks.
+ */
+ void resetToStrict();
+
+ /**
+ * Switches the control from record mode to replay mode.
+ */
+ void replay();
+
+ /**
+ * Verifies that all expectations were met.
+ */
+ void verify();
+
+ /**
+ * Switches order checking on and off.
+ * @param state <code>true</code> switches order checking on, <code>false</code> switches it off.
+ */
+ void checkOrder(boolean state);
+
+ /**
+ * Makes the mock thread safe.
+ *
+ * @param threadSafe If the mock should be thread safe or not
+ */
+ void makeThreadSafe(boolean threadSafe);
+
+ /**
+ * Check that the mock is called from only one thread
+ *
+ * @param shouldBeUsedInOneThread
+ * If it should be used in one thread only or not
+ */
+ void checkIsUsedInOneThread(boolean shouldBeUsedInOneThread);
+}
diff --git a/src/org/easymock/LogicalOperator.java b/src/org/easymock/LogicalOperator.java
new file mode 100644
index 0000000..2c41434
--- /dev/null
+++ b/src/org/easymock/LogicalOperator.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2001-2009 OFFIS, Henri Tremblay
+ *
+ * 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 org.easymock;
+
+/**
+ * See {@link EasyMock#cmp}
+ */
+public enum LogicalOperator {
+ LESS_THAN("<") {
+ public boolean matchResult(int result) {
+ return result < 0;
+ }
+ },
+ LESS_OR_EQUAL("<=") {
+ public boolean matchResult(int result) {
+ return result <= 0;
+ }
+ },
+ EQUAL("==") {
+ public boolean matchResult(int result) {
+ return result == 0;
+ }
+ },
+ GREATER_OR_EQUAL(">=") {
+ public boolean matchResult(int result) {
+ return result >= 0;
+ }
+ },
+ GREATER(">") {
+ public boolean matchResult(int result) {
+ return result > 0;
+ }
+ };
+
+ private String symbol;
+
+ private LogicalOperator(String symbol) {
+ this.symbol = symbol;
+ }
+
+ public String getSymbol() {
+ return symbol;
+ }
+
+ public abstract boolean matchResult(int result);
+}
diff --git a/src/org/easymock/MockControl.java b/src/org/easymock/MockControl.java
new file mode 100644
index 0000000..601a6b4
--- /dev/null
+++ b/src/org/easymock/MockControl.java
@@ -0,0 +1,649 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock;
+
+import static org.easymock.EasyMock.*;
+
+import java.io.Serializable;
+
+import org.easymock.internal.*;
+
+/**
+ * A <code>MockControl</code> object controls the behavior of its associated
+ * mock object. For more information, see the EasyMock documentation.
+ *
+ * @param <T> type of the mock controlled
+ *
+ * @deprecated Since EasyMock 2.0, static methods on <code>EasyMock</code> are
+ * used to create and control mock objects.
+ */
+@Deprecated
+public class MockControl<T> implements Serializable {
+
+ private static final long serialVersionUID = 8741244302173698092L;
+
+ private final T mock;
+
+ private final MocksControl ctrl;
+
+ protected MockControl(MocksControl ctrl, Class<T> toMock) {
+ this.ctrl = ctrl;
+ this.mock = ctrl.createMock(toMock);
+ }
+
+ /**
+ * Creates a mock control object for the specified interface. The
+ * <code>MockControl</code> and its associated mock object will not check
+ * the order of expected method calls. An unexpected method call on the mock
+ * object will lead to an <code>AssertionError</code>.
+ *
+ * @param <T> type of the mock controlled
+ * @param toMock
+ * the class of the interface to mock.
+ * @return the mock control.
+ */
+ public static <T> MockControl<T> createControl(Class<T> toMock) {
+ return new MockControl<T>((MocksControl) EasyMock.createControl(),
+ toMock);
+ }
+
+ /**
+ * Creates a mock control object for the specified interface. The
+ * <code>MockControl</code> and its associated mock object will check the
+ * order of expected method calls. An unexpected method call on the mock
+ * object will lead to an <code>AssertionError</code>.
+ *
+ * @param <T> type of the mock controlled
+ * @param toMock
+ * the class of the interface to mock.
+ * @return the mock control.
+ */
+ public static <T> MockControl<T> createStrictControl(Class<T> toMock) {
+ return new MockControl<T>(
+ (MocksControl) EasyMock.createStrictControl(), toMock);
+ }
+
+ /**
+ * Creates a mock control object for the specified interface. The
+ * <code>MockControl</code> and its associated mock object will not check
+ * the order of expected method calls. An unexpected method call on the mock
+ * object will return an empty value (0, null, false).
+ *
+ * @param <T> type of the mock controlled
+ * @param toMock
+ * the class of the interface to mock.
+ * @return the mock control.
+ */
+ public static <T> MockControl<T> createNiceControl(Class<T> toMock) {
+ return new MockControl<T>((MocksControl) EasyMock.createNiceControl(),
+ toMock);
+ }
+
+ /**
+ * Returns the mock object.
+ *
+ * @return the mock object of this control
+ */
+ public T getMock() {
+ return mock;
+ }
+
+ /**
+ * Resets the mock control and the mock object to the state directly after
+ * creation.
+ */
+ public final void reset() {
+ ctrl.reset();
+ }
+
+ /**
+ * Switches the mock object from record state to replay state. For more
+ * information, see the EasyMock documentation.
+ *
+ * @throws IllegalStateException
+ * if the mock object already is in replay state.
+ */
+ public void replay() {
+ ctrl.replay();
+ }
+
+ /**
+ * Verifies that all expectations have been met. For more information, see
+ * the EasyMock documentation.
+ *
+ * @throws IllegalStateException
+ * if the mock object is in record state.
+ * @throws AssertionError
+ * if any expectation has not been met.
+ */
+ public void verify() {
+ ctrl.verify();
+ }
+
+ /**
+ * Records that the mock object will expect the last method call once, and
+ * will react by returning silently.
+ *
+ * @exception IllegalStateException
+ * if the mock object is in replay state, if no method was
+ * called on the mock object before, or if the last method
+ * called on the mock was no void method.
+ */
+ public void setVoidCallable() {
+ expectLastCall(
+ "method call on the mock needed before setting void callable")
+ .once();
+ }
+
+ /**
+ * Records that the mock object will expect the last method call once, and
+ * will react by throwing the provided Throwable.
+ *
+ * @param throwable
+ * the Throwable to throw.
+ * @exception IllegalStateException
+ * if the mock object is in replay state or if no method was
+ * called on the mock object before.
+ * @exception IllegalArgumentException
+ * if the last method called on the mock cannot throw the
+ * provided Throwable.
+ * @exception NullPointerException
+ * if throwable is null.
+ */
+ public void setThrowable(Throwable throwable) {
+ expectLastCall(
+ "method call on the mock needed before setting Throwable")
+ .andThrow(throwable).once();
+ }
+
+ /**
+ * Records that the mock object will expect the last method call once, and
+ * will react by returning the provided return value.
+ *
+ * @param value
+ * the return value.
+ * @throws IllegalStateException
+ * if the mock object is in replay state, if no method was
+ * called on the mock object before. or if the last method
+ * called on the mock does not return <code>boolean</code>.
+ */
+ public void setReturnValue(Object value) {
+ expectLastCall(
+ "method call on the mock needed before setting return value")
+ .andReturn(value).once();
+ }
+
+ /**
+ * Records that the mock object will expect the last method call a fixed
+ * number of times, and will react by returning silently.
+ *
+ * @param times
+ * the number of times that the call is expected.
+ * @exception IllegalStateException
+ * if the mock object is in replay state, if no method was
+ * called on the mock object before, or if the last method
+ * called on the mock was no void method.
+ */
+ public void setVoidCallable(int times) {
+ expectLastCall(
+ "method call on the mock needed before setting void callable")
+ .times(times);
+ }
+
+ /**
+ * Records that the mock object will expect the last method call a fixed
+ * number of times, and will react by throwing the provided Throwable.
+ *
+ * @param throwable
+ * the Throwable to throw.
+ * @param times
+ * the number of times that the call is expected.
+ * @exception IllegalStateException
+ * if the mock object is in replay state or if no method was
+ * called on the mock object before.
+ * @exception IllegalArgumentException
+ * if the last method called on the mock cannot throw the
+ * provided Throwable.
+ * @exception NullPointerException
+ * if throwable is null.
+ */
+ public void setThrowable(Throwable throwable, int times) {
+ expectLastCall(
+ "method call on the mock needed before setting Throwable")
+ .andThrow(throwable).times(times);
+ }
+
+ /**
+ * Records that the mock object will expect the last method call a fixed
+ * number of times, and will react by returning the provided return value.
+ *
+ * @param value
+ * the return value.
+ * @param times
+ * the number of times that the call is expected.
+ * @throws IllegalStateException
+ * if the mock object is in replay state, if no method was
+ * called on the mock object before. or if the last method
+ * called on the mock does not return <code>boolean</code>.
+ */
+ public void setReturnValue(Object value, int times) {
+ expectLastCall(
+ "method call on the mock needed before setting return value")
+ .andReturn(value).times(times);
+ }
+
+ /**
+ * Records that the mock object will expect the last method call a fixed
+ * number of times, and will react by returning the provided return value.
+ *
+ * @param value
+ * the return value.
+ * @param range
+ * the number of times that the call is expected.
+ * @throws IllegalStateException
+ * if the mock object is in replay state, if no method was
+ * called on the mock object before. or if the last method
+ * called on the mock does not return <code>boolean</code>.
+ */
+ public void setReturnValue(Object value, Range range) {
+ IExpectationSetters<Object> setter = expectLastCall(
+ "method call on the mock needed before setting return value")
+ .andReturn(value);
+ callWithConvertedRange(setter, range);
+ }
+
+ /**
+ * Records that the mock object will by default allow the last method
+ * specified by a method call.
+ *
+ * @exception IllegalStateException
+ * if the mock object is in replay state, if no method was
+ * called on the mock object before, or if the last method
+ * called on the mock was no void method.
+ */
+ public void setDefaultVoidCallable() {
+ ((MocksControl) expectLastCall("method call on the mock needed before setting default void callable"))
+ .setLegacyDefaultVoidCallable();
+ }
+
+ /**
+ * Records that the mock object will by default allow the last method
+ * specified by a method call, and will react by throwing the provided
+ * Throwable.
+ *
+ * @param throwable
+ * throwable the throwable to be thrown
+ * @exception IllegalArgumentException
+ * if the last method called on the mock cannot throw the
+ * provided Throwable.
+ * @exception NullPointerException
+ * if throwable is null.
+ * @exception IllegalStateException
+ * if the mock object is in replay state, or if no method was
+ * called on the mock object before.
+ */
+ public void setDefaultThrowable(Throwable throwable) {
+ ctrl.setLegacyDefaultThrowable(throwable);
+ }
+
+ /**
+ * Records that the mock object will by default allow the last method
+ * specified by a method call, and will react by returning the provided
+ * return value.
+ *
+ * @param value
+ * the return value.
+ * @throws IllegalStateException
+ * if the mock object is in replay state, if no method was
+ * called on the mock object before. or if the last method
+ * called on the mock does not return <code>boolean</code>.
+ */
+ public void setDefaultReturnValue(Object value) {
+ ctrl.setLegacyDefaultReturnValue(value);
+ }
+
+ /**
+ * Sets the ArgumentsMatcher for the last method called on the mock object.
+ * The matcher must be set before any behavior for the method is defined.
+ *
+ * @param matcher the matcher for the last method called
+ * @throws IllegalStateException
+ * if called in replay state, or if no method was called on the
+ * mock object before.
+ */
+ public void setMatcher(ArgumentsMatcher matcher) {
+ ctrl.setLegacyMatcher(matcher);
+ }
+
+ /**
+ * Records that the mock object will expect the last method call between
+ * <code>minCount</code> and <code>maxCount</code> times, and will react
+ * by returning silently.
+ *
+ * @param minCount
+ * the minimum number of times that the call is expected.
+ * @param maxCount
+ * the maximum number of times that the call is expected.
+ * @exception IllegalStateException
+ * if the mock object is in replay state, if no method was
+ * called on the mock object before, or if the last method
+ * called on the mock was no void method.
+ */
+ public void setVoidCallable(int minCount, int maxCount) {
+ expectLastCall(
+ "method call on the mock needed before setting void callable")
+ .times(minCount, maxCount);
+ }
+
+ public void setVoidCallable(Range range) {
+ IExpectationSetters<Object> setter = expectLastCall("method call on the mock needed before setting void callable");
+ callWithConvertedRange(setter, range);
+ }
+
+ /**
+ * Records that the mock object will expect the last method call between
+ * <code>minCount</code> and <code>maxCount</code> times, and will react
+ * by throwing the provided Throwable.
+ *
+ * @param throwable
+ * the Throwable to throw.
+ * @param minCount
+ * the minimum number of times that the call is expected.
+ * @param maxCount
+ * the maximum number of times that the call is expected.
+ * @exception IllegalStateException
+ * if the mock object is in replay state or if no method was
+ * called on the mock object before.
+ * @exception IllegalArgumentException
+ * if the last method called on the mock cannot throw the
+ * provided Throwable.
+ * @exception NullPointerException
+ * if throwable is null.
+ */
+ public void setThrowable(Throwable throwable, int minCount, int maxCount) {
+ expectLastCall(
+ "method call on the mock needed before setting Throwable")
+ .andThrow(throwable).times(minCount, maxCount);
+ }
+
+ public void setThrowable(Throwable throwable, Range range) {
+ IExpectationSetters<Object> setter = expectLastCall(
+ "method call on the mock needed before setting Throwable")
+ .andThrow(throwable);
+ callWithConvertedRange(setter, range);
+ }
+
+ /**
+ * Records that the mock object will expect the last method call between
+ * <code>minCount</code> and <code>maxCount</code> times, and will react
+ * by returning the provided return value.
+ *
+ * @param value
+ * the return value.
+ * @param minCount
+ * the minimum number of times that the call is expected.
+ * @param maxCount
+ * the maximum number of times that the call is expected.
+ * @throws IllegalStateException
+ * if the mock object is in replay state, if no method was
+ * called on the mock object before. or if the last method
+ * called on the mock does not return <code>boolean</code>.
+ */
+ public void setReturnValue(Object value, int minCount, int maxCount) {
+ expectLastCall(
+ "method call on the mock needed before setting return value")
+ .andReturn(value).times(minCount, maxCount);
+ }
+
+ /**
+ * Exactly one call.
+ */
+ public static final Range ONE = MocksControl.ONCE;
+
+ /**
+ * One or more calls.
+ */
+ public static final Range ONE_OR_MORE = MocksControl.AT_LEAST_ONCE;
+
+ /**
+ * Zero or more calls.
+ */
+ public static final Range ZERO_OR_MORE = MocksControl.ZERO_OR_MORE;
+
+ /**
+ * Matches if each expected argument is equal to the corresponding actual
+ * argument.
+ */
+ public static final ArgumentsMatcher EQUALS_MATCHER = new EqualsMatcher();
+
+ /**
+ * Matches always.
+ */
+ public static final ArgumentsMatcher ALWAYS_MATCHER = new AlwaysMatcher();
+
+ /**
+ * Matches if each expected argument is equal to the corresponding actual
+ * argument for non-array arguments; array arguments are compared with the
+ * appropriate <code>java.util.Arrays.equals()</code> -method.
+ */
+ public static final ArgumentsMatcher ARRAY_MATCHER = new ArrayMatcher();
+
+ /**
+ * Sets the default ArgumentsMatcher for all methods of the mock object. The
+ * matcher must be set before any behavior is defined on the mock object.
+ *
+ * @param matcher the default matcher for this control
+ * @throws IllegalStateException
+ * if called in replay state, or if any behavior is already
+ * defined on the mock object.
+ */
+ public void setDefaultMatcher(ArgumentsMatcher matcher) {
+ ctrl.setLegacyDefaultMatcher(matcher);
+ }
+
+ /**
+ * Same as {@link MockControl#setReturnValue(Object)}. For explanation, see
+ * "Convenience Methods for Return Values" in the EasyMock documentation.
+ *
+ * @param <V1> mocked method return type
+ * @param <V2> returned value type
+ * @param ignored
+ * an ignored value.
+ * @param value value returned by the mock
+ */
+ public <V1, V2 extends V1> void expectAndReturn(V1 ignored, V2 value) {
+ EasyMock.expectLastCall().andReturn(value).once();
+ }
+
+ public void expectAndReturn(int ignored, int value) {
+ this.expectAndReturn((Object) ignored, (Object) value);
+ }
+
+ /**
+ * Same as {@link MockControl#setReturnValue(Object, Range)}. For
+ * explanation, see "Convenience Methods for Return Values" in the EasyMock
+ * documentation.
+ *
+ * @param <V1> mocked method return type
+ * @param <V2> returned value type
+ * @param ignored
+ * an ignored value.
+ * @param value value returned by the mock
+ * @param range range of number of calls
+ */
+ public <V1, V2 extends V1> void expectAndReturn(V1 ignored, V2 value,
+ Range range) {
+ IExpectationSetters<Object> expectAndReturn = EasyMock.expectLastCall()
+ .andReturn(value);
+ callWithConvertedRange(expectAndReturn, range);
+ }
+
+ public void expectAndReturn(int ignored, int value, Range range) {
+ this.expectAndReturn((Object) ignored, (Object) value, range);
+ }
+
+ /**
+ * Same as {@link MockControl#setReturnValue(Object, int)}. For
+ * explanation, see "Convenience Methods for Return Values" in the EasyMock
+ * documentation.
+ *
+ * @param <V1> mocked method return type
+ * @param <V2> returned value type
+ * @param ignored
+ * an ignored value.
+ * @param value value returned by the mock
+ * @param count number of times the call is expected
+ */
+ public <V1, V2 extends V1> void expectAndReturn(V1 ignored, V2 value,
+ int count) {
+ EasyMock.expectLastCall().andReturn(value).times(count);
+ }
+
+ public void expectAndReturn(int ignored, int value, int count) {
+ this.expectAndReturn((Object) ignored, (Object) value, count);
+ }
+
+ /**
+ * Same as {@link MockControl#setReturnValue(Object, int, int)}. For
+ * explanation, see "Convenience Methods for Return Values" in the EasyMock
+ * documentation.
+ *
+ * @param <V1> mocked method return type
+ * @param <V2> returned value type
+ * @param ignored
+ * an ignored value.
+ * @param value value returned by the mock
+ * @param min minimum number of times the call is expected
+ * @param max maximum number of times the call is expected
+ */
+ public <V1, V2 extends V1> void expectAndReturn(V1 ignored, V2 value,
+ int min, int max) {
+ EasyMock.expectLastCall().andReturn(value).times(min, max);
+ }
+
+ public void expectAndReturn(int ignored, int value, int min, int max) {
+ this.expectAndReturn((Object) ignored, (Object) value, min, max);
+ }
+
+ /**
+ * Same as {@link MockControl#setThrowable(Throwable)}. For explanation,
+ * see "Convenience Methods for Throwables" in the EasyMock documentation.
+ *
+ * @param ignored
+ * an ignored value.
+ * @param throwable to be thrown on the call
+ */
+ public void expectAndThrow(Object ignored, Throwable throwable) {
+ EasyMock.expect(ignored).andThrow(throwable).once();
+ }
+
+ /**
+ * Same as {@link MockControl#setThrowable(Throwable, Range)}. For
+ * explanation, see "Convenience Methods for Throwables" in the EasyMock
+ * documentation.
+ *
+ * @param ignored
+ * an ignored value.
+ * @param throwable to be thrown on the call
+ * @param range range of number of calls
+ */
+ public void expectAndThrow(Object ignored, Throwable throwable, Range range) {
+ IExpectationSetters<Object> setter = EasyMock.expect(ignored).andThrow(
+ throwable);
+ callWithConvertedRange(setter, range);
+ }
+
+ /**
+ * Same as {@link MockControl#setThrowable(Throwable, int)}. For
+ * explanation, see "Convenience Methods for Throwables" in the EasyMock
+ * documentation.
+ *
+ * @param ignored
+ * an ignored value.
+ * @param throwable to be thrown on the call
+ * @param count number of times the call is expected
+ */
+ public void expectAndThrow(Object ignored, Throwable throwable, int count) {
+ expect(ignored).andThrow(throwable).times(count);
+ }
+
+ /**
+ * Same as {@link MockControl#setThrowable(Throwable, int, int)}. For
+ * explanation, see "Convenience Methods for Throwables" in the EasyMock
+ * documentation.
+ *
+ * @param ignored
+ * an ignored value.
+ * @param throwable to be thrown on the call
+ * @param min minimum number of times the call is expected
+ * @param max maximum number of times the call is expected
+ */
+ public void expectAndThrow(Object ignored, Throwable throwable, int min,
+ int max) {
+ expect(ignored).andThrow(throwable).times(min, max);
+ }
+
+ /**
+ * Same as {@link MockControl#setDefaultReturnValue(Object)}. For
+ * explanation, see "Convenience Methods for Return Values" in the EasyMock
+ * documentation.
+ *
+ * @param <V1> mocked method return type
+ * @param <V2> returned value type
+ * @param ignored
+ * an ignored value.
+ * @param value value returned by the mock
+ */
+ public <V1, V2 extends V1> void expectAndDefaultReturn(V1 ignored, V2 value) {
+ EasyMock.expectLastCall().andStubReturn(value);
+ }
+
+ /**
+ * Same as {@link MockControl#setDefaultThrowable(Throwable)}. For
+ * explanation, see "Convenience Methods for Throwables" in the EasyMock
+ * documentation.
+ *
+ * @param ignored
+ * an ignored value.
+ * @param throwable to be thrown on the call
+ */
+ public void expectAndDefaultThrow(Object ignored, Throwable throwable) {
+ expectLastCall(
+ "method call on the mock needed before setting default Throwable")
+ .andStubThrow(throwable);
+ }
+
+ private IExpectationSetters<Object> expectLastCall(String failureMessage) {
+ try {
+ return EasyMock.expectLastCall();
+ } catch (IllegalStateException e) {
+ throw new IllegalStateException(failureMessage);
+ }
+ }
+
+ private void callWithConvertedRange(IExpectationSetters<Object> setter, Range range) {
+ if (range == ONE) {
+ setter.once();
+ } else if (range == ONE_OR_MORE) {
+ setter.atLeastOnce();
+ } else if (range == ZERO_OR_MORE) {
+ setter.anyTimes();
+ } else {
+ throw new IllegalArgumentException("Unexpected Range");
+ }
+ }
+
+} \ No newline at end of file
diff --git a/src/org/easymock/internal/AlwaysMatcher.java b/src/org/easymock/internal/AlwaysMatcher.java
new file mode 100644
index 0000000..f301936
--- /dev/null
+++ b/src/org/easymock/internal/AlwaysMatcher.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal;
+
+import org.easymock.AbstractMatcher;
+
+@SuppressWarnings("deprecation")
+public class AlwaysMatcher extends AbstractMatcher {
+
+ private static final long serialVersionUID = 592339838132342008L;
+
+ public boolean matches(Object[] expected, Object[] actual) {
+ return true;
+ }
+
+ protected String argumentToString(Object argument) {
+ return "<any>";
+ }
+} \ No newline at end of file
diff --git a/src/org/easymock/internal/ArgumentToString.java b/src/org/easymock/internal/ArgumentToString.java
new file mode 100644
index 0000000..81d5676
--- /dev/null
+++ b/src/org/easymock/internal/ArgumentToString.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2003-2009 OFFIS, Henri Tremblay
+ *
+ * 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 org.easymock.internal;
+
+import java.lang.reflect.Array;
+
+public final class ArgumentToString {
+
+ // ///CLOVER:OFF
+ private ArgumentToString() {
+ }
+ // ///CLOVER:ON
+
+ public static void appendArgument(Object value, StringBuffer buffer) {
+ if (value == null) {
+ buffer.append("null");
+ } else if (value instanceof String) {
+ buffer.append("\"");
+ buffer.append(value);
+ buffer.append("\"");
+ } else if (value instanceof Character) {
+ buffer.append("'");
+ buffer.append(value);
+ buffer.append("'");
+ } else if (value.getClass().isArray()) {
+ buffer.append("[");
+ for (int i = 0; i < Array.getLength(value); i++) {
+ if (i > 0) {
+ buffer.append(", ");
+ }
+ appendArgument(Array.get(value, i), buffer);
+ }
+ buffer.append("]");
+ } else {
+ buffer.append(value);
+ }
+ }
+}
diff --git a/src/org/easymock/internal/ArrayMatcher.java b/src/org/easymock/internal/ArrayMatcher.java
new file mode 100644
index 0000000..807149f
--- /dev/null
+++ b/src/org/easymock/internal/ArrayMatcher.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal;
+
+import org.easymock.AbstractMatcher;
+import org.easymock.internal.matchers.ArrayEquals;
+
+@SuppressWarnings("deprecation")
+public class ArrayMatcher extends AbstractMatcher {
+
+ private static final long serialVersionUID = -4594659581004800814L;
+
+ @Override
+ public boolean argumentMatches(Object expected, Object actual) {
+ return new ArrayEquals(expected).matches(actual);
+ }
+} \ No newline at end of file
diff --git a/src/org/easymock/internal/AssertionErrorWrapper.java b/src/org/easymock/internal/AssertionErrorWrapper.java
new file mode 100644
index 0000000..d36a3c7
--- /dev/null
+++ b/src/org/easymock/internal/AssertionErrorWrapper.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal;
+
+public class AssertionErrorWrapper extends RuntimeException {
+
+ private static final long serialVersionUID = -2087349195182278608L;
+
+ private final AssertionError error;
+
+ public AssertionErrorWrapper(AssertionError error) {
+ this.error = error;
+ }
+
+ public AssertionError getAssertionError() {
+ return error;
+ }
+}
diff --git a/src/org/easymock/internal/EasyMockProperties.java b/src/org/easymock/internal/EasyMockProperties.java
new file mode 100644
index 0000000..5094104
--- /dev/null
+++ b/src/org/easymock/internal/EasyMockProperties.java
@@ -0,0 +1,146 @@
+/*
+ * Copyright 2003-2009 OFFIS, Henri Tremblay
+ *
+ * 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 org.easymock.internal;
+
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Map;
+import java.util.Properties;
+
+/**
+ * Contains properties used by EasyMock to change its default behavior. The
+ * loading order is (any step being able to overload the properties of the
+ * previous step):
+ * <ul>
+ * <li>easymock.properties in classpath default package</li>
+ * <li>System properties</li>
+ * <li>explicit call to setProperty</li>
+ * </ul>
+ */
+public final class EasyMockProperties {
+
+ private static final String PREFIX = "easymock.";
+
+ // volatile for double-checked locking
+ private static volatile EasyMockProperties instance;
+
+ private final Properties properties = new Properties();
+
+ public static EasyMockProperties getInstance() {
+ if (instance == null) {
+ synchronized (EasyMockProperties.class) {
+ // ///CLOVER:OFF
+ if (instance == null) {
+ // ///CLOVER:ON
+ instance = new EasyMockProperties();
+ }
+ }
+ }
+ return instance;
+ }
+
+ private EasyMockProperties() {
+ // Load the easymock.properties file
+ InputStream in = getClassLoader().getResourceAsStream(
+ "easymock.properties");
+ if (in != null) {
+ in = new BufferedInputStream(in);
+ try {
+ properties.load(in);
+ } catch (IOException e) {
+ throw new RuntimeException(
+ "Failed to read easymock.properties file");
+ } finally {
+ try {
+ in.close();
+ } catch (IOException e) {
+ // Doesn't matter
+ }
+ }
+ }
+ // Then overload it with system properties
+ for (Map.Entry<Object, Object> entry : System.getProperties()
+ .entrySet()) {
+ if (entry.getKey() instanceof String
+ && entry.getKey().toString().startsWith(PREFIX)) {
+ properties.put(entry.getKey(), entry.getValue());
+ }
+ }
+ }
+
+ /**
+ * Searches for the property with the specified key. If the key is not
+ * found, return the default value.
+ *
+ * @param key
+ * key leading to the property
+ * @param defaultValue
+ * the value to be returned if the key isn't found
+ * @return the value found for the key or the default value
+ */
+ public String getProperty(String key, String defaultValue) {
+ return properties.getProperty(key, defaultValue);
+ }
+
+ /**
+ * Searches for the property with the specified key. Return null if the key
+ * is not found.
+ *
+ * @param key
+ * key leading to the property
+ * @return the value found for the key or null
+ */
+ public String getProperty(String key) {
+ return properties.getProperty(key);
+ }
+
+ /**
+ * Add a value referenced by the provided key. A null value will remove the
+ * key
+ *
+ * @param key
+ * the key of the new property
+ * @param value
+ * the value corresponding to <tt>key</tt>.
+ * @return the property previous value
+ */
+ public String setProperty(String key, String value) {
+ if (!key.startsWith(PREFIX)) {
+ throw new IllegalArgumentException("Invalid key (" + key
+ + "), an easymock property starts with \"" + PREFIX + "\"");
+ }
+ if (value == null) {
+ return (String) properties.remove(key);
+ }
+ return (String) properties.setProperty(key, value);
+ }
+
+ private ClassLoader getClassLoader() {
+ ClassLoader cl = null;
+ try {
+ cl = Thread.currentThread().getContextClassLoader();
+ } catch (Throwable ex) {
+ // Cannot access thread context ClassLoader - falling back to system
+ // class loader
+ }
+ if (cl == null) {
+ // No thread context class loader -> use class loader of this class.
+ cl = getClass().getClassLoader();
+ }
+ return cl;
+ }
+}
diff --git a/src/org/easymock/internal/EqualsMatcher.java b/src/org/easymock/internal/EqualsMatcher.java
new file mode 100644
index 0000000..ee49098
--- /dev/null
+++ b/src/org/easymock/internal/EqualsMatcher.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal;
+
+import org.easymock.AbstractMatcher;
+
+@SuppressWarnings("deprecation")
+public class EqualsMatcher extends AbstractMatcher {
+
+ private static final long serialVersionUID = 4152805764785966978L;
+} \ No newline at end of file
diff --git a/src/org/easymock/internal/ErrorMessage.java b/src/org/easymock/internal/ErrorMessage.java
new file mode 100644
index 0000000..9284f6c
--- /dev/null
+++ b/src/org/easymock/internal/ErrorMessage.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2003-2009 OFFIS, Henri Tremblay
+ *
+ * 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 org.easymock.internal;
+
+public class ErrorMessage {
+
+ private final boolean matching;
+
+ private final String message;
+
+ private final int actualCount;
+
+ public ErrorMessage(boolean matching, String message, int actualCount) {
+ this.matching = matching;
+ this.message = message;
+ this.actualCount = actualCount;
+ }
+
+ public boolean isMatching() {
+ return matching;
+ }
+
+ public String getMessage() {
+ return message;
+ }
+
+ public int getActualCount() {
+ return actualCount;
+ }
+
+ public void appendTo(StringBuilder buffer, int matches) {
+ buffer.append("\n ").append(message).append(", actual: ");
+ if (matching) {
+ if (matches == 1) {
+ buffer.append(getActualCount() + 1);
+ } else {
+ buffer.append(getActualCount());
+ buffer.append(" (+1)");
+ }
+ }
+ else {
+ buffer.append(getActualCount());
+ }
+ }
+}
diff --git a/src/org/easymock/internal/ExpectedInvocation.java b/src/org/easymock/internal/ExpectedInvocation.java
new file mode 100644
index 0000000..7bff86c
--- /dev/null
+++ b/src/org/easymock/internal/ExpectedInvocation.java
@@ -0,0 +1,135 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal;
+
+import java.io.Serializable;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.easymock.IArgumentMatcher;
+import org.easymock.internal.matchers.Equals;
+
+public class ExpectedInvocation implements Serializable {
+
+ private static final long serialVersionUID = -5554816464613350531L;
+
+ private final Invocation invocation;
+
+ @SuppressWarnings("deprecation")
+ private final org.easymock.ArgumentsMatcher matcher;
+
+ private final List<IArgumentMatcher> matchers;
+
+ public ExpectedInvocation(Invocation invocation,
+ List<IArgumentMatcher> matchers) {
+ this(invocation, matchers, null);
+ }
+
+ private ExpectedInvocation(Invocation invocation,
+ List<IArgumentMatcher> matchers, @SuppressWarnings("deprecation")
+ org.easymock.ArgumentsMatcher matcher) {
+ this.invocation = invocation;
+ this.matcher = matcher;
+ this.matchers = (matcher == null) ? createMissingMatchers(invocation,
+ matchers) : null;
+ }
+
+ private List<IArgumentMatcher> createMissingMatchers(Invocation invocation,
+ List<IArgumentMatcher> matchers) {
+ if (matchers != null) {
+ if (matchers.size() != invocation.getArguments().length) {
+ throw new IllegalStateException(""
+ + invocation.getArguments().length
+ + " matchers expected, " + matchers.size()
+ + " recorded.");
+ }
+ return matchers;
+ }
+ List<IArgumentMatcher> result = new ArrayList<IArgumentMatcher>();
+ for (Object argument : invocation.getArguments()) {
+ result.add(new Equals(argument));
+ }
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o == null || !this.getClass().equals(o.getClass()))
+ return false;
+
+ ExpectedInvocation other = (ExpectedInvocation) o;
+ return this.invocation.equals(other.invocation)
+ && ((this.matcher == null && other.matcher == null) || (this.matcher != null && this.matcher
+ .equals(other.matcher)))
+ && ((this.matchers == null && other.matchers == null) || (this.matchers != null && this.matchers
+ .equals(other.matchers)));
+ }
+
+ @Override
+ public int hashCode() {
+ throw new UnsupportedOperationException("hashCode() is not implemented");
+ }
+
+ public boolean matches(Invocation actual) {
+ return matchers != null ? this.invocation.getMock().equals(
+ actual.getMock())
+ && this.invocation.getMethod().equals(actual.getMethod())
+ && matches(actual.getArguments()) : this.invocation.matches(
+ actual, matcher);
+ }
+
+ private boolean matches(Object[] arguments) {
+ if (arguments.length != matchers.size()) {
+ return false;
+ }
+ for (int i = 0; i < arguments.length; i++) {
+ if (!matchers.get(i).matches(arguments[i])) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return matchers != null ? myToString() : invocation.toString(matcher);
+ }
+
+ private String myToString() {
+ StringBuffer result = new StringBuffer();
+ result.append(invocation.getMockAndMethodName());
+ result.append("(");
+ for (Iterator<IArgumentMatcher> it = matchers.iterator(); it.hasNext();) {
+ it.next().appendTo(result);
+ if (it.hasNext()) {
+ result.append(", ");
+ }
+ }
+ result.append(")");
+ return result.toString();
+ }
+
+ public Method getMethod() {
+ return invocation.getMethod();
+ }
+
+ public ExpectedInvocation withMatcher(@SuppressWarnings("deprecation")
+ org.easymock.ArgumentsMatcher matcher) {
+ return new ExpectedInvocation(invocation, null, matcher);
+ }
+}
diff --git a/src/org/easymock/internal/ExpectedInvocationAndResult.java b/src/org/easymock/internal/ExpectedInvocationAndResult.java
new file mode 100644
index 0000000..b33be7f
--- /dev/null
+++ b/src/org/easymock/internal/ExpectedInvocationAndResult.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal;
+
+import java.io.Serializable;
+
+public class ExpectedInvocationAndResult implements Serializable {
+
+ private static final long serialVersionUID = -1951159588262854559L;
+
+ ExpectedInvocation expectedInvocation;
+
+ Result result;
+
+ public ExpectedInvocationAndResult(ExpectedInvocation expectedInvocation,
+ Result result) {
+ this.expectedInvocation = expectedInvocation;
+ this.result = result;
+ }
+
+ public ExpectedInvocation getExpectedInvocation() {
+ return expectedInvocation;
+ }
+
+ public Result getResult() {
+ return result;
+ }
+} \ No newline at end of file
diff --git a/src/org/easymock/internal/ExpectedInvocationAndResults.java b/src/org/easymock/internal/ExpectedInvocationAndResults.java
new file mode 100644
index 0000000..52b6743
--- /dev/null
+++ b/src/org/easymock/internal/ExpectedInvocationAndResults.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal;
+
+import java.io.Serializable;
+
+public class ExpectedInvocationAndResults implements Serializable {
+
+ private static final long serialVersionUID = 8189985418895395472L;
+
+ ExpectedInvocation expectedInvocation;
+
+ Results results;
+
+ public ExpectedInvocationAndResults(ExpectedInvocation expectedInvocation,
+ Results results) {
+ this.expectedInvocation = expectedInvocation;
+ this.results = results;
+ }
+
+ public ExpectedInvocation getExpectedInvocation() {
+ return expectedInvocation;
+ }
+
+ public Results getResults() {
+ return results;
+ }
+
+ @Override
+ public String toString() {
+ return expectedInvocation.toString() + ": " + results.toString();
+ }
+} \ No newline at end of file
diff --git a/src/org/easymock/internal/ILegacyMatcherMethods.java b/src/org/easymock/internal/ILegacyMatcherMethods.java
new file mode 100644
index 0000000..48f8fb2
--- /dev/null
+++ b/src/org/easymock/internal/ILegacyMatcherMethods.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal;
+
+import java.lang.reflect.Method;
+
+public interface ILegacyMatcherMethods {
+
+ @SuppressWarnings("deprecation")
+ void setDefaultMatcher(org.easymock.ArgumentsMatcher matcher);
+
+ @SuppressWarnings("deprecation")
+ void setMatcher(Method method, org.easymock.ArgumentsMatcher matcher);
+} \ No newline at end of file
diff --git a/src/org/easymock/internal/ILegacyMethods.java b/src/org/easymock/internal/ILegacyMethods.java
new file mode 100644
index 0000000..45c8de2
--- /dev/null
+++ b/src/org/easymock/internal/ILegacyMethods.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal;
+
+public interface ILegacyMethods extends ILegacyMatcherMethods {
+ void setDefaultReturnValue(Object value);
+
+ void setDefaultThrowable(Throwable throwable);
+
+ void setDefaultVoidCallable();
+}
diff --git a/src/org/easymock/internal/IMocksBehavior.java b/src/org/easymock/internal/IMocksBehavior.java
new file mode 100644
index 0000000..b72ec59
--- /dev/null
+++ b/src/org/easymock/internal/IMocksBehavior.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal;
+
+public interface IMocksBehavior extends ILegacyMatcherMethods {
+
+ // record
+ void addExpected(ExpectedInvocation expected, Result result, Range count);
+
+ void addStub(ExpectedInvocation expected, Result result);
+
+ void checkOrder(boolean value);
+
+ void makeThreadSafe(boolean isThreadSafe);
+
+ void shouldBeUsedInOneThread(boolean shouldBeUsedInOneThread);
+
+ // replay
+ Result addActual(Invocation invocation);
+
+ boolean isThreadSafe();
+
+ void checkThreadSafety();
+
+ // verify
+ void verify();
+}
diff --git a/src/org/easymock/internal/IMocksControlState.java b/src/org/easymock/internal/IMocksControlState.java
new file mode 100644
index 0000000..4ff2842
--- /dev/null
+++ b/src/org/easymock/internal/IMocksControlState.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal;
+
+import org.easymock.IAnswer;
+
+public interface IMocksControlState extends ILegacyMethods {
+
+ Object invoke(Invocation invocation) throws Throwable;
+
+ void assertRecordState();
+
+ void andReturn(Object value);
+
+ void andThrow(Throwable throwable);
+
+ void andAnswer(IAnswer<?> answer);
+
+ void andDelegateTo(Object answer);
+
+ void andStubReturn(Object value);
+
+ void andStubThrow(Throwable throwable);
+
+ void andStubAnswer(IAnswer<?> answer);
+
+ void andStubDelegateTo(Object delegateTo);
+
+ void asStub();
+
+ void times(Range range);
+
+ void checkOrder(boolean value);
+
+ void makeThreadSafe(boolean threadSafe);
+
+ void checkIsUsedInOneThread(boolean shouldBeUsedInOneThread);
+
+ void replay();
+
+ void verify();
+}
diff --git a/src/org/easymock/internal/IProxyFactory.java b/src/org/easymock/internal/IProxyFactory.java
new file mode 100644
index 0000000..9e22062
--- /dev/null
+++ b/src/org/easymock/internal/IProxyFactory.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal;
+
+import java.lang.reflect.InvocationHandler;
+
+public interface IProxyFactory<T> {
+ T createProxy(Class<T> toMock, InvocationHandler handler);
+}
diff --git a/src/org/easymock/internal/Invocation.java b/src/org/easymock/internal/Invocation.java
new file mode 100644
index 0000000..c058524
--- /dev/null
+++ b/src/org/easymock/internal/Invocation.java
@@ -0,0 +1,218 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal;
+
+import static java.lang.Character.*;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.lang.reflect.Array;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import org.easymock.internal.matchers.Captures;
+
+public class Invocation implements Serializable {
+
+ private static final long serialVersionUID = 1604995470419943411L;
+
+ private final Object mock;
+
+ private transient Method method;
+
+ private final Object[] arguments;
+
+ private final Collection<Captures<?>> currentCaptures = new ArrayList<Captures<?>>(
+ 0);
+
+ public Invocation(Object mock, Method method, Object[] args) {
+ this.mock = mock;
+ this.method = method;
+ this.arguments = expandVarArgs(method.isVarArgs(), args);
+ }
+
+ private static Object[] expandVarArgs(final boolean isVarArgs,
+ final Object[] args) {
+ if (!isVarArgs) {
+ return args == null ? new Object[0] : args;
+ }
+ if (args[args.length - 1] == null) {
+ return args;
+ }
+ Object[] varArgs = createObjectArray(args[args.length - 1]);
+ final int nonVarArgsCount = args.length - 1;
+ final int varArgsCount = varArgs.length;
+ Object[] newArgs = new Object[nonVarArgsCount + varArgsCount];
+ System.arraycopy(args, 0, newArgs, 0, nonVarArgsCount);
+ System.arraycopy(varArgs, 0, newArgs, nonVarArgsCount, varArgsCount);
+ return newArgs;
+ }
+
+ private static Object[] createObjectArray(Object array) {
+ if (array instanceof Object[]) {
+ return (Object[]) array;
+ }
+ Object[] result = new Object[Array.getLength(array)];
+ for (int i = 0; i < Array.getLength(array); i++) {
+ result[i] = Array.get(array, i);
+ }
+ return result;
+ }
+
+ public Object getMock() {
+ return mock;
+ }
+
+ public Method getMethod() {
+ return method;
+ }
+
+ public Object[] getArguments() {
+ return arguments;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o == null || !o.getClass().equals(this.getClass()))
+ return false;
+
+ Invocation other = (Invocation) o;
+
+ return this.mock.equals(other.mock) && this.method.equals(other.method)
+ && this.equalArguments(other.arguments);
+ }
+
+ @Override
+ public int hashCode() {
+ throw new UnsupportedOperationException("hashCode() is not implemented");
+ }
+
+ private boolean equalArguments(Object[] arguments) {
+ if (this.arguments.length != arguments.length) {
+ return false;
+ }
+ for (int i = 0; i < this.arguments.length; i++) {
+ Object myArgument = this.arguments[i];
+ Object otherArgument = arguments[i];
+
+ if (isPrimitiveParameter(i)) {
+ if (!myArgument.equals(otherArgument)) {
+ return false;
+ }
+ } else {
+ if (myArgument != otherArgument) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+ private boolean isPrimitiveParameter(int parameterPosition) {
+ Class<?>[] parameterTypes = method.getParameterTypes();
+ if (method.isVarArgs()) {
+ parameterPosition = Math.min(parameterPosition,
+ parameterTypes.length - 1);
+ }
+ return parameterTypes[parameterPosition].isPrimitive();
+ }
+
+ @SuppressWarnings("deprecation")
+ public boolean matches(Invocation actual, org.easymock.ArgumentsMatcher matcher) {
+ return this.mock.equals(actual.mock)
+ && this.method.equals(actual.method)
+ && matcher.matches(this.arguments, actual.arguments);
+ }
+
+ @SuppressWarnings("deprecation")
+ public String toString(org.easymock.ArgumentsMatcher matcher) {
+ return getMockAndMethodName() + "(" + matcher.toString(arguments) + ")";
+ }
+
+ public String getMockAndMethodName() {
+ String mockName = mock.toString();
+ String methodName = method.getName();
+ if (toStringIsDefined(mock) && isJavaIdentifier(mockName)) {
+ return mockName + "." + methodName;
+ } else {
+ return methodName;
+ }
+ }
+
+ public void addCapture(Captures<Object> capture, Object value) {
+ capture.setPotentialValue(value);
+ currentCaptures.add(capture);
+ }
+
+ public void validateCaptures() {
+ for (Captures<?> c : currentCaptures) {
+ c.validateCapture();
+ }
+ }
+
+ public void clearCaptures() {
+ for (Captures<?> c : currentCaptures) {
+ c.setPotentialValue(null);
+ }
+ currentCaptures.clear();
+ }
+
+ private boolean toStringIsDefined(Object o) {
+ try {
+ o.getClass().getDeclaredMethod("toString", (Class[]) null)
+ .getModifiers();
+ return true;
+ } catch (SecurityException ignored) {
+ // ///CLOVER:OFF
+ return false;
+ // ///CLOVER:ON
+ } catch (NoSuchMethodException shouldNeverHappen) {
+ // ///CLOVER:OFF
+ throw new RuntimeException("The toString() method could not be found!");
+ // ///CLOVER:ON
+ }
+ }
+
+ public static boolean isJavaIdentifier(String mockName) {
+ if (mockName.length() == 0 || mockName.indexOf(' ') > -1
+ || !Character.isJavaIdentifierStart(mockName.charAt(0))) {
+ return false;
+ }
+ for (char c : mockName.substring(1).toCharArray()) {
+ if (!isJavaIdentifierPart(c)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ private void readObject(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException {
+ stream.defaultReadObject();
+ try {
+ method = ((MethodSerializationWrapper) stream.readObject()).getMethod();
+ } catch (NoSuchMethodException e) {
+ // ///CLOVER:OFF
+ throw new IOException(e.toString());
+ // ///CLOVER:ON
+ }
+ }
+
+ private void writeObject(java.io.ObjectOutputStream stream) throws IOException {
+ stream.defaultWriteObject();
+ stream.writeObject(new MethodSerializationWrapper(method));
+ }
+}
diff --git a/src/org/easymock/internal/JavaProxyFactory.java b/src/org/easymock/internal/JavaProxyFactory.java
new file mode 100644
index 0000000..2d1c47d
--- /dev/null
+++ b/src/org/easymock/internal/JavaProxyFactory.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Proxy;
+
+public class JavaProxyFactory<T> implements IProxyFactory<T> {
+ @SuppressWarnings("unchecked")
+ public T createProxy(Class<T> toMock, InvocationHandler handler) {
+ return (T) Proxy.newProxyInstance(toMock.getClassLoader(),
+ new Class[] { toMock }, handler);
+ }
+}
diff --git a/src/org/easymock/internal/LastControl.java b/src/org/easymock/internal/LastControl.java
new file mode 100644
index 0000000..2acc1e6
--- /dev/null
+++ b/src/org/easymock/internal/LastControl.java
@@ -0,0 +1,124 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal;
+
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Stack;
+
+import org.easymock.IArgumentMatcher;
+import org.easymock.internal.matchers.And;
+import org.easymock.internal.matchers.Not;
+import org.easymock.internal.matchers.Or;
+
+public class LastControl {
+ private static final ThreadLocal<MocksControl> threadToControl = new ThreadLocal<MocksControl>();
+
+ private static final ThreadLocal<Stack<Invocation>> threadToCurrentInvocation = new ThreadLocal<Stack<Invocation>>();
+
+ private static final ThreadLocal<Stack<IArgumentMatcher>> threadToArgumentMatcherStack = new ThreadLocal<Stack<IArgumentMatcher>>();
+
+ public static void reportLastControl(MocksControl control) {
+ if (control != null) {
+ threadToControl.set(control);
+ } else {
+ threadToControl.remove();
+ }
+ }
+
+ public static MocksControl lastControl() {
+ return threadToControl.get();
+ }
+
+ public static void reportMatcher(IArgumentMatcher matcher) {
+ Stack<IArgumentMatcher> stack = threadToArgumentMatcherStack.get();
+ if (stack == null) {
+ stack = new Stack<IArgumentMatcher>();
+ threadToArgumentMatcherStack.set(stack);
+ }
+ stack.push(matcher);
+ }
+
+ public static List<IArgumentMatcher> pullMatchers() {
+ Stack<IArgumentMatcher> stack = threadToArgumentMatcherStack.get();
+ if (stack == null) {
+ return null;
+ }
+ threadToArgumentMatcherStack.remove();
+ return new ArrayList<IArgumentMatcher>(stack);
+ }
+
+ public static void reportAnd(int count) {
+ Stack<IArgumentMatcher> stack = threadToArgumentMatcherStack.get();
+ assertState(stack != null, "no matchers found.");
+ stack.push(new And(popLastArgumentMatchers(count)));
+ }
+
+ public static void reportNot() {
+ Stack<IArgumentMatcher> stack = threadToArgumentMatcherStack.get();
+ assertState(stack != null, "no matchers found.");
+ stack.push(new Not(popLastArgumentMatchers(1).get(0)));
+ }
+
+ private static List<IArgumentMatcher> popLastArgumentMatchers(int count) {
+ Stack<IArgumentMatcher> stack = threadToArgumentMatcherStack.get();
+ assertState(stack != null, "no matchers found.");
+ assertState(stack.size() >= count, "" + count + " matchers expected, "
+ + stack.size() + " recorded.");
+ List<IArgumentMatcher> result = new LinkedList<IArgumentMatcher>();
+ result.addAll(stack.subList(stack.size() - count, stack.size()));
+ for (int i = 0; i < count; i++) {
+ stack.pop();
+ }
+ return result;
+ }
+
+ private static void assertState(boolean toAssert, String message) {
+ if (!toAssert) {
+ threadToArgumentMatcherStack.remove();
+ throw new IllegalStateException(message);
+ }
+ }
+
+ public static void reportOr(int count) {
+ Stack<IArgumentMatcher> stack = threadToArgumentMatcherStack.get();
+ assertState(stack != null, "no matchers found.");
+ stack.push(new Or(popLastArgumentMatchers(count)));
+ }
+
+ public static Invocation getCurrentInvocation() {
+ Stack<Invocation> stack = threadToCurrentInvocation.get();
+ if (stack == null || stack.empty()) {
+ return null;
+ }
+ return stack.lastElement();
+ }
+
+ public static void pushCurrentInvocation(Invocation invocation) {
+ Stack<Invocation> stack = threadToCurrentInvocation.get();
+ if (stack == null) {
+ stack = new Stack<Invocation>();
+ threadToCurrentInvocation.set(stack);
+ }
+ stack.push(invocation);
+ }
+
+ public static void popCurrentInvocation() {
+ Stack<Invocation> stack = threadToCurrentInvocation.get();
+ stack.pop();
+ }
+}
diff --git a/src/org/easymock/internal/LegacyMatcherProvider.java b/src/org/easymock/internal/LegacyMatcherProvider.java
new file mode 100644
index 0000000..b8665e9
--- /dev/null
+++ b/src/org/easymock/internal/LegacyMatcherProvider.java
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.easymock.ArgumentsMatcher;
+import org.easymock.MockControl;
+
+@SuppressWarnings("deprecation")
+public class LegacyMatcherProvider implements Serializable {
+
+ private static final long serialVersionUID = -4143082656571251917L;
+
+ private ArgumentsMatcher defaultMatcher;
+
+ private boolean defaultMatcherSet;
+
+ private transient Map<Method, ArgumentsMatcher> matchers = new HashMap<Method, ArgumentsMatcher>();
+
+ public ArgumentsMatcher getMatcher(Method method) {
+ if (!matchers.containsKey(method)) {
+ if (!defaultMatcherSet) {
+ setDefaultMatcher(MockControl.EQUALS_MATCHER);
+ }
+ matchers.put(method, defaultMatcher);
+ }
+ return matchers.get(method);
+ }
+
+ public void setDefaultMatcher(ArgumentsMatcher matcher) {
+ if (defaultMatcherSet) {
+ throw new RuntimeExceptionWrapper(
+ new IllegalStateException(
+ "default matcher can only be set once directly after creation of the MockControl"));
+ }
+ defaultMatcher = matcher;
+ defaultMatcherSet = true;
+ }
+
+ public void setMatcher(Method method, ArgumentsMatcher matcher) {
+ if (matchers.containsKey(method) && matchers.get(method) != matcher) {
+ throw new RuntimeExceptionWrapper(new IllegalStateException(
+ "for method "
+ + method.getName()
+ + "("
+ + (method.getParameterTypes().length == 0 ? ""
+ : "...")
+ + "), a matcher has already been set"));
+ }
+ matchers.put(method, matcher);
+ }
+
+ @SuppressWarnings("unchecked")
+ private void readObject(java.io.ObjectInputStream stream)
+ throws IOException, ClassNotFoundException {
+ stream.defaultReadObject();
+ Map<MethodSerializationWrapper, ArgumentsMatcher> map = (Map<MethodSerializationWrapper, ArgumentsMatcher>) stream
+ .readObject();
+ matchers = new HashMap<Method, ArgumentsMatcher>(map.size());
+ for (Map.Entry<MethodSerializationWrapper, ArgumentsMatcher> entry : map
+ .entrySet()) {
+ try {
+ Method method = entry.getKey().getMethod();
+ matchers.put(method, entry.getValue());
+ } catch (NoSuchMethodException e) {
+ // ///CLOVER:OFF
+ throw new IOException(e.toString());
+ // ///CLOVER:ON
+ }
+ }
+ }
+
+ private void writeObject(java.io.ObjectOutputStream stream)
+ throws IOException {
+ stream.defaultWriteObject();
+ Map<MethodSerializationWrapper, ArgumentsMatcher> map = new HashMap<MethodSerializationWrapper, ArgumentsMatcher>(
+ matchers.size());
+ for (Map.Entry<Method, ArgumentsMatcher> matcher : matchers.entrySet()) {
+ map.put(new MethodSerializationWrapper(matcher.getKey()), matcher
+ .getValue());
+ }
+ stream.writeObject(map);
+ }
+}
diff --git a/src/org/easymock/internal/MethodSerializationWrapper.java b/src/org/easymock/internal/MethodSerializationWrapper.java
new file mode 100644
index 0000000..924331c
--- /dev/null
+++ b/src/org/easymock/internal/MethodSerializationWrapper.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2003-2009 OFFIS, Henri Tremblay
+ *
+ * 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 org.easymock.internal;
+
+import java.io.Serializable;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+
+public class MethodSerializationWrapper implements Serializable {
+
+ private static final long serialVersionUID = 1775475200823842126L;
+
+ private static final Map<String, Class<?>> primitiveTypes = new HashMap<String, Class<?>>(
+ 10);
+
+ static {
+ primitiveTypes.put(Boolean.TYPE.getName(), Boolean.TYPE);
+ primitiveTypes.put(Byte.TYPE.getName(), Byte.TYPE);
+ primitiveTypes.put(Short.TYPE.getName(), Short.TYPE);
+ primitiveTypes.put(Character.TYPE.getName(), Character.TYPE);
+ primitiveTypes.put(Integer.TYPE.getName(), Integer.TYPE);
+ primitiveTypes.put(Long.TYPE.getName(), Long.TYPE);
+ primitiveTypes.put(Float.TYPE.getName(), Float.TYPE);
+ primitiveTypes.put(Double.TYPE.getName(), Double.TYPE);
+ }
+
+ private String className;
+
+ private String methodName;
+
+ private String[] parameterTypeNames;
+
+ public MethodSerializationWrapper(Method m) {
+ className = m.getDeclaringClass().getName();
+ methodName = m.getName();
+
+ Class<?>[] parameterTypes = m.getParameterTypes();
+
+ parameterTypeNames = new String[parameterTypes.length];
+
+ for (int i = 0; i < parameterTypes.length; i++) {
+ parameterTypeNames[i] = parameterTypes[i].getName();
+ }
+ }
+
+ public Method getMethod() throws ClassNotFoundException,
+ NoSuchMethodException {
+ Class<?> clazz = Class.forName(className, true, Thread.currentThread()
+ .getContextClassLoader());
+
+ Class<?>[] parameterTypes = new Class[parameterTypeNames.length];
+
+ for (int i = 0; i < parameterTypeNames.length; i++) {
+ Class<?> primitiveType = primitiveTypes.get(parameterTypeNames[i]);
+ if (primitiveType != null) {
+ parameterTypes[i] = primitiveType;
+ } else {
+ parameterTypes[i] = Class.forName(parameterTypeNames[i], true,
+ Thread.currentThread().getContextClassLoader());
+ }
+ }
+
+ Method m = clazz.getMethod(methodName, parameterTypes);
+
+ return m;
+ }
+}
diff --git a/src/org/easymock/internal/MockInvocationHandler.java b/src/org/easymock/internal/MockInvocationHandler.java
new file mode 100644
index 0000000..323cb4e
--- /dev/null
+++ b/src/org/easymock/internal/MockInvocationHandler.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal;
+
+import java.io.Serializable;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+
+public final class MockInvocationHandler implements InvocationHandler, Serializable {
+
+ private static final long serialVersionUID = -7799769066534714634L;
+
+ private final MocksControl control;
+
+ public MockInvocationHandler(MocksControl control) {
+ this.control = control;
+ }
+
+ public Object invoke(Object proxy, Method method, Object[] args)
+ throws Throwable {
+ try {
+ if (control.getState() instanceof RecordState) {
+ LastControl.reportLastControl(control);
+ }
+ return control.getState().invoke(
+ new Invocation(proxy, method, args));
+ } catch (RuntimeExceptionWrapper e) {
+ throw e.getRuntimeException().fillInStackTrace();
+ } catch (AssertionErrorWrapper e) {
+ throw e.getAssertionError().fillInStackTrace();
+ } catch (ThrowableWrapper t) {
+ throw t.getThrowable().fillInStackTrace();
+ } catch (Throwable t) {
+ throw t; // let all unwrapped pass unmodified
+ }
+ }
+
+ public MocksControl getControl() {
+ return control;
+ }
+} \ No newline at end of file
diff --git a/src/org/easymock/internal/MocksBehavior.java b/src/org/easymock/internal/MocksBehavior.java
new file mode 100644
index 0000000..84a49a5
--- /dev/null
+++ b/src/org/easymock/internal/MocksBehavior.java
@@ -0,0 +1,239 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal;
+
+import java.io.Serializable;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.easymock.EasyMock;
+
+public class MocksBehavior implements IMocksBehavior, Serializable {
+
+ private static final long serialVersionUID = 3265727009370529027L;
+
+ private final List<UnorderedBehavior> behaviorLists = new ArrayList<UnorderedBehavior>();
+
+ private final List<ExpectedInvocationAndResult> stubResults = new ArrayList<ExpectedInvocationAndResult>();
+
+ private final boolean nice;
+
+ private boolean checkOrder;
+
+ private boolean isThreadSafe;
+
+ private boolean shouldBeUsedInOneThread;
+
+ private int position = 0;
+
+ private transient volatile Thread lastThread;
+
+ private LegacyMatcherProvider legacyMatcherProvider;
+
+ public MocksBehavior(boolean nice) {
+ this.nice = nice;
+ this.isThreadSafe = !Boolean.valueOf(EasyMockProperties.getInstance()
+ .getProperty(EasyMock.NOT_THREAD_SAFE_BY_DEFAULT));
+ this.shouldBeUsedInOneThread = Boolean.valueOf(EasyMockProperties
+ .getInstance().getProperty(
+ EasyMock.ENABLE_THREAD_SAFETY_CHECK_BY_DEFAULT));
+ }
+
+ public final void addStub(ExpectedInvocation expected, Result result) {
+ stubResults.add(new ExpectedInvocationAndResult(expected, result));
+ }
+
+ public void addExpected(ExpectedInvocation expected, Result result,
+ Range count) {
+ if (legacyMatcherProvider != null) {
+ expected = expected.withMatcher(legacyMatcherProvider
+ .getMatcher(expected.getMethod()));
+ }
+ addBehaviorListIfNecessary(expected);
+ lastBehaviorList().addExpected(expected, result, count);
+ }
+
+ private final Result getStubResult(Invocation actual) {
+ for (ExpectedInvocationAndResult each : stubResults) {
+ if (each.getExpectedInvocation().matches(actual)) {
+ return each.getResult();
+ }
+ }
+ return null;
+ }
+
+ private void addBehaviorListIfNecessary(ExpectedInvocation expected) {
+ if (behaviorLists.isEmpty()
+ || !lastBehaviorList().allowsExpectedInvocation(expected,
+ checkOrder)) {
+ behaviorLists.add(new UnorderedBehavior(checkOrder));
+ }
+ }
+
+ private UnorderedBehavior lastBehaviorList() {
+ return behaviorLists.get(behaviorLists.size() - 1);
+ }
+
+ @SuppressWarnings("deprecation")
+ public final Result addActual(Invocation actual) {
+ int initialPosition = position;
+
+ while (position < behaviorLists.size()) {
+ Result result = behaviorLists.get(position).addActual(actual);
+ if (result != null) {
+ return result;
+ }
+ if (!behaviorLists.get(position).verify()) {
+ break;
+ }
+ position++;
+ }
+ Result stubOrNice = getStubResult(actual);
+ if (stubOrNice == null && nice) {
+ stubOrNice = Result.createReturnResult(RecordState
+ .emptyReturnValueFor(actual.getMethod().getReturnType()));
+ }
+
+ int endPosition = position;
+
+ // Do not move the cursor in case of stub, nice or error
+ position = initialPosition;
+
+ if (stubOrNice != null) {
+ actual.validateCaptures();
+ actual.clearCaptures();
+ return stubOrNice;
+ }
+
+ // Case where the loop was exited at the end of the behaviorLists
+ if (endPosition == behaviorLists.size()) {
+ endPosition--;
+ }
+
+ // Loop all around the behaviors left to generate the message
+ StringBuilder errorMessage = new StringBuilder(70 * (endPosition
+ - initialPosition + 1)); // rough approximation of the length
+ errorMessage.append("\n Unexpected method call ").append(
+ actual.toString(org.easymock.MockControl.EQUALS_MATCHER));
+
+ List<ErrorMessage> messages = new ArrayList<ErrorMessage>();
+
+ int matches = 0;
+
+ // First find how many match we have
+ for (int i = initialPosition; i <= endPosition; i++) {
+ List<ErrorMessage> thisListMessages = behaviorLists.get(i)
+ .getMessages(actual);
+ messages.addAll(thisListMessages);
+ for (ErrorMessage m : thisListMessages) {
+ if (m.isMatching()) {
+ matches++;
+ }
+ }
+ }
+
+ if (matches > 1) {
+ errorMessage
+ .append(". Possible matches are marked with (+1):");
+ } else {
+ errorMessage.append(":");
+ }
+
+ for (ErrorMessage m : messages) {
+ m.appendTo(errorMessage, matches);
+ }
+
+ // And finally throw the error
+ throw new AssertionErrorWrapper(new AssertionError(errorMessage));
+ }
+
+ public void verify() {
+ boolean verified = true;
+
+ for (UnorderedBehavior behaviorList : behaviorLists.subList(position,
+ behaviorLists.size())) {
+ if (!behaviorList.verify()) {
+ verified = false;
+ }
+ }
+ if (verified) {
+ return;
+ }
+
+ StringBuilder errorMessage = new StringBuilder(70 * (behaviorLists
+ .size()
+ - position + 1));
+
+ errorMessage.append("\n Expectation failure on verify:");
+ for (UnorderedBehavior behaviorList : behaviorLists.subList(position,
+ behaviorLists.size())) {
+ for (ErrorMessage m : behaviorList.getMessages(null)) {
+ m.appendTo(errorMessage, 0);
+ }
+ }
+
+ throw new AssertionErrorWrapper(new AssertionError(errorMessage
+ .toString()));
+ }
+
+ public void checkOrder(boolean value) {
+ this.checkOrder = value;
+ }
+
+ public void makeThreadSafe(boolean isThreadSafe) {
+ this.isThreadSafe = isThreadSafe;
+ }
+
+ public void shouldBeUsedInOneThread(boolean shouldBeUsedInOneThread) {
+ this.shouldBeUsedInOneThread = shouldBeUsedInOneThread;
+ }
+
+ public boolean isThreadSafe() {
+ return this.isThreadSafe;
+ }
+
+ public void checkThreadSafety() {
+ if (!shouldBeUsedInOneThread) {
+ return;
+ }
+ if (lastThread == null) {
+ lastThread = Thread.currentThread();
+ } else if(lastThread != Thread.currentThread()) {
+ throw new AssertionErrorWrapper(new AssertionError(
+ "\n Mock isn't supposed to be called from multiple threads. Last: "
+ + lastThread +
+ " Current: " + Thread.currentThread()));
+ }
+ }
+
+ public LegacyMatcherProvider getLegacyMatcherProvider() {
+ if (legacyMatcherProvider == null) {
+ legacyMatcherProvider = new LegacyMatcherProvider();
+ }
+ return legacyMatcherProvider;
+ }
+
+ @SuppressWarnings("deprecation")
+ public void setDefaultMatcher(org.easymock.ArgumentsMatcher matcher) {
+ getLegacyMatcherProvider().setDefaultMatcher(matcher);
+ }
+
+ @SuppressWarnings("deprecation")
+ public void setMatcher(Method method, org.easymock.ArgumentsMatcher matcher) {
+ getLegacyMatcherProvider().setMatcher(method, matcher);
+ }
+}
diff --git a/src/org/easymock/internal/MocksControl.java b/src/org/easymock/internal/MocksControl.java
new file mode 100644
index 0000000..8de3cb6
--- /dev/null
+++ b/src/org/easymock/internal/MocksControl.java
@@ -0,0 +1,315 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal;
+
+import java.io.Serializable;
+
+import org.easymock.IAnswer;
+import org.easymock.IExpectationSetters;
+import org.easymock.IMocksControl;
+
+public class MocksControl implements IMocksControl, IExpectationSetters<Object>, Serializable {
+
+ private static final long serialVersionUID = 443604921336702014L;
+
+ private IMocksControlState state;
+
+ private IMocksBehavior behavior;
+
+ public enum MockType {
+ NICE, DEFAULT, STRICT
+ }
+
+ private MockType type;
+
+ public MocksControl(MockType type) {
+ this.type = type;
+ reset();
+ }
+
+ public IMocksControlState getState() {
+ return state;
+ }
+
+ public <T> T createMock(Class<T> toMock) {
+ try {
+ state.assertRecordState();
+ IProxyFactory<T> proxyFactory = createProxyFactory(toMock);
+ return proxyFactory.createProxy(toMock, new ObjectMethodsFilter(
+ toMock, new MockInvocationHandler(this), null));
+ } catch (RuntimeExceptionWrapper e) {
+ throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
+ }
+ }
+
+ public <T> T createMock(String name, Class<T> toMock) {
+ try {
+ state.assertRecordState();
+ IProxyFactory<T> proxyFactory = createProxyFactory(toMock);
+ return proxyFactory.createProxy(toMock, new ObjectMethodsFilter(
+ toMock, new MockInvocationHandler(this), name));
+ } catch (RuntimeExceptionWrapper e) {
+ throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
+ }
+ }
+
+ protected <T> IProxyFactory<T> createProxyFactory(Class<T> toMock) {
+ return new JavaProxyFactory<T>();
+ }
+
+ public final void reset() {
+ behavior = new MocksBehavior(type == MockType.NICE);
+ behavior.checkOrder(type == MockType.STRICT);
+ state = new RecordState(behavior);
+ LastControl.reportLastControl(null);
+ }
+
+ public void resetToNice() {
+ type = MockType.NICE;
+ reset();
+ }
+
+ public void resetToDefault() {
+ type = MockType.DEFAULT;
+ reset();
+ }
+
+ public void resetToStrict() {
+ type = MockType.STRICT;
+ reset();
+ }
+
+ public void replay() {
+ try {
+ state.replay();
+ state = new ReplayState(behavior);
+ LastControl.reportLastControl(null);
+ } catch (RuntimeExceptionWrapper e) {
+ throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
+ }
+ }
+
+ public void verify() {
+ try {
+ state.verify();
+ } catch (RuntimeExceptionWrapper e) {
+ throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
+ } catch (AssertionErrorWrapper e) {
+ throw (AssertionError) e.getAssertionError().fillInStackTrace();
+ }
+ }
+
+ public void checkOrder(boolean value) {
+ try {
+ state.checkOrder(value);
+ } catch (RuntimeExceptionWrapper e) {
+ throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
+ }
+ }
+
+ public void makeThreadSafe(boolean threadSafe) {
+ try {
+ state.makeThreadSafe(threadSafe);
+ } catch (RuntimeExceptionWrapper e) {
+ throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
+ }
+ }
+
+ public void checkIsUsedInOneThread(boolean shouldBeUsedInOneThread) {
+ try {
+ state.checkIsUsedInOneThread(shouldBeUsedInOneThread);
+ } catch (RuntimeExceptionWrapper e) {
+ throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
+ }
+ }
+
+ // methods from IBehaviorSetters
+
+ public IExpectationSetters<Object> andReturn(Object value) {
+ try {
+ state.andReturn(value);
+ return this;
+ } catch (RuntimeExceptionWrapper e) {
+ throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
+ }
+ }
+
+ public IExpectationSetters<Object> andThrow(Throwable throwable) {
+ try {
+ state.andThrow(throwable);
+ return this;
+ } catch (RuntimeExceptionWrapper e) {
+ throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
+ }
+ }
+
+ public IExpectationSetters<Object> andAnswer(IAnswer<? extends Object> answer) {
+ try {
+ state.andAnswer(answer);
+ return this;
+ } catch (RuntimeExceptionWrapper e) {
+ throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
+ }
+ }
+
+ public IExpectationSetters<Object> andDelegateTo(Object answer) {
+ try {
+ state.andDelegateTo(answer);
+ return this;
+ } catch (RuntimeExceptionWrapper e) {
+ throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
+ }
+ }
+
+ public void andStubReturn(Object value) {
+ try {
+ state.andStubReturn(value);
+ } catch (RuntimeExceptionWrapper e) {
+ throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
+ }
+ }
+
+ public void andStubThrow(Throwable throwable) {
+ try {
+ state.andStubThrow(throwable);
+ } catch (RuntimeExceptionWrapper e) {
+ throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
+ }
+ }
+
+ public void andStubAnswer(IAnswer<? extends Object> answer) {
+ try {
+ state.andStubAnswer(answer);
+ } catch (RuntimeExceptionWrapper e) {
+ throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
+ }
+ }
+
+
+ public void andStubDelegateTo(Object delegateTo) {
+ try {
+ state.andStubDelegateTo(delegateTo);
+ } catch (RuntimeExceptionWrapper e) {
+ throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
+ }
+ }
+
+ public void asStub() {
+ try {
+ state.asStub();
+ } catch (RuntimeExceptionWrapper e) {
+ throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
+ }
+ }
+
+ public IExpectationSetters<Object> times(int times) {
+ try {
+ state.times(new Range(times));
+ return this;
+ } catch (RuntimeExceptionWrapper e) {
+ throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
+ }
+ }
+
+ public IExpectationSetters<Object> times(int min, int max) {
+ try {
+ state.times(new Range(min, max));
+ return this;
+ } catch (RuntimeExceptionWrapper e) {
+ throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
+ }
+ }
+
+ public IExpectationSetters<Object> once() {
+ try {
+ state.times(ONCE);
+ return this;
+ } catch (RuntimeExceptionWrapper e) {
+ throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
+ }
+ }
+
+ public IExpectationSetters<Object> atLeastOnce() {
+ try {
+ state.times(AT_LEAST_ONCE);
+ return this;
+ } catch (RuntimeExceptionWrapper e) {
+ throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
+ }
+ }
+
+ public IExpectationSetters<Object> anyTimes() {
+ try {
+ state.times(ZERO_OR_MORE);
+ return this;
+ } catch (RuntimeExceptionWrapper e) {
+ throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
+ }
+ }
+
+ /**
+ * Exactly one call.
+ */
+ public static final Range ONCE = new Range(1);
+
+ /**
+ * One or more calls.
+ */
+ public static final Range AT_LEAST_ONCE = new Range(1, Integer.MAX_VALUE);
+
+ /**
+ * Zero or more calls.
+ */
+ public static final Range ZERO_OR_MORE = new Range(0, Integer.MAX_VALUE);
+
+ @SuppressWarnings("deprecation")
+ public void setLegacyDefaultMatcher(org.easymock.ArgumentsMatcher matcher) {
+ try {
+ state.setDefaultMatcher(matcher);
+ } catch (RuntimeExceptionWrapper e) {
+ throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
+ }
+ }
+
+ @SuppressWarnings("deprecation")
+ public void setLegacyMatcher(org.easymock.ArgumentsMatcher matcher) {
+ try {
+ state.setMatcher(null, matcher);
+ } catch (RuntimeExceptionWrapper e) {
+ throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
+ }
+ }
+
+ public void setLegacyDefaultReturnValue(Object value) {
+ try {
+ state.setDefaultReturnValue(value);
+ } catch (RuntimeExceptionWrapper e) {
+ throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
+ }
+ }
+
+ public void setLegacyDefaultVoidCallable() {
+ state.setDefaultVoidCallable();
+ }
+
+ public void setLegacyDefaultThrowable(Throwable throwable) {
+ try {
+ state.setDefaultThrowable(throwable);
+ } catch (RuntimeExceptionWrapper e) {
+ throw (RuntimeException) e.getRuntimeException().fillInStackTrace();
+ }
+ }
+}
diff --git a/src/org/easymock/internal/ObjectMethodsFilter.java b/src/org/easymock/internal/ObjectMethodsFilter.java
new file mode 100644
index 0000000..a562540
--- /dev/null
+++ b/src/org/easymock/internal/ObjectMethodsFilter.java
@@ -0,0 +1,109 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal;
+
+import java.io.IOException;
+import java.io.Serializable;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+public class ObjectMethodsFilter implements InvocationHandler, Serializable {
+
+ private static final long serialVersionUID = -2120581954279966998L;
+
+ private transient Method equalsMethod;
+
+ private transient Method hashCodeMethod;
+
+ private transient Method toStringMethod;
+
+ private final MockInvocationHandler delegate;
+
+ private final String name;
+
+ public ObjectMethodsFilter(Class<?> toMock, MockInvocationHandler delegate,
+ String name) {
+ if (name != null && !Invocation.isJavaIdentifier(name)) {
+ throw new IllegalArgumentException(String.format("'%s' is not a valid Java identifier.", name));
+
+ }
+ try {
+ if (toMock.isInterface()) {
+ toMock = Object.class;
+ }
+ equalsMethod = toMock.getMethod("equals",
+ new Class[] { Object.class });
+ hashCodeMethod = toMock.getMethod("hashCode", (Class[]) null);
+ toStringMethod = toMock.getMethod("toString", (Class[]) null);
+ } catch (NoSuchMethodException e) {
+ // ///CLOVER:OFF
+ throw new RuntimeException("An Object method could not be found!");
+ // ///CLOVER:ON
+ }
+ this.delegate = delegate;
+ this.name = name;
+ }
+
+ public final Object invoke(Object proxy, Method method, Object[] args)
+ throws Throwable {
+ if (equalsMethod.equals(method)) {
+ return Boolean.valueOf(proxy == args[0]);
+ }
+ if (hashCodeMethod.equals(method)) {
+ return Integer.valueOf(System.identityHashCode(proxy));
+ }
+ if (toStringMethod.equals(method)) {
+ return mockToString(proxy);
+ }
+ return delegate.invoke(proxy, method, args);
+ }
+
+ private String mockToString(Object proxy) {
+ return (name != null) ? name : "EasyMock for " + mockType(proxy);
+ }
+
+ private String mockType(Object proxy) {
+ if (Proxy.isProxyClass(proxy.getClass()))
+ return proxy.getClass().getInterfaces()[0].toString();
+ else
+ return proxy.getClass().getSuperclass().toString();
+ }
+
+ public MockInvocationHandler getDelegate() {
+ return delegate;
+ }
+
+ private void readObject(java.io.ObjectInputStream stream) throws IOException, ClassNotFoundException {
+ stream.defaultReadObject();
+ try {
+ toStringMethod = ((MethodSerializationWrapper) stream.readObject()).getMethod();
+ equalsMethod = ((MethodSerializationWrapper) stream.readObject()).getMethod();
+ hashCodeMethod = ((MethodSerializationWrapper) stream.readObject()).getMethod();
+ } catch (NoSuchMethodException e) {
+ // ///CLOVER:OFF
+ throw new IOException(e.toString());
+ // ///CLOVER:ON
+ }
+ }
+
+ private void writeObject(java.io.ObjectOutputStream stream) throws IOException {
+ stream.defaultWriteObject();
+ stream.writeObject(new MethodSerializationWrapper(toStringMethod));
+ stream.writeObject(new MethodSerializationWrapper(equalsMethod));
+ stream.writeObject(new MethodSerializationWrapper(hashCodeMethod));
+ }
+} \ No newline at end of file
diff --git a/src/org/easymock/internal/Range.java b/src/org/easymock/internal/Range.java
new file mode 100644
index 0000000..bd9dd96
--- /dev/null
+++ b/src/org/easymock/internal/Range.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal;
+
+import java.io.Serializable;
+
+public class Range implements Serializable {
+
+ private static final long serialVersionUID = -6743402320315331536L;
+
+ private final int minimum;
+
+ private final int maximum;
+
+ public Range(int count) {
+ this(count, count);
+ }
+
+ public Range(int minimum, int maximum) {
+ if (!(minimum <= maximum)) {
+ throw new RuntimeExceptionWrapper(new IllegalArgumentException(
+ "minimum must be <= maximum"));
+ }
+
+ if (!(minimum >= 0)) {
+ throw new RuntimeExceptionWrapper(new IllegalArgumentException(
+ "minimum must be >= 0"));
+ }
+
+ if (!(maximum >= 1)) {
+ throw new RuntimeExceptionWrapper(new IllegalArgumentException(
+ "maximum must be >= 1"));
+ }
+ this.minimum = minimum;
+ this.maximum = maximum;
+ }
+
+ public boolean hasFixedCount() {
+ return minimum == maximum;
+ }
+
+ public int getMaximum() {
+ return maximum;
+ }
+
+ public int getMinimum() {
+ return minimum;
+ }
+
+ @Override
+ public String toString() {
+ if (hasFixedCount()) {
+ return "" + minimum;
+ } else if (hasOpenCount()) {
+ return "at least " + minimum;
+ } else {
+ return "between " + minimum + " and " + maximum;
+ }
+ }
+
+ public String expectedCount() {
+ return "expected: " + this.toString();
+ }
+
+ public boolean contains(int count) {
+ return minimum <= count && count <= maximum;
+ }
+
+ public boolean hasOpenCount() {
+ return maximum == Integer.MAX_VALUE;
+ }
+}
diff --git a/src/org/easymock/internal/RecordState.java b/src/org/easymock/internal/RecordState.java
new file mode 100644
index 0000000..433b40e
--- /dev/null
+++ b/src/org/easymock/internal/RecordState.java
@@ -0,0 +1,389 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal;
+
+import java.io.Serializable;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.easymock.IAnswer;
+import org.easymock.IArgumentMatcher;
+
+public class RecordState implements IMocksControlState, Serializable {
+
+ private static final long serialVersionUID = -5418279681566430252L;
+
+ private ExpectedInvocation lastInvocation = null;
+
+ private boolean lastInvocationUsed = true;
+
+ private Result lastResult;
+
+ private final IMocksBehavior behavior;
+
+ private static Map<Class<?>, Object> emptyReturnValues = new HashMap<Class<?>, Object>();
+
+ static {
+ emptyReturnValues.put(Void.TYPE, null);
+ emptyReturnValues.put(Boolean.TYPE, Boolean.FALSE);
+ emptyReturnValues.put(Byte.TYPE, Byte.valueOf((byte) 0));
+ emptyReturnValues.put(Short.TYPE, Short.valueOf((short) 0));
+ emptyReturnValues.put(Character.TYPE, Character.valueOf((char)0));
+ emptyReturnValues.put(Integer.TYPE, Integer.valueOf(0));
+ emptyReturnValues.put(Long.TYPE, Long.valueOf(0));
+ emptyReturnValues.put(Float.TYPE, Float.valueOf(0));
+ emptyReturnValues.put(Double.TYPE, Double.valueOf(0));
+ }
+
+ private static Map<Class<?>, Class<?>> primitiveToWrapperType = new HashMap<Class<?>, Class<?>>();
+
+ static {
+ primitiveToWrapperType.put(Boolean.TYPE, Boolean.class);
+ primitiveToWrapperType.put(Byte.TYPE, Byte.class);
+ primitiveToWrapperType.put(Short.TYPE, Short.class);
+ primitiveToWrapperType.put(Character.TYPE, Character.class);
+ primitiveToWrapperType.put(Integer.TYPE, Integer.class);
+ primitiveToWrapperType.put(Long.TYPE, Long.class);
+ primitiveToWrapperType.put(Float.TYPE, Float.class);
+ primitiveToWrapperType.put(Double.TYPE, Double.class);
+ }
+
+ public RecordState(IMocksBehavior behavior) {
+ this.behavior = behavior;
+ }
+
+ public void assertRecordState() {
+ }
+
+ public java.lang.Object invoke(Invocation invocation) {
+ closeMethod();
+ List<IArgumentMatcher> lastMatchers = LastControl.pullMatchers();
+ lastInvocation = new ExpectedInvocation(invocation, lastMatchers);
+ lastInvocationUsed = false;
+ return emptyReturnValueFor(invocation.getMethod().getReturnType());
+ }
+
+ public void replay() {
+ closeMethod();
+ if (LastControl.pullMatchers() != null) {
+ throw new IllegalStateException("matcher calls were used outside expectations");
+ }
+ }
+
+ public void verify() {
+ throw new RuntimeExceptionWrapper(new IllegalStateException(
+ "calling verify is not allowed in record state"));
+ }
+
+ public void andReturn(Object value) {
+ requireMethodCall("return value");
+ value = convertNumberClassIfNeccessary(value);
+ requireAssignable(value);
+ if (lastResult != null) {
+ times(MocksControl.ONCE);
+ }
+ lastResult = Result.createReturnResult(value);
+ }
+
+ public void andThrow(Throwable throwable) {
+ requireMethodCall("Throwable");
+ requireValidThrowable(throwable);
+ if (lastResult != null) {
+ times(MocksControl.ONCE);
+ }
+ lastResult = Result.createThrowResult(throwable);
+ }
+
+ public void andAnswer(IAnswer<?> answer) {
+ requireMethodCall("answer");
+ requireValidAnswer(answer);
+ if (lastResult != null) {
+ times(MocksControl.ONCE);
+ }
+ lastResult = Result.createAnswerResult(answer);
+ }
+
+ public void andDelegateTo(Object delegateTo) {
+ requireMethodCall("delegate");
+ requireValidDelegation(delegateTo);
+ if (lastResult != null) {
+ times(MocksControl.ONCE);
+ }
+ lastResult = Result.createDelegatingResult(delegateTo);
+ }
+
+ public void andStubReturn(Object value) {
+ requireMethodCall("stub return value");
+ value = convertNumberClassIfNeccessary(value);
+ requireAssignable(value);
+ if (lastResult != null) {
+ times(MocksControl.ONCE);
+ }
+ behavior.addStub(lastInvocation, Result.createReturnResult(value));
+ lastInvocationUsed = true;
+ }
+
+ @SuppressWarnings("deprecation")
+ public void setDefaultReturnValue(Object value) {
+ requireMethodCall("default return value");
+ value = convertNumberClassIfNeccessary(value);
+ requireAssignable(value);
+ if (lastResult != null) {
+ times(MocksControl.ONCE);
+ }
+ behavior.addStub(
+ lastInvocation.withMatcher(org.easymock.MockControl.ALWAYS_MATCHER), Result
+ .createReturnResult(value));
+ lastInvocationUsed = true;
+ }
+
+ public void asStub() {
+ requireMethodCall("stub behavior");
+ requireVoidMethod();
+ behavior.addStub(lastInvocation, Result.createReturnResult(null));
+ lastInvocationUsed = true;
+ }
+
+ @SuppressWarnings("deprecation")
+ public void setDefaultVoidCallable() {
+ requireMethodCall("default void callable");
+ requireVoidMethod();
+ behavior.addStub(
+ lastInvocation.withMatcher(org.easymock.MockControl.ALWAYS_MATCHER), Result
+ .createReturnResult(null));
+ lastInvocationUsed = true;
+ }
+
+ public void andStubThrow(Throwable throwable) {
+ requireMethodCall("stub Throwable");
+ requireValidThrowable(throwable);
+ if (lastResult != null) {
+ times(MocksControl.ONCE);
+ }
+ behavior.addStub(lastInvocation, Result.createThrowResult(throwable));
+ lastInvocationUsed = true;
+ }
+
+ @SuppressWarnings("deprecation")
+ public void setDefaultThrowable(Throwable throwable) {
+ requireMethodCall("default Throwable");
+ requireValidThrowable(throwable);
+ if (lastResult != null) {
+ times(MocksControl.ONCE);
+ }
+ behavior.addStub(
+ lastInvocation.withMatcher(org.easymock.MockControl.ALWAYS_MATCHER), Result
+ .createThrowResult(throwable));
+ lastInvocationUsed = true;
+ }
+
+ public void andStubAnswer(IAnswer<?> answer) {
+ requireMethodCall("stub answer");
+ requireValidAnswer(answer);
+ if (lastResult != null) {
+ times(MocksControl.ONCE);
+ }
+ behavior.addStub(lastInvocation, Result.createAnswerResult(answer));
+ lastInvocationUsed = true;
+ }
+
+ public void andStubDelegateTo(Object delegateTo) {
+ requireMethodCall("stub delegate");
+ requireValidDelegation(delegateTo);
+ if (lastResult != null) {
+ times(MocksControl.ONCE);
+ }
+ behavior.addStub(lastInvocation, Result
+ .createDelegatingResult(delegateTo));
+ lastInvocationUsed = true;
+ }
+
+ public void times(Range range) {
+ requireMethodCall("times");
+ requireLastResultOrVoidMethod();
+
+ behavior.addExpected(lastInvocation, lastResult != null ? lastResult
+ : Result.createReturnResult(null), range);
+ lastInvocationUsed = true;
+ lastResult = null;
+ }
+
+ private Object createNumberObject(Object value, Class<?> returnType) {
+ if (!(value instanceof Number)) {
+ return value;
+ }
+ Number number = (Number) value;
+ if (returnType.equals(Byte.TYPE)) {
+ return number.byteValue();
+ } else if (returnType.equals(Short.TYPE)) {
+ return number.shortValue();
+ } else if (returnType.equals(Character.TYPE)) {
+ return (char) number.intValue();
+ } else if (returnType.equals(Integer.TYPE)) {
+ return number.intValue();
+ } else if (returnType.equals(Long.TYPE)) {
+ return number.longValue();
+ } else if (returnType.equals(Float.TYPE)) {
+ return number.floatValue();
+ } else if (returnType.equals(Double.TYPE)) {
+ return number.doubleValue();
+ } else {
+ return number;
+ }
+ }
+
+ private Object convertNumberClassIfNeccessary(Object o) {
+ Class<?> returnType = lastInvocation.getMethod().getReturnType();
+ return createNumberObject(o, returnType);
+ }
+
+ @SuppressWarnings("deprecation")
+ private void closeMethod() {
+ if (lastInvocationUsed && lastResult == null) {
+ return;
+ }
+ if (!isLastResultOrVoidMethod()) {
+ throw new RuntimeExceptionWrapper(new IllegalStateException(
+ "missing behavior definition for the preceding method call "
+ + lastInvocation.toString()));
+ }
+ this.times(org.easymock.MockControl.ONE);
+ }
+
+ public static Object emptyReturnValueFor(Class<?> type) {
+ return type.isPrimitive() ? emptyReturnValues.get(type) : null;
+ }
+
+ private void requireMethodCall(String failMessage) {
+ if (lastInvocation == null) {
+ throw new RuntimeExceptionWrapper(new IllegalStateException(
+ "method call on the mock needed before setting "
+ + failMessage));
+ }
+ }
+
+ private void requireAssignable(Object returnValue) {
+ if (lastMethodIsVoidMethod()) {
+ throw new RuntimeExceptionWrapper(new IllegalStateException(
+ "void method cannot return a value"));
+ }
+ if (returnValue == null) {
+ return;
+ }
+ Class<?> returnedType = lastInvocation.getMethod().getReturnType();
+ if (returnedType.isPrimitive()) {
+ returnedType = primitiveToWrapperType.get(returnedType);
+
+ }
+ if (!returnedType.isAssignableFrom(returnValue.getClass())) {
+ throw new RuntimeExceptionWrapper(new IllegalStateException(
+ "incompatible return value type"));
+ }
+ }
+
+ private void requireValidThrowable(Throwable throwable) {
+ if (throwable == null)
+ throw new RuntimeExceptionWrapper(new NullPointerException(
+ "null cannot be thrown"));
+ if (isValidThrowable(throwable))
+ return;
+
+ throw new RuntimeExceptionWrapper(new IllegalArgumentException(
+ "last method called on mock cannot throw "
+ + throwable.getClass().getName()));
+ }
+
+ private void requireValidAnswer(IAnswer<?> answer) {
+ if (answer == null)
+ throw new RuntimeExceptionWrapper(new NullPointerException(
+ "answer object must not be null"));
+ }
+
+ private void requireValidDelegation(Object delegateTo) {
+ if (delegateTo == null)
+ throw new RuntimeExceptionWrapper(new NullPointerException(
+ "delegated to object must not be null"));
+ // Would be nice to validate delegateTo is implementing the mock
+ // interface (not possible right now)
+ }
+
+ private void requireLastResultOrVoidMethod() {
+ if (isLastResultOrVoidMethod()) {
+ return;
+ }
+ throw new RuntimeExceptionWrapper(new IllegalStateException(
+ "last method called on mock is not a void method"));
+ }
+
+ private void requireVoidMethod() {
+ if (lastMethodIsVoidMethod()) {
+ return;
+ }
+ throw new RuntimeExceptionWrapper(new IllegalStateException(
+ "last method called on mock is not a void method"));
+ }
+
+ private boolean isLastResultOrVoidMethod() {
+ return lastResult != null || lastMethodIsVoidMethod();
+ }
+
+ private boolean lastMethodIsVoidMethod() {
+ Class<?> returnType = lastInvocation.getMethod().getReturnType();
+ return returnType.equals(Void.TYPE);
+ }
+
+ private boolean isValidThrowable(Throwable throwable) {
+ if (throwable instanceof RuntimeException) {
+ return true;
+ }
+ if (throwable instanceof Error) {
+ return true;
+ }
+ Class<?>[] exceptions = lastInvocation.getMethod().getExceptionTypes();
+ Class<?> throwableClass = throwable.getClass();
+ for (Class<?> exception : exceptions) {
+ if (exception.isAssignableFrom(throwableClass))
+ return true;
+ }
+ return false;
+ }
+
+ public void checkOrder(boolean value) {
+ closeMethod();
+ behavior.checkOrder(value);
+ }
+
+ public void makeThreadSafe(boolean threadSafe) {
+ behavior.makeThreadSafe(threadSafe);
+ }
+
+ public void checkIsUsedInOneThread(boolean shouldBeUsedInOneThread) {
+ behavior.shouldBeUsedInOneThread(shouldBeUsedInOneThread);
+ }
+
+ @SuppressWarnings("deprecation")
+ public void setDefaultMatcher(org.easymock.ArgumentsMatcher matcher) {
+ behavior.setDefaultMatcher(matcher);
+ }
+
+ @SuppressWarnings("deprecation")
+ public void setMatcher(Method method, org.easymock.ArgumentsMatcher matcher) {
+ requireMethodCall("matcher");
+ behavior.setMatcher(lastInvocation.getMethod(), matcher);
+ }
+} \ No newline at end of file
diff --git a/src/org/easymock/internal/ReplayState.java b/src/org/easymock/internal/ReplayState.java
new file mode 100644
index 0000000..c0462e2
--- /dev/null
+++ b/src/org/easymock/internal/ReplayState.java
@@ -0,0 +1,165 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal;
+
+import java.io.Serializable;
+import java.lang.reflect.Method;
+import java.util.concurrent.locks.ReentrantLock;
+
+import org.easymock.IAnswer;
+
+public class ReplayState implements IMocksControlState, Serializable {
+
+ private static final long serialVersionUID = 6314142602251047572L;
+
+ private final IMocksBehavior behavior;
+
+ private final ReentrantLock lock = new ReentrantLock();
+
+ public ReplayState(IMocksBehavior behavior) {
+ this.behavior = behavior;
+ }
+
+ public Object invoke(Invocation invocation) throws Throwable {
+
+ behavior.checkThreadSafety();
+
+ if (behavior.isThreadSafe()) {
+ // If thread safe, synchronize the mock
+ lock.lock();
+ try {
+ return invokeInner(invocation);
+ }
+ finally {
+ lock.unlock();
+ }
+ }
+
+ return invokeInner(invocation);
+ }
+
+ private Object invokeInner(Invocation invocation) throws Throwable {
+ LastControl.pushCurrentInvocation(invocation);
+ try {
+ Result result = behavior.addActual(invocation);
+ try {
+ return result.answer();
+ } catch (Throwable t) {
+ if (result.shouldFillInStackTrace()) {
+ throw new ThrowableWrapper(t);
+ }
+ throw t;
+ }
+ } finally {
+ LastControl.popCurrentInvocation();
+ }
+ }
+
+ public void verify() {
+ behavior.verify();
+ }
+
+ public void replay() {
+ throwWrappedIllegalStateException();
+ }
+
+ public void callback(Runnable runnable) {
+ throwWrappedIllegalStateException();
+ }
+
+ public void checkOrder(boolean value) {
+ throwWrappedIllegalStateException();
+ }
+
+ public void makeThreadSafe(boolean threadSafe) {
+ throwWrappedIllegalStateException();
+ }
+
+ public void checkIsUsedInOneThread(boolean shouldBeUsedInOneThread) {
+ throwWrappedIllegalStateException();
+ }
+
+ public void andReturn(Object value) {
+ throwWrappedIllegalStateException();
+ }
+
+ public void andThrow(Throwable throwable) {
+ throwWrappedIllegalStateException();
+ }
+
+ public void andAnswer(IAnswer<?> answer) {
+ throwWrappedIllegalStateException();
+ }
+
+ public void andDelegateTo(Object answer) {
+ throwWrappedIllegalStateException();
+ }
+
+ public void andStubReturn(Object value) {
+ throwWrappedIllegalStateException();
+ }
+
+ public void andStubThrow(Throwable throwable) {
+ throwWrappedIllegalStateException();
+ }
+
+ public void andStubAnswer(IAnswer<?> answer) {
+ throwWrappedIllegalStateException();
+ }
+
+ public void andStubDelegateTo(Object delegateTo) {
+ throwWrappedIllegalStateException();
+ }
+
+ public void asStub() {
+ throwWrappedIllegalStateException();
+ }
+
+ public void times(Range range) {
+ throwWrappedIllegalStateException();
+ }
+
+ @SuppressWarnings("deprecation")
+ public void setMatcher(Method method, org.easymock.ArgumentsMatcher matcher) {
+ throwWrappedIllegalStateException();
+ }
+
+ @SuppressWarnings("deprecation")
+ public void setDefaultMatcher(org.easymock.ArgumentsMatcher matcher) {
+ throwWrappedIllegalStateException();
+ }
+
+ public void setDefaultReturnValue(Object value) {
+ throwWrappedIllegalStateException();
+ }
+
+ public void setDefaultThrowable(Throwable throwable) {
+ throwWrappedIllegalStateException();
+ }
+
+ public void setDefaultVoidCallable() {
+ throwWrappedIllegalStateException();
+ }
+
+ private void throwWrappedIllegalStateException() {
+ throw new RuntimeExceptionWrapper(new IllegalStateException(
+ "This method must not be called in replay state."));
+ }
+
+ public void assertRecordState() {
+ throwWrappedIllegalStateException();
+ }
+}
diff --git a/src/org/easymock/internal/Result.java b/src/org/easymock/internal/Result.java
new file mode 100644
index 0000000..9ad26b4
--- /dev/null
+++ b/src/org/easymock/internal/Result.java
@@ -0,0 +1,114 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal;
+
+import java.io.Serializable;
+import java.lang.reflect.InvocationTargetException;
+
+import org.easymock.IAnswer;
+
+public class Result implements IAnswer<Object>, Serializable {
+
+ private static final long serialVersionUID = 5476251941213917681L;
+
+ private final IAnswer<?> value;
+
+ private final boolean shouldFillInStackTrace;
+
+ private Result(IAnswer<?> value, boolean shouldFillInStackTrace) {
+ this.value = value;
+ this.shouldFillInStackTrace = shouldFillInStackTrace;
+ }
+
+ public static Result createThrowResult(final Throwable throwable) {
+ class ThrowingAnswer implements IAnswer<Object>, Serializable {
+
+ private static final long serialVersionUID = -332797751209289222L;
+
+ public Object answer() throws Throwable {
+ throw throwable;
+ }
+
+ @Override
+ public String toString() {
+ return "Answer throwing " + throwable;
+ }
+ }
+ return new Result(new ThrowingAnswer(), true);
+ }
+
+ public static Result createReturnResult(final Object value) {
+ class ReturningAnswer implements IAnswer<Object>, Serializable {
+
+ private static final long serialVersionUID = 6973893913593916866L;
+
+ public Object answer() throws Throwable {
+ return value;
+ }
+
+ @Override
+ public String toString() {
+ return "Answer returning " + value;
+ }
+ }
+ return new Result(new ReturningAnswer(), true);
+ }
+
+ public static Result createDelegatingResult(final Object value) {
+ class DelegatingAnswer implements IAnswer<Object>, Serializable {
+
+ private static final long serialVersionUID = -5699326678580460103L;
+
+ public Object answer() throws Throwable {
+ Invocation invocation = LastControl.getCurrentInvocation();
+ try {
+ return invocation.getMethod().invoke(value,
+ invocation.getArguments());
+ } catch (IllegalArgumentException e) {
+ throw new IllegalArgumentException("Delegation to object ["
+ + String.valueOf(value)
+ + "] is not implementing the mocked method ["
+ + invocation.getMethod() + "]", e);
+ } catch (InvocationTargetException e) {
+ throw e.getCause();
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "Delegated to " + value;
+ }
+ }
+ return new Result(new DelegatingAnswer(), false);
+ }
+
+ public static Result createAnswerResult(IAnswer<?> answer) {
+ return new Result(answer, false);
+ }
+
+ public Object answer() throws Throwable {
+ return value.answer();
+ }
+
+ public boolean shouldFillInStackTrace() {
+ return shouldFillInStackTrace;
+ }
+
+ @Override
+ public String toString() {
+ return value.toString();
+ }
+}
diff --git a/src/org/easymock/internal/Results.java b/src/org/easymock/internal/Results.java
new file mode 100644
index 0000000..2f83769
--- /dev/null
+++ b/src/org/easymock/internal/Results.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.LinkedList;
+import java.util.List;
+
+public class Results implements Serializable {
+
+ private static final long serialVersionUID = -2722051869610289637L;
+
+ private int callCount;
+
+ private final LinkedList<Range> ranges = new LinkedList<Range>();
+
+ private final List<Result> results = new ArrayList<Result>();
+
+ public void add(Result result, Range range) {
+ if (!ranges.isEmpty()) {
+ Range lastRange = ranges.getLast();
+ if (!lastRange.hasFixedCount())
+ throw new RuntimeExceptionWrapper(
+ new IllegalStateException(
+ "last method called on mock already has a non-fixed count set."));
+ }
+ ranges.add(range);
+ results.add(result);
+ }
+
+ public Result next() {
+ int currentPosition = 0;
+ for (int i = 0; i < ranges.size(); i++) {
+ Range interval = ranges.get(i);
+ if (interval.hasOpenCount()) {
+ callCount += 1;
+ return results.get(i);
+ }
+ currentPosition += interval.getMaximum();
+ if (currentPosition > callCount) {
+ callCount += 1;
+ return results.get(i);
+ }
+ }
+ return null;
+ }
+
+ public boolean hasValidCallCount() {
+ return getMainInterval().contains(getCallCount());
+ }
+
+ @Override
+ public String toString() {
+ return getMainInterval().expectedCount();
+ }
+
+ private Range getMainInterval() {
+ int min = 0, max = 0;
+
+ for (Range interval : ranges) {
+ min += interval.getMinimum();
+ if (interval.hasOpenCount() || max == Integer.MAX_VALUE) {
+ max = Integer.MAX_VALUE;
+ } else {
+ max += interval.getMaximum();
+ }
+ }
+
+ return new Range(min, max);
+ }
+
+ public int getCallCount() {
+ return callCount;
+ }
+}
diff --git a/src/org/easymock/internal/RuntimeExceptionWrapper.java b/src/org/easymock/internal/RuntimeExceptionWrapper.java
new file mode 100644
index 0000000..8c0e48a
--- /dev/null
+++ b/src/org/easymock/internal/RuntimeExceptionWrapper.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal;
+
+public class RuntimeExceptionWrapper extends RuntimeException {
+
+ private static final long serialVersionUID = -3483500330975410177L;
+
+ private final RuntimeException runtimeException;
+
+ public RuntimeExceptionWrapper(final RuntimeException runtimeException) {
+ this.runtimeException = runtimeException;
+ }
+
+ public RuntimeException getRuntimeException() {
+ return runtimeException;
+ }
+}
diff --git a/src/org/easymock/internal/ThrowableWrapper.java b/src/org/easymock/internal/ThrowableWrapper.java
new file mode 100644
index 0000000..7bf1555
--- /dev/null
+++ b/src/org/easymock/internal/ThrowableWrapper.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal;
+
+public class ThrowableWrapper extends Throwable {
+
+ private static final long serialVersionUID = -4434322855124959723L;
+
+ private final Throwable throwable;
+
+ public ThrowableWrapper(final Throwable throwable) {
+ this.throwable = throwable;
+ }
+
+ public Throwable getThrowable() {
+ return throwable;
+ }
+}
diff --git a/src/org/easymock/internal/UnorderedBehavior.java b/src/org/easymock/internal/UnorderedBehavior.java
new file mode 100644
index 0000000..39695ef
--- /dev/null
+++ b/src/org/easymock/internal/UnorderedBehavior.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+public class UnorderedBehavior implements Serializable {
+
+ private static final long serialVersionUID = 2185791334636597469L;
+
+ private final List<ExpectedInvocationAndResults> results = new ArrayList<ExpectedInvocationAndResults>();
+
+ private final boolean checkOrder;
+
+ public UnorderedBehavior(boolean checkOrder) {
+ this.checkOrder = checkOrder;
+ }
+
+ public void addExpected(ExpectedInvocation expected, Result result,
+ Range count) {
+ for (ExpectedInvocationAndResults entry : results) {
+ if (entry.getExpectedInvocation().equals(expected)) {
+ entry.getResults().add(result, count);
+ return;
+ }
+ }
+ Results list = new Results();
+ list.add(result, count);
+ results.add(new ExpectedInvocationAndResults(expected, list));
+ }
+
+ public Result addActual(Invocation actual) {
+ for (ExpectedInvocationAndResults entry : results) {
+ try {
+ if (!entry.getExpectedInvocation().matches(actual)) {
+ continue;
+ }
+ Result result = entry.getResults().next();
+ if (result != null) {
+ // actual and expected matched, validate the capture
+ actual.validateCaptures();
+ return result;
+ }
+ }
+ finally {
+ // reset the capture (already validated or expected didn't
+ // matched)
+ actual.clearCaptures();
+ }
+ }
+ return null;
+ }
+
+ public boolean verify() {
+ for (ExpectedInvocationAndResults entry : results) {
+ if (!entry.getResults().hasValidCallCount()) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public List<ErrorMessage> getMessages(Invocation invocation) {
+ List<ErrorMessage> messages = new ArrayList<ErrorMessage>(results
+ .size());
+ for (ExpectedInvocationAndResults entry : results) {
+ boolean unordered = !checkOrder;
+ boolean validCallCount = entry.getResults().hasValidCallCount();
+ boolean match = invocation != null
+ && entry.getExpectedInvocation().matches(invocation);
+
+ if (unordered && validCallCount && !match) {
+ continue;
+ }
+
+ ErrorMessage message = new ErrorMessage(match, entry.toString(),
+ entry.getResults()
+ .getCallCount());
+ messages.add(message);
+ }
+ return messages;
+
+ }
+
+ public boolean allowsExpectedInvocation(ExpectedInvocation expected,
+ boolean checkOrder) {
+ if (this.checkOrder != checkOrder) {
+ return false;
+ } else if (results.isEmpty() || !this.checkOrder) {
+ return true;
+ } else {
+ ExpectedInvocation lastMethodCall = results.get(results.size() - 1)
+ .getExpectedInvocation();
+ return lastMethodCall.equals(expected);
+ }
+ }
+
+} \ No newline at end of file
diff --git a/src/org/easymock/internal/matchers/And.java b/src/org/easymock/internal/matchers/And.java
new file mode 100644
index 0000000..555ffe5
--- /dev/null
+++ b/src/org/easymock/internal/matchers/And.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal.matchers;
+
+import java.io.Serializable;
+import java.util.Iterator;
+import java.util.List;
+
+import org.easymock.IArgumentMatcher;
+
+public class And implements IArgumentMatcher, Serializable {
+
+ private static final long serialVersionUID = 3874580646798403818L;
+
+ private final List<IArgumentMatcher> matchers;
+
+ public And(List<IArgumentMatcher> matchers) {
+ this.matchers = matchers;
+ }
+
+ public boolean matches(Object actual) {
+ for (IArgumentMatcher matcher : matchers) {
+ if (!matcher.matches(actual)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public void appendTo(StringBuffer buffer) {
+ buffer.append("and(");
+ for (Iterator<IArgumentMatcher> it = matchers.iterator(); it.hasNext();) {
+ it.next().appendTo(buffer);
+ if (it.hasNext()) {
+ buffer.append(", ");
+ }
+ }
+ buffer.append(")");
+ }
+}
diff --git a/src/org/easymock/internal/matchers/Any.java b/src/org/easymock/internal/matchers/Any.java
new file mode 100644
index 0000000..8fcf57c
--- /dev/null
+++ b/src/org/easymock/internal/matchers/Any.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal.matchers;
+
+import java.io.Serializable;
+
+import org.easymock.IArgumentMatcher;
+
+public class Any implements IArgumentMatcher, Serializable {
+
+ private static final long serialVersionUID = -3743894206806704049L;
+
+ public static final Any ANY = new Any();
+
+ private Any() {
+
+ }
+
+ public boolean matches(Object actual) {
+ return true;
+ }
+
+ public void appendTo(StringBuffer buffer) {
+ buffer.append("<any>");
+ }
+}
diff --git a/src/org/easymock/internal/matchers/ArrayEquals.java b/src/org/easymock/internal/matchers/ArrayEquals.java
new file mode 100644
index 0000000..9ead937
--- /dev/null
+++ b/src/org/easymock/internal/matchers/ArrayEquals.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal.matchers;
+
+import java.util.Arrays;
+
+import org.easymock.internal.ArgumentToString;
+
+public class ArrayEquals extends Equals {
+
+ private static final long serialVersionUID = 1L;
+
+ public ArrayEquals(Object expected) {
+ super(expected);
+ }
+
+ @Override
+ public boolean matches(Object actual) {
+ Object expected = getExpected();
+ if (expected instanceof boolean[]
+ && (actual == null || actual instanceof boolean[])) {
+ return Arrays.equals((boolean[]) expected, (boolean[]) actual);
+ } else if (expected instanceof byte[]
+ && (actual == null || actual instanceof byte[])) {
+ return Arrays.equals((byte[]) expected, (byte[]) actual);
+ } else if (expected instanceof char[]
+ && (actual == null || actual instanceof char[])) {
+ return Arrays.equals((char[]) expected, (char[]) actual);
+ } else if (expected instanceof double[]
+ && (actual == null || actual instanceof double[])) {
+ return Arrays.equals((double[]) expected, (double[]) actual);
+ } else if (expected instanceof float[]
+ && (actual == null || actual instanceof float[])) {
+ return Arrays.equals((float[]) expected, (float[]) actual);
+ } else if (expected instanceof int[]
+ && (actual == null || actual instanceof int[])) {
+ return Arrays.equals((int[]) expected, (int[]) actual);
+ } else if (expected instanceof long[]
+ && (actual == null || actual instanceof long[])) {
+ return Arrays.equals((long[]) expected, (long[]) actual);
+ } else if (expected instanceof short[]
+ && (actual == null || actual instanceof short[])) {
+ return Arrays.equals((short[]) expected, (short[]) actual);
+ } else if (expected instanceof Object[]
+ && (actual == null || actual instanceof Object[])) {
+ return Arrays.equals((Object[]) expected, (Object[]) actual);
+ } else {
+ return super.matches(actual);
+ }
+ }
+
+ @Override
+ public void appendTo(StringBuffer buffer) {
+ ArgumentToString.appendArgument(getExpected(), buffer);
+ }
+}
diff --git a/src/org/easymock/internal/matchers/Captures.java b/src/org/easymock/internal/matchers/Captures.java
new file mode 100644
index 0000000..5a75c0a
--- /dev/null
+++ b/src/org/easymock/internal/matchers/Captures.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2003-2009 OFFIS, Henri Tremblay
+ *
+ * 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 org.easymock.internal.matchers;
+
+import java.io.Serializable;
+
+import org.easymock.Capture;
+import org.easymock.IArgumentMatcher;
+import org.easymock.internal.LastControl;
+
+public class Captures<T> implements IArgumentMatcher, Serializable {
+
+ private static final long serialVersionUID = -5048595127450771363L;
+
+ private final Capture<T> capture;
+
+ private T potentialValue;
+
+ public Captures(Capture<T> captured) {
+ this.capture = captured;
+ }
+
+ public void appendTo(StringBuffer buffer) {
+ buffer.append("capture(").append(capture).append(")");
+ }
+
+ public void setPotentialValue(T potentialValue) {
+ this.potentialValue = potentialValue;
+ }
+
+ @SuppressWarnings("unchecked")
+ public boolean matches(Object actual) {
+ LastControl.getCurrentInvocation().addCapture((Captures<Object>) this,
+ actual);
+ return true;
+ }
+
+ public void validateCapture() {
+ capture.setValue(potentialValue);
+ }
+}
diff --git a/src/org/easymock/internal/matchers/Compare.java b/src/org/easymock/internal/matchers/Compare.java
new file mode 100644
index 0000000..9ed96a6
--- /dev/null
+++ b/src/org/easymock/internal/matchers/Compare.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2001-2009 OFFIS, Henri Tremblay
+ *
+ * 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 org.easymock.internal.matchers;
+
+import java.io.Serializable;
+import java.util.Comparator;
+
+import org.easymock.IArgumentMatcher;
+import org.easymock.LogicalOperator;
+
+public class Compare<T> implements IArgumentMatcher, Serializable {
+
+ private static final long serialVersionUID = -4859402739599754147L;
+
+ private T expected;
+
+ private Comparator<? super T> comparator;
+
+ private LogicalOperator operator;
+
+ public Compare(T expected, Comparator<? super T> comparator, LogicalOperator result) {
+ this.expected = expected;
+ this.comparator = comparator;
+ this.operator = result;
+ }
+
+ public void appendTo(StringBuffer buffer) {
+ buffer.append(comparator + "(" + expected + ") " + operator.getSymbol()
+ + " 0");
+ }
+
+ @SuppressWarnings("unchecked")
+ public boolean matches(Object actual) {
+ if(actual == null) {
+ return false;
+ }
+ return operator.matchResult(comparator.compare((T) actual, expected));
+ }
+
+}
diff --git a/src/org/easymock/internal/matchers/CompareEqual.java b/src/org/easymock/internal/matchers/CompareEqual.java
new file mode 100644
index 0000000..b62bf36
--- /dev/null
+++ b/src/org/easymock/internal/matchers/CompareEqual.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal.matchers;
+
+public class CompareEqual<T extends Comparable<T>> extends CompareTo<T> {
+
+ private static final long serialVersionUID = 7616033998227799268L;
+
+ public CompareEqual(Comparable<T> value) {
+ super(value);
+ }
+
+ @Override
+ protected String getName() {
+ return "cmpEq";
+ }
+
+ @Override
+ protected boolean matchResult(int result) {
+ return result == 0;
+ }
+}
diff --git a/src/org/easymock/internal/matchers/CompareTo.java b/src/org/easymock/internal/matchers/CompareTo.java
new file mode 100644
index 0000000..0d108e4
--- /dev/null
+++ b/src/org/easymock/internal/matchers/CompareTo.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal.matchers;
+
+import java.io.Serializable;
+
+import org.easymock.IArgumentMatcher;
+
+public abstract class CompareTo<T extends Comparable<T>> implements IArgumentMatcher, Serializable {
+
+ private static final long serialVersionUID = -8447010713532143168L;
+
+ private final Comparable<T> expected;
+
+ public CompareTo(Comparable<T> value) {
+ this.expected = value;
+ }
+
+ @SuppressWarnings("unchecked")
+ public boolean matches(Object actual) {
+
+ if(!(actual instanceof Comparable)) {
+ return false;
+ }
+
+ return matchResult(((Comparable) actual).compareTo(expected));
+ }
+
+ public void appendTo(StringBuffer buffer) {
+ buffer.append(getName() + "(" + expected + ")");
+ }
+
+ protected abstract String getName();
+
+ protected abstract boolean matchResult(int result);
+}
diff --git a/src/org/easymock/internal/matchers/Contains.java b/src/org/easymock/internal/matchers/Contains.java
new file mode 100644
index 0000000..57483c2
--- /dev/null
+++ b/src/org/easymock/internal/matchers/Contains.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal.matchers;
+
+import java.io.Serializable;
+
+import org.easymock.IArgumentMatcher;
+
+public class Contains implements IArgumentMatcher, Serializable {
+
+ private static final long serialVersionUID = -6785245714002503134L;
+
+ private final String substring;
+
+ public Contains(String substring) {
+ this.substring = substring;
+ }
+
+ public boolean matches(Object actual) {
+ return (actual instanceof String)
+ && ((String) actual).indexOf(substring) >= 0;
+ }
+
+ public void appendTo(StringBuffer buffer) {
+ buffer.append("contains(\"" + substring + "\")");
+ }
+}
diff --git a/src/org/easymock/internal/matchers/EndsWith.java b/src/org/easymock/internal/matchers/EndsWith.java
new file mode 100644
index 0000000..f8e024b
--- /dev/null
+++ b/src/org/easymock/internal/matchers/EndsWith.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal.matchers;
+
+import java.io.Serializable;
+
+import org.easymock.IArgumentMatcher;
+
+public class EndsWith implements IArgumentMatcher, Serializable {
+
+ private static final long serialVersionUID = 5159338714596685067L;
+
+ private final String suffix;
+
+ public EndsWith(String suffix) {
+ this.suffix = suffix;
+ }
+
+ public boolean matches(Object actual) {
+ return (actual instanceof String) && ((String) actual).endsWith(suffix);
+ }
+
+ public void appendTo(StringBuffer buffer) {
+ buffer.append("endsWith(\"" + suffix + "\")");
+ }
+}
diff --git a/src/org/easymock/internal/matchers/Equals.java b/src/org/easymock/internal/matchers/Equals.java
new file mode 100644
index 0000000..3988215
--- /dev/null
+++ b/src/org/easymock/internal/matchers/Equals.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal.matchers;
+
+import java.io.Serializable;
+
+import org.easymock.IArgumentMatcher;
+import org.easymock.internal.ArgumentToString;
+
+public class Equals implements IArgumentMatcher, Serializable {
+
+ private static final long serialVersionUID = 583055160049982067L;
+
+ private final Object expected;
+
+ public Equals(Object expected) {
+ this.expected = expected;
+ }
+
+ public boolean matches(Object actual) {
+ if (this.expected == null) {
+ return actual == null;
+ }
+ return expected.equals(actual);
+ }
+
+ public void appendTo(StringBuffer buffer) {
+ ArgumentToString.appendArgument(expected, buffer);
+ }
+
+ protected final Object getExpected() {
+ return expected;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o == null || !this.getClass().equals(o.getClass()))
+ return false;
+ Equals other = (Equals) o;
+ return this.expected == null && other.expected == null
+ || this.expected != null
+ && this.expected.equals(other.expected);
+ }
+
+ @Override
+ public int hashCode() {
+ throw new UnsupportedOperationException("hashCode() is not supported");
+ }
+
+}
diff --git a/src/org/easymock/internal/matchers/EqualsWithDelta.java b/src/org/easymock/internal/matchers/EqualsWithDelta.java
new file mode 100644
index 0000000..7cc4f33
--- /dev/null
+++ b/src/org/easymock/internal/matchers/EqualsWithDelta.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal.matchers;
+
+import java.io.Serializable;
+
+import org.easymock.IArgumentMatcher;
+
+public class EqualsWithDelta implements IArgumentMatcher, Serializable {
+
+ private static final long serialVersionUID = -3018631689416120154L;
+
+ private final Number expected;
+
+ private final Number delta;
+
+ public EqualsWithDelta(Number value, Number delta) {
+ this.expected = value;
+ this.delta = delta;
+ }
+
+ public boolean matches(Object actual) {
+ Number actualNumber = (Number) actual;
+ return expected.doubleValue() - delta.doubleValue() <= actualNumber
+ .doubleValue()
+ && actualNumber.doubleValue() <= expected.doubleValue()
+ + delta.doubleValue();
+ }
+
+ public void appendTo(StringBuffer buffer) {
+ buffer.append("eq(" + expected + ", " + delta + ")");
+ }
+}
diff --git a/src/org/easymock/internal/matchers/Find.java b/src/org/easymock/internal/matchers/Find.java
new file mode 100644
index 0000000..ec83018
--- /dev/null
+++ b/src/org/easymock/internal/matchers/Find.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal.matchers;
+
+import java.io.Serializable;
+import java.util.regex.Pattern;
+
+import org.easymock.IArgumentMatcher;
+
+public class Find implements IArgumentMatcher, Serializable {
+
+ private static final long serialVersionUID = -7104607303959381785L;
+
+ private final String regex;
+
+ public Find(String regex) {
+ this.regex = regex;
+ }
+
+ public boolean matches(Object actual) {
+ return (actual instanceof String)
+ && Pattern.compile(regex).matcher((String) actual).find();
+ }
+
+ public void appendTo(StringBuffer buffer) {
+ buffer.append("find(\"" + regex.replaceAll("\\\\", "\\\\\\\\") + "\")");
+ }
+}
diff --git a/src/org/easymock/internal/matchers/GreaterOrEqual.java b/src/org/easymock/internal/matchers/GreaterOrEqual.java
new file mode 100644
index 0000000..4d567bc
--- /dev/null
+++ b/src/org/easymock/internal/matchers/GreaterOrEqual.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal.matchers;
+
+public class GreaterOrEqual<T extends Comparable<T>> extends CompareTo<T> {
+
+ private static final long serialVersionUID = -504083241204488174L;
+
+ public GreaterOrEqual(Comparable<T> value) {
+ super(value);
+ }
+
+ @Override
+ protected String getName() {
+ return "geq";
+ }
+
+ @Override
+ protected boolean matchResult(int result) {
+ return result >= 0;
+ }
+}
diff --git a/src/org/easymock/internal/matchers/GreaterThan.java b/src/org/easymock/internal/matchers/GreaterThan.java
new file mode 100644
index 0000000..ddb70df
--- /dev/null
+++ b/src/org/easymock/internal/matchers/GreaterThan.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal.matchers;
+
+public class GreaterThan<T extends Comparable<T>> extends CompareTo<T> {
+
+ private static final long serialVersionUID = 2736983121197045828L;
+
+ public GreaterThan(Comparable<T> value) {
+ super(value);
+ }
+
+ @Override
+ protected String getName() {
+ return "gt";
+ }
+
+ @Override
+ protected boolean matchResult(int result) {
+ return result > 0;
+ }
+}
diff --git a/src/org/easymock/internal/matchers/InstanceOf.java b/src/org/easymock/internal/matchers/InstanceOf.java
new file mode 100644
index 0000000..edda143
--- /dev/null
+++ b/src/org/easymock/internal/matchers/InstanceOf.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal.matchers;
+
+import java.io.Serializable;
+
+import org.easymock.IArgumentMatcher;
+
+public class InstanceOf implements IArgumentMatcher, Serializable {
+
+ private static final long serialVersionUID = -551735356674347591L;
+
+ private final Class<?> clazz;
+
+ public InstanceOf(Class<?> clazz) {
+ this.clazz = clazz;
+ }
+
+ public boolean matches(Object actual) {
+ return (actual != null) && clazz.isAssignableFrom(actual.getClass());
+ }
+
+ public void appendTo(StringBuffer buffer) {
+ buffer.append("isA(" + clazz.getName() + ")");
+ }
+}
diff --git a/src/org/easymock/internal/matchers/LessOrEqual.java b/src/org/easymock/internal/matchers/LessOrEqual.java
new file mode 100644
index 0000000..36d073e
--- /dev/null
+++ b/src/org/easymock/internal/matchers/LessOrEqual.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal.matchers;
+
+public class LessOrEqual<T extends Comparable<T>> extends CompareTo<T> {
+
+ private static final long serialVersionUID = -2485406702001842607L;
+
+ public LessOrEqual(Comparable<T> value) {
+ super(value);
+ }
+
+ @Override
+ protected String getName() {
+ return "leq";
+ }
+
+ @Override
+ protected boolean matchResult(int result) {
+ return result <= 0;
+ }
+}
diff --git a/src/org/easymock/internal/matchers/LessThan.java b/src/org/easymock/internal/matchers/LessThan.java
new file mode 100644
index 0000000..7646e9b
--- /dev/null
+++ b/src/org/easymock/internal/matchers/LessThan.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal.matchers;
+
+public class LessThan<T extends Comparable<T>> extends CompareTo<T> {
+
+ private static final long serialVersionUID = 6004888476822043880L;
+
+ public LessThan(Comparable<T> value) {
+ super(value);
+ }
+
+ @Override
+ protected String getName() {
+ return "lt";
+ }
+
+ @Override
+ protected boolean matchResult(int result) {
+ return result < 0;
+ }
+}
diff --git a/src/org/easymock/internal/matchers/Matches.java b/src/org/easymock/internal/matchers/Matches.java
new file mode 100644
index 0000000..452082b
--- /dev/null
+++ b/src/org/easymock/internal/matchers/Matches.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal.matchers;
+
+import java.io.Serializable;
+
+import org.easymock.IArgumentMatcher;
+
+public class Matches implements IArgumentMatcher, Serializable {
+
+ private static final long serialVersionUID = -6657694947057597484L;
+
+ private final String regex;
+
+ public Matches(String regex) {
+ this.regex = regex;
+ }
+
+ public boolean matches(Object actual) {
+ return (actual instanceof String) && ((String) actual).matches(regex);
+ }
+
+ public void appendTo(StringBuffer buffer) {
+ buffer.append("matches(\"" + regex.replaceAll("\\\\", "\\\\\\\\")
+ + "\")");
+ }
+}
diff --git a/src/org/easymock/internal/matchers/Not.java b/src/org/easymock/internal/matchers/Not.java
new file mode 100644
index 0000000..76ca20f
--- /dev/null
+++ b/src/org/easymock/internal/matchers/Not.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal.matchers;
+
+import java.io.Serializable;
+
+import org.easymock.IArgumentMatcher;
+
+public class Not implements IArgumentMatcher, Serializable {
+
+ private static final long serialVersionUID = -5160559075998939348L;
+
+ private final IArgumentMatcher first;
+
+ public Not(IArgumentMatcher first) {
+ this.first = first;
+ }
+
+ public boolean matches(Object actual) {
+ return !first.matches(actual);
+ }
+
+ public void appendTo(StringBuffer buffer) {
+ buffer.append("not(");
+ first.appendTo(buffer);
+ buffer.append(")");
+ }
+}
diff --git a/src/org/easymock/internal/matchers/NotNull.java b/src/org/easymock/internal/matchers/NotNull.java
new file mode 100644
index 0000000..86f006d
--- /dev/null
+++ b/src/org/easymock/internal/matchers/NotNull.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal.matchers;
+
+import java.io.Serializable;
+
+import org.easymock.IArgumentMatcher;
+
+public class NotNull implements IArgumentMatcher, Serializable {
+
+ private static final long serialVersionUID = -2689588759855326190L;
+
+ public static final NotNull NOT_NULL = new NotNull();
+
+ private NotNull() {
+
+ }
+
+ public boolean matches(Object actual) {
+ return actual != null;
+ }
+
+ public void appendTo(StringBuffer buffer) {
+ buffer.append("notNull()");
+ }
+}
diff --git a/src/org/easymock/internal/matchers/Null.java b/src/org/easymock/internal/matchers/Null.java
new file mode 100644
index 0000000..c401bef
--- /dev/null
+++ b/src/org/easymock/internal/matchers/Null.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal.matchers;
+
+import java.io.Serializable;
+
+import org.easymock.IArgumentMatcher;
+
+public class Null implements IArgumentMatcher, Serializable {
+
+ private static final long serialVersionUID = 6077244839421122011L;
+
+ public static final Null NULL = new Null();
+
+ private Null() {
+ }
+
+ public boolean matches(Object actual) {
+ return actual == null;
+ }
+
+ public void appendTo(StringBuffer buffer) {
+ buffer.append("isNull()");
+ }
+}
diff --git a/src/org/easymock/internal/matchers/Or.java b/src/org/easymock/internal/matchers/Or.java
new file mode 100644
index 0000000..910c13f
--- /dev/null
+++ b/src/org/easymock/internal/matchers/Or.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal.matchers;
+
+import java.io.Serializable;
+import java.util.Iterator;
+import java.util.List;
+
+import org.easymock.IArgumentMatcher;
+
+public class Or implements IArgumentMatcher, Serializable {
+
+ private static final long serialVersionUID = -5701204283180444317L;
+
+ private final List<IArgumentMatcher> matchers;
+
+ public Or(List<IArgumentMatcher> matchers) {
+ this.matchers = matchers;
+ }
+
+ public boolean matches(Object actual) {
+ for (IArgumentMatcher matcher : matchers) {
+ if (matcher.matches(actual)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public void appendTo(StringBuffer buffer) {
+ buffer.append("or(");
+ for (Iterator<IArgumentMatcher> it = matchers.iterator(); it.hasNext();) {
+ it.next().appendTo(buffer);
+ if (it.hasNext()) {
+ buffer.append(", ");
+ }
+ }
+ buffer.append(")");
+ }
+}
diff --git a/src/org/easymock/internal/matchers/Same.java b/src/org/easymock/internal/matchers/Same.java
new file mode 100644
index 0000000..a106d46
--- /dev/null
+++ b/src/org/easymock/internal/matchers/Same.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal.matchers;
+
+import java.io.Serializable;
+
+import org.easymock.IArgumentMatcher;
+import org.easymock.internal.ArgumentToString;
+
+public class Same implements IArgumentMatcher, Serializable {
+
+ private static final long serialVersionUID = 1094930851962278376L;
+
+ private final Object expected;
+
+ public Same(Object expected) {
+ this.expected = expected;
+ }
+
+ public boolean matches(Object actual) {
+ return expected == actual;
+ }
+
+ public void appendTo(StringBuffer buffer) {
+ buffer.append("same(");
+ ArgumentToString.appendArgument(expected, buffer);
+ buffer.append(")");
+ }
+}
diff --git a/src/org/easymock/internal/matchers/StartsWith.java b/src/org/easymock/internal/matchers/StartsWith.java
new file mode 100644
index 0000000..bf12f96
--- /dev/null
+++ b/src/org/easymock/internal/matchers/StartsWith.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2001-2009 OFFIS, Tammo Freese
+ *
+ * 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 org.easymock.internal.matchers;
+
+import java.io.Serializable;
+
+import org.easymock.IArgumentMatcher;
+
+public class StartsWith implements IArgumentMatcher, Serializable {
+
+ private static final long serialVersionUID = -658998692584342514L;
+
+ private final String prefix;
+
+ public StartsWith(String prefix) {
+ this.prefix = prefix;
+ }
+
+ public boolean matches(Object actual) {
+ return (actual instanceof String)
+ && ((String) actual).startsWith(prefix);
+ }
+
+ public void appendTo(StringBuffer buffer) {
+ buffer.append("startsWith(\"" + prefix + "\")");
+ }
+}