/* * Copyright (c) 2007 Mockito contributors * This program is made available under the terms of the MIT License. */ package org.mockito; import org.mockito.internal.matchers.ArrayEquals; import org.mockito.internal.matchers.CompareEqual; import org.mockito.internal.matchers.EqualsWithDelta; import org.mockito.internal.matchers.Find; import org.mockito.internal.matchers.GreaterOrEqual; import org.mockito.internal.matchers.GreaterThan; import org.mockito.internal.matchers.LessOrEqual; import org.mockito.internal.matchers.LessThan; import org.mockito.internal.progress.HandyReturnValues; import org.mockito.internal.progress.MockingProgress; import org.mockito.internal.progress.ThreadSafeMockingProgress; /** * See {@link Matchers} for general info about matchers. *
* AdditionalMatchers provides rarely used matchers, kept only for somewhat compatibility with EasyMock. * Use additional matchers very judiciously because they may impact readability of a test. * It is recommended to use matchers from {@link Matchers} and keep stubbing and verification simple. *
* Example of using logical and(), not(), or() matchers: * *
* //anything but not "ejb"
* mock.someMethod(not(eq("ejb")));
*
* //not "ejb" and not "michael jackson"
* mock.someMethod(and(not(eq("ejb")), not(eq("michael jackson"))));
*
* //1 or 10
* mock.someMethod(or(eq(1), eq(10)));
*
*
* Scroll down to see all methods - full list of matchers.
*/
public class AdditionalMatchers {
private static MockingProgress mockingProgress = new ThreadSafeMockingProgress();
/**
* argument greater than or equal the given value.
*
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param value
* the given value.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param value
* the given value.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param value
* the given value.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param value
* the given value.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param value
* the given value.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param value
* the given value.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param value
* the given value.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param value
* the given value.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param value
* the given value.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param value
* the given value.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param value
* the given value.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param value
* the given value.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param value
* the given value.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param value
* the given value.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param value
* the given value.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param value
* the given value.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param value
* the given value.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param value
* the given value.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param value
* the given value.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param value
* the given value.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param value
* the given value.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param value
* the given value.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param value
* the given value.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param value
* the given value.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param value
* the given value.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param value
* the given value.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param value
* the given value.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param value
* the given value.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param value
* the given value.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param value
* the given array.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param value
* the given array.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param value
* the given array.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param value
* the given array.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param value
* the given array.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param value
* the given array.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param value
* the given array.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param value
* the given array.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param first
* placeholder for the first argument matcher.
* @param second
* placeholder for the second argument matcher.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param first
* placeholder for the first argument matcher.
* @param second
* placeholder for the second argument matcher.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param first
* placeholder for the first argument matcher.
* @param second
* placeholder for the second argument matcher.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param first
* placeholder for the first argument matcher.
* @param second
* placeholder for the second argument matcher.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param first
* placeholder for the first argument matcher.
* @param second
* placeholder for the second argument matcher.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param first
* placeholder for the first argument matcher.
* @param second
* placeholder for the second argument matcher.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param first
* placeholder for the first argument matcher.
* @param second
* placeholder for the second argument matcher.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param first
* placeholder for the first argument matcher.
* @param second
* placeholder for the second argument matcher.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param first
* placeholder for the first argument matcher.
* @param second
* placeholder for the second argument matcher.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param first
* placeholder for the first argument matcher.
* @param second
* placeholder for the second argument matcher.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param first
* placeholder for the first argument matcher.
* @param second
* placeholder for the second argument matcher.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param first
* placeholder for the first argument matcher.
* @param second
* placeholder for the second argument matcher.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param first
* placeholder for the first argument matcher.
* @param second
* placeholder for the second argument matcher.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param first
* placeholder for the first argument matcher.
* @param second
* placeholder for the second argument matcher.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param first
* placeholder for the first argument matcher.
* @param second
* placeholder for the second argument matcher.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param first
* placeholder for the first argument matcher.
* @param second
* placeholder for the second argument matcher.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param first
* placeholder for the argument matcher.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param first
* placeholder for the argument matcher.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param first
* placeholder for the argument matcher.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param first
* placeholder for the argument matcher.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param first
* placeholder for the argument matcher.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param first
* placeholder for the argument matcher.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param first
* placeholder for the argument matcher.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param first
* placeholder for the argument matcher.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param value
* the given value.
* @param delta
* the given delta.
* @return
* See examples in javadoc for {@link AdditionalMatchers} class
*
* @param value
* the given value.
* @param delta
* the given delta.
* @return null
.
*/
public static 0
.
*/
public static byte geq(byte value) {
return reportMatcher(new GreaterOrEqual0
.
*/
public static double geq(double value) {
return reportMatcher(new GreaterOrEqual0
.
*/
public static float geq(float value) {
return reportMatcher(new GreaterOrEqual0
.
*/
public static int geq(int value) {
return reportMatcher(new GreaterOrEqual0
.
*/
public static long geq(long value) {
return reportMatcher(new GreaterOrEqual0
.
*/
public static short geq(short value) {
return reportMatcher(new GreaterOrEqualnull
.
*/
public static 0
.
*/
public static byte leq(byte value) {
return reportMatcher(new LessOrEqual0
.
*/
public static double leq(double value) {
return reportMatcher(new LessOrEqual0
.
*/
public static float leq(float value) {
return reportMatcher(new LessOrEqual0
.
*/
public static int leq(int value) {
return reportMatcher(new LessOrEqual0
.
*/
public static long leq(long value) {
return reportMatcher(new LessOrEqual0
.
*/
public static short leq(short value) {
return reportMatcher(new LessOrEqualnull
.
*/
public static 0
.
*/
public static byte gt(byte value) {
return reportMatcher(new GreaterThan0
.
*/
public static double gt(double value) {
return reportMatcher(new GreaterThan0
.
*/
public static float gt(float value) {
return reportMatcher(new GreaterThan0
.
*/
public static int gt(int value) {
return reportMatcher(new GreaterThan0
.
*/
public static long gt(long value) {
return reportMatcher(new GreaterThan0
.
*/
public static short gt(short value) {
return reportMatcher(new GreaterThannull
.
*/
public static 0
.
*/
public static byte lt(byte value) {
return reportMatcher(new LessThan0
.
*/
public static double lt(double value) {
return reportMatcher(new LessThan0
.
*/
public static float lt(float value) {
return reportMatcher(new LessThan0
.
*/
public static int lt(int value) {
return reportMatcher(new LessThan0
.
*/
public static long lt(long value) {
return reportMatcher(new LessThan0
.
*/
public static short lt(short value) {
return reportMatcher(new LessThannull
.
*/
public static null
.
*/
public static String find(String regex) {
return reportMatcher(new Find(regex)).null
.
*/
public static null
.
*/
public static short[] aryEq(short[] value) {
return reportMatcher(new ArrayEquals(value)).returnNull();
}
/**
* long array argument that is equal to the given array, i.e. it has to have
* the same length, and each element has to be equal.
* null
.
*/
public static long[] aryEq(long[] value) {
return reportMatcher(new ArrayEquals(value)).returnNull();
}
/**
* int array argument that is equal to the given array, i.e. it has to have
* the same length, and each element has to be equal.
* null
.
*/
public static int[] aryEq(int[] value) {
return reportMatcher(new ArrayEquals(value)).returnNull();
}
/**
* float array argument that is equal to the given array, i.e. it has to
* have the same length, and each element has to be equal.
* null
.
*/
public static float[] aryEq(float[] value) {
return reportMatcher(new ArrayEquals(value)).returnNull();
}
/**
* double array argument that is equal to the given array, i.e. it has to
* have the same length, and each element has to be equal.
* null
.
*/
public static double[] aryEq(double[] value) {
return reportMatcher(new ArrayEquals(value)).returnNull();
}
/**
* char array argument that is equal to the given array, i.e. it has to have
* the same length, and each element has to be equal.
* null
.
*/
public static char[] aryEq(char[] value) {
return reportMatcher(new ArrayEquals(value)).returnNull();
}
/**
* byte array argument that is equal to the given array, i.e. it has to have
* the same length, and each element has to be equal.
* null
.
*/
public static byte[] aryEq(byte[] value) {
return reportMatcher(new ArrayEquals(value)).returnNull();
}
/**
* boolean array argument that is equal to the given array, i.e. it has to
* have the same length, and each element has to be equal.
* null
.
*/
public static boolean[] aryEq(boolean[] value) {
return reportMatcher(new ArrayEquals(value)).returnNull();
}
/**
* boolean argument that matches both given matchers.
* false
.
*/
public static boolean and(boolean first, boolean second) {
return mockingProgress.getArgumentMatcherStorage().reportAnd().returnFalse();
}
/**
* byte argument that matches both given argument matchers.
* 0
.
*/
public static byte and(byte first, byte second) {
return mockingProgress.getArgumentMatcherStorage().reportAnd().returnZero();
}
/**
* char argument that matches both given argument matchers.
* 0
.
*/
public static char and(char first, char second) {
return mockingProgress.getArgumentMatcherStorage().reportAnd().returnChar();
}
/**
* double argument that matches both given argument matchers.
* 0
.
*/
public static double and(double first, double second) {
return mockingProgress.getArgumentMatcherStorage().reportAnd().returnZero();
}
/**
* float argument that matches both given argument matchers.
* 0
.
*/
public static float and(float first, float second) {
return mockingProgress.getArgumentMatcherStorage().reportAnd().returnZero();
}
/**
* int argument that matches both given argument matchers.
* 0
.
*/
public static int and(int first, int second) {
return mockingProgress.getArgumentMatcherStorage().reportAnd().returnZero();
}
/**
* long argument that matches both given argument matchers.
* 0
.
*/
public static long and(long first, long second) {
return mockingProgress.getArgumentMatcherStorage().reportAnd().returnZero();
}
/**
* short argument that matches both given argument matchers.
* 0
.
*/
public static short and(short first, short second) {
return mockingProgress.getArgumentMatcherStorage().reportAnd().returnZero();
}
/**
* Object argument that matches both given argument matchers.
* null
.
*/
public static false
.
*/
public static boolean or(boolean first, boolean second) {
return mockingProgress.getArgumentMatcherStorage().reportOr().returnFalse();
}
/**
* Object argument that matches any of the given argument matchers.
* null
.
*/
public static 0
.
*/
public static short or(short first, short second) {
return mockingProgress.getArgumentMatcherStorage().reportOr().returnZero();
}
/**
* long argument that matches any of the given argument matchers.
* 0
.
*/
public static long or(long first, long second) {
return mockingProgress.getArgumentMatcherStorage().reportOr().returnZero();
}
/**
* int argument that matches any of the given argument matchers.
* 0
.
*/
public static int or(int first, int second) {
return mockingProgress.getArgumentMatcherStorage().reportOr().returnZero();
}
/**
* float argument that matches any of the given argument matchers.
* 0
.
*/
public static float or(float first, float second) {
return mockingProgress.getArgumentMatcherStorage().reportOr().returnZero();
}
/**
* double argument that matches any of the given argument matchers.
* 0
.
*/
public static double or(double first, double second) {
return mockingProgress.getArgumentMatcherStorage().reportOr().returnZero();
}
/**
* char argument that matches any of the given argument matchers.
* 0
.
*/
public static char or(char first, char second) {
return mockingProgress.getArgumentMatcherStorage().reportOr().returnChar();
}
/**
* byte argument that matches any of the given argument matchers.
* 0
.
*/
public static byte or(byte first, byte second) {
return mockingProgress.getArgumentMatcherStorage().reportOr().returnZero();
}
/**
* Object argument that does not match the given argument matcher.
* null
.
*/
public static 0
.
*/
public static short not(short first) {
return mockingProgress.getArgumentMatcherStorage().reportNot().returnZero();
}
/**
* int argument that does not match the given argument matcher.
* 0
.
*/
public static int not(int first) {
return mockingProgress.getArgumentMatcherStorage().reportNot().returnZero();
}
/**
* long argument that does not match the given argument matcher.
* 0
.
*/
public static long not(long first) {
return mockingProgress.getArgumentMatcherStorage().reportNot().returnZero();
}
/**
* float argument that does not match the given argument matcher.
* 0
.
*/
public static float not(float first) {
return mockingProgress.getArgumentMatcherStorage().reportNot().returnZero();
}
/**
* double argument that does not match the given argument matcher.
* 0
.
*/
public static double not(double first) {
return mockingProgress.getArgumentMatcherStorage().reportNot().returnZero();
}
/**
* char argument that does not match the given argument matcher.
* 0
.
*/
public static char not(char first) {
return mockingProgress.getArgumentMatcherStorage().reportNot().returnChar();
}
/**
* boolean argument that does not match the given argument matcher.
* false
.
*/
public static boolean not(boolean first) {
return mockingProgress.getArgumentMatcherStorage().reportNot().returnFalse();
}
/**
* byte argument that does not match the given argument matcher.
* 0
.
*/
public static byte not(byte first) {
return mockingProgress.getArgumentMatcherStorage().reportNot().returnZero();
}
/**
* double argument that has an absolute difference to the given value that
* is less than the given delta details.
* 0
.
*/
public static double eq(double value, double delta) {
return reportMatcher(new EqualsWithDelta(value, delta)).returnZero();
}
/**
* float argument that has an absolute difference to the given value that is
* less than the given delta details.
* 0
.
*/
public static float eq(float value, float delta) {
return reportMatcher(new EqualsWithDelta(value, delta)).returnZero();
}
private static HandyReturnValues reportMatcher(ArgumentMatcher> matcher) {
return mockingProgress.getArgumentMatcherStorage().reportMatcher(matcher);
}
}