All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.mockito.AdditionalMatchers Maven / Gradle / Ivy

There is a newer version: 5.13.0
Show newest version
/*
 * Copyright (c) 2007 Mockito contributors
 * This program is made available under the terms of the MIT License.
 */
package org.mockito;

import static org.mockito.internal.progress.ThreadSafeMockingProgress.mockingProgress;

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;

/**
 * See {@link ArgumentMatchers} 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 ArgumentMatchers} 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. */ @SuppressWarnings("ALL") public final class AdditionalMatchers { /** * argument greater than or equal the given value. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given value. * @return null. */ public static > T geq(T value) { reportMatcher(new GreaterOrEqual(value)); return null; } /** * byte argument greater than or equal to the given value. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given value. * @return 0. */ public static byte geq(byte value) { reportMatcher(new GreaterOrEqual(value)); return 0; } /** * double argument greater than or equal to the given value. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given value. * @return 0. */ public static double geq(double value) { reportMatcher(new GreaterOrEqual(value)); return 0; } /** * float argument greater than or equal to the given value. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given value. * @return 0. */ public static float geq(float value) { reportMatcher(new GreaterOrEqual(value)); return 0; } /** * int argument greater than or equal to the given value. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given value. * @return 0. */ public static int geq(int value) { reportMatcher(new GreaterOrEqual(value)); return 0; } /** * long argument greater than or equal to the given value. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given value. * @return 0. */ public static long geq(long value) { reportMatcher(new GreaterOrEqual(value)); return 0; } /** * short argument greater than or equal to the given value. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given value. * @return 0. */ public static short geq(short value) { reportMatcher(new GreaterOrEqual(value)); return 0; } /** * comparable argument less than or equal the given value details. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given value. * @return null. */ public static > T leq(T value) { reportMatcher(new LessOrEqual(value)); return null; } /** * byte argument less than or equal to the given value. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given value. * @return 0. */ public static byte leq(byte value) { reportMatcher(new LessOrEqual(value)); return 0; } /** * double argument less than or equal to the given value. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given value. * @return 0. */ public static double leq(double value) { reportMatcher(new LessOrEqual(value)); return 0; } /** * float argument less than or equal to the given value. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given value. * @return 0. */ public static float leq(float value) { reportMatcher(new LessOrEqual(value)); return 0; } /** * int argument less than or equal to the given value. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given value. * @return 0. */ public static int leq(int value) { reportMatcher(new LessOrEqual(value)); return 0; } /** * long argument less than or equal to the given value. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given value. * @return 0. */ public static long leq(long value) { reportMatcher(new LessOrEqual(value)); return 0; } /** * short argument less than or equal to the given value. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given value. * @return 0. */ public static short leq(short value) { reportMatcher(new LessOrEqual(value)); return 0; } /** * comparable argument greater than the given value. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given value. * @return null. */ public static > T gt(T value) { reportMatcher(new GreaterThan(value)); return null; } /** * byte argument greater than the given value. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given value. * @return 0. */ public static byte gt(byte value) { reportMatcher(new GreaterThan(value)); return 0; } /** * double argument greater than the given value. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given value. * @return 0. */ public static double gt(double value) { reportMatcher(new GreaterThan(value)); return 0; } /** * float argument greater than the given value. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given value. * @return 0. */ public static float gt(float value) { reportMatcher(new GreaterThan(value)); return 0; } /** * int argument greater than the given value. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given value. * @return 0. */ public static int gt(int value) { reportMatcher(new GreaterThan(value)); return 0; } /** * long argument greater than the given value. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given value. * @return 0. */ public static long gt(long value) { reportMatcher(new GreaterThan(value)); return 0; } /** * short argument greater than the given value. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given value. * @return 0. */ public static short gt(short value) { reportMatcher(new GreaterThan(value)); return 0; } /** * comparable argument less than the given value. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given value. * @return null. */ public static > T lt(T value) { reportMatcher(new LessThan(value)); return null; } /** * byte argument less than the given value. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given value. * @return 0. */ public static byte lt(byte value) { reportMatcher(new LessThan(value)); return 0; } /** * double argument less than the given value. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given value. * @return 0. */ public static double lt(double value) { reportMatcher(new LessThan(value)); return 0; } /** * float argument less than the given value. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given value. * @return 0. */ public static float lt(float value) { reportMatcher(new LessThan(value)); return 0; } /** * int argument less than the given value. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given value. * @return 0. */ public static int lt(int value) { reportMatcher(new LessThan(value)); return 0; } /** * long argument less than the given value. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given value. * @return 0. */ public static long lt(long value) { reportMatcher(new LessThan(value)); return 0; } /** * short argument less than the given value. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given value. * @return 0. */ public static short lt(short value) { reportMatcher(new LessThan(value)); return 0; } /** * comparable argument equals to the given value according to their * compareTo method. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given value. * @return null. */ public static > T cmpEq(T value) { reportMatcher(new CompareEqual(value)); return null; } /** * String argument that contains a substring that matches the given regular * expression. * * @param regex * the regular expression. * @return null. */ public static String find(String regex) { reportMatcher(new Find(regex)); return null; } /** * Object array argument that is equal to the given array, i.e. it has to * have the same type, length, and each element has to be equal. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param * the type of the array, it is passed through to prevent casts. * @param value * the given array. * @return null. */ public static T[] aryEq(T[] value) { reportMatcher(new ArrayEquals(value)); return null; } /** * short 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. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given array. * @return null. */ public static short[] aryEq(short[] value) { reportMatcher(new ArrayEquals(value)); return null; } /** * 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. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given array. * @return null. */ public static long[] aryEq(long[] value) { reportMatcher(new ArrayEquals(value)); return null; } /** * 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. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given array. * @return null. */ public static int[] aryEq(int[] value) { reportMatcher(new ArrayEquals(value)); return null; } /** * 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. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given array. * @return null. */ public static float[] aryEq(float[] value) { reportMatcher(new ArrayEquals(value)); return null; } /** * 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. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given array. * @return null. */ public static double[] aryEq(double[] value) { reportMatcher(new ArrayEquals(value)); return null; } /** * 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. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given array. * @return null. */ public static char[] aryEq(char[] value) { reportMatcher(new ArrayEquals(value)); return null; } /** * 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. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given array. * @return null. */ public static byte[] aryEq(byte[] value) { reportMatcher(new ArrayEquals(value)); return null; } /** * 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. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given array. * @return null. */ public static boolean[] aryEq(boolean[] value) { reportMatcher(new ArrayEquals(value)); return null; } /** * boolean argument that matches both given matchers. *

* 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 false. */ public static boolean and(boolean first, boolean second) { mockingProgress().getArgumentMatcherStorage().reportAnd(); return false; } /** * byte argument that matches both given argument matchers. *

* 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 0. */ public static byte and(byte first, byte second) { mockingProgress().getArgumentMatcherStorage().reportAnd(); return 0; } /** * char argument that matches both given argument matchers. *

* 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 0. */ public static char and(char first, char second) { mockingProgress().getArgumentMatcherStorage().reportAnd(); return 0; } /** * double argument that matches both given argument matchers. *

* 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 0. */ public static double and(double first, double second) { mockingProgress().getArgumentMatcherStorage().reportAnd(); return 0; } /** * float argument that matches both given argument matchers. *

* 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 0. */ public static float and(float first, float second) { mockingProgress().getArgumentMatcherStorage().reportAnd(); return 0; } /** * int argument that matches both given argument matchers. *

* 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 0. */ public static int and(int first, int second) { mockingProgress().getArgumentMatcherStorage().reportAnd(); return 0; } /** * long argument that matches both given argument matchers. *

* 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 0. */ public static long and(long first, long second) { mockingProgress().getArgumentMatcherStorage().reportAnd(); return 0; } /** * short argument that matches both given argument matchers. *

* 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 0. */ public static short and(short first, short second) { mockingProgress().getArgumentMatcherStorage().reportAnd(); return 0; } /** * Object argument that matches both given argument matchers. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param * the type of the object, it is passed through to prevent casts. * @param first * placeholder for the first argument matcher. * @param second * placeholder for the second argument matcher. * @return null. */ public static T and(T first, T second) { mockingProgress().getArgumentMatcherStorage().reportAnd(); return null; } /** * boolean argument that matches any of the given argument matchers. *

* 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 false. */ public static boolean or(boolean first, boolean second) { mockingProgress().getArgumentMatcherStorage().reportOr(); return false; } /** * Object argument that matches any of the given argument matchers. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param * the type of the object, it is passed through to prevent casts. * @param first * placeholder for the first argument matcher. * @param second * placeholder for the second argument matcher. * @return null. */ public static T or(T first, T second) { mockingProgress().getArgumentMatcherStorage().reportOr(); return null; } /** * short argument that matches any of the given argument matchers. *

* 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 0. */ public static short or(short first, short second) { mockingProgress().getArgumentMatcherStorage().reportOr(); return 0; } /** * long argument that matches any of the given argument matchers. *

* 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 0. */ public static long or(long first, long second) { mockingProgress().getArgumentMatcherStorage().reportOr(); return 0; } /** * int argument that matches any of the given argument matchers. *

* 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 0. */ public static int or(int first, int second) { mockingProgress().getArgumentMatcherStorage().reportOr(); return 0; } /** * float argument that matches any of the given argument matchers. *

* 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 0. */ public static float or(float first, float second) { mockingProgress().getArgumentMatcherStorage().reportOr(); return 0; } /** * double argument that matches any of the given argument matchers. *

* 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 0. */ public static double or(double first, double second) { mockingProgress().getArgumentMatcherStorage().reportOr(); return 0; } /** * char argument that matches any of the given argument matchers. *

* 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 0. */ public static char or(char first, char second) { mockingProgress().getArgumentMatcherStorage().reportOr(); return 0; } /** * byte argument that matches any of the given argument matchers. *

* 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 0. */ public static byte or(byte first, byte second) { mockingProgress().getArgumentMatcherStorage().reportOr(); return 0; } /** * Object argument that does not match the given argument matcher. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param * the type of the object, it is passed through to prevent casts. * @param first * placeholder for the argument matcher. * @return null. */ public static T not(T first) { mockingProgress().getArgumentMatcherStorage().reportNot(); return null; } /** * short argument that does not match the given argument matcher. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param first * placeholder for the argument matcher. * @return 0. */ public static short not(short first) { mockingProgress().getArgumentMatcherStorage().reportNot(); return 0; } /** * int argument that does not match the given argument matcher. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param first * placeholder for the argument matcher. * @return 0. */ public static int not(int first) { mockingProgress().getArgumentMatcherStorage().reportNot(); return 0; } /** * long argument that does not match the given argument matcher. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param first * placeholder for the argument matcher. * @return 0. */ public static long not(long first) { mockingProgress().getArgumentMatcherStorage().reportNot(); return 0; } /** * float argument that does not match the given argument matcher. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param first * placeholder for the argument matcher. * @return 0. */ public static float not(float first) { mockingProgress().getArgumentMatcherStorage().reportNot(); return 0; } /** * double argument that does not match the given argument matcher. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param first * placeholder for the argument matcher. * @return 0. */ public static double not(double first) { mockingProgress().getArgumentMatcherStorage().reportNot(); return 0; } /** * char argument that does not match the given argument matcher. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param first * placeholder for the argument matcher. * @return 0. */ public static char not(char first) { mockingProgress().getArgumentMatcherStorage().reportNot(); return 0; } /** * boolean argument that does not match the given argument matcher. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param first * placeholder for the argument matcher. * @return false. */ public static boolean not(boolean first) { mockingProgress().getArgumentMatcherStorage().reportNot(); return false; } /** * byte argument that does not match the given argument matcher. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param first * placeholder for the argument matcher. * @return 0. */ public static byte not(byte first) { mockingProgress().getArgumentMatcherStorage().reportNot(); return 0; } /** * double argument that has an absolute difference to the given value that * is less than the given delta details. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given value. * @param delta * the given delta. * @return 0. */ public static double eq(double value, double delta) { reportMatcher(new EqualsWithDelta(value, delta)); return 0; } /** * float argument that has an absolute difference to the given value that is * less than the given delta details. *

* See examples in javadoc for {@link AdditionalMatchers} class * * @param value * the given value. * @param delta * the given delta. * @return 0. */ public static float eq(float value, float delta) { reportMatcher(new EqualsWithDelta(value, delta)); return 0; } private static void reportMatcher(ArgumentMatcher matcher) { mockingProgress().getArgumentMatcherStorage().reportMatcher(matcher); } private AdditionalMatchers() {} }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy