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

com.fitbur.mockito.AdditionalMatchers Maven / Gradle / Ivy

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

package com.fitbur.mockito;

import com.fitbur.mockito.internal.matchers.ArrayEquals;
import com.fitbur.mockito.internal.matchers.CompareEqual;
import com.fitbur.mockito.internal.matchers.EqualsWithDelta;
import com.fitbur.mockito.internal.matchers.Find;
import com.fitbur.mockito.internal.matchers.GreaterOrEqual;
import com.fitbur.mockito.internal.matchers.GreaterThan;
import com.fitbur.mockito.internal.matchers.LessOrEqual;
import com.fitbur.mockito.internal.matchers.LessThan;
import com.fitbur.mockito.internal.progress.MockingProgress;
import com.fitbur.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 final MockingProgress MOCKING_PROGRESS = new ThreadSafeMockingProgress(); /** * 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(Comparable 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(Comparable 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(Comparable 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(Comparable 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(Comparable 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) { MOCKING_PROGRESS.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) { MOCKING_PROGRESS.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) { MOCKING_PROGRESS.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) { MOCKING_PROGRESS.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) { MOCKING_PROGRESS.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) { MOCKING_PROGRESS.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) { MOCKING_PROGRESS.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) { MOCKING_PROGRESS.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) { MOCKING_PROGRESS.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) { MOCKING_PROGRESS.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) { MOCKING_PROGRESS.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) { MOCKING_PROGRESS.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) { MOCKING_PROGRESS.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) { MOCKING_PROGRESS.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) { MOCKING_PROGRESS.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) { MOCKING_PROGRESS.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) { MOCKING_PROGRESS.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) { MOCKING_PROGRESS.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) { MOCKING_PROGRESS.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) { MOCKING_PROGRESS.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) { MOCKING_PROGRESS.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) { MOCKING_PROGRESS.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) { MOCKING_PROGRESS.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) { MOCKING_PROGRESS.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) { MOCKING_PROGRESS.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) { MOCKING_PROGRESS.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) { MOCKING_PROGRESS.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) { MOCKING_PROGRESS.getArgumentMatcherStorage().reportMatcher(matcher); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy