Class PersistentMatchers
public class PersistentMatchers
extends java.lang.Object
PersistentMatcher.
Furthermore it offers a factory method for creating
ComboMatchers. Whenever you want to use PersistentMatcher it will be necessary to wrap them in a ComboMatcher with
the factory method combo(Object, PersistentMatcher). After that you can use the ComboMatcher like any other ParameterMatcher. The same rules, which are valid for any
ParameterMatcher are applied to ComboMatcher as well.- See Also:
Matchers
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPersistentMatchers.EqualsMatcher<T>This Matcher is typically used byequalsMatcher(), but since it is also used internally in various places it is implemented as a class rather than a simple lambda, as it is the case with most of the Matchers. -
Method Summary
Modifier and Type Method Description static <T> TanyRecorded()Matches parameters during recording and during tests, that use previously recorded samples.static <T> TanyRecorded(PersistentMatcher<T> persistentMatcher)Matches all types of parameters during recording and during tests, that use previously recorded samples.static <T> TanyRecorded(java.lang.Class<T> type)Matches parameters during recording and during tests, that use previously recorded samples.static booleananyRecordedBoolean()Matches boolean parameters during recording and during tests, that use previously recorded samples.static byteanyRecordedByte()Matches byte parameters during recording and during tests, that use previously recorded samples.static charanyRecordedChar()Matches char parameters during recording and during tests, that use previously recorded samples.static doubleanyRecordedDouble()Matches double parameters during recording and during tests, that use previously recorded samples.static floatanyRecordedFloat()Matches float parameters during recording and during tests, that use previously recorded samples.static intanyRecordedInt()Matches int parameters during recording and during tests, that use previously recorded samples.static longanyRecordedLong()Matches long parameters during recording and during tests, that use previously recorded samples.static shortanyRecordedShort()Matches short parameters during recording and during tests, that use previously recorded samples.static java.lang.StringanyRecordedString()Matches string parameters during recording and during tests, that use previously recorded samples.static <T> Tcombo(T recordingMatcher, PersistentMatcher<T> playingMatcher)Allows adding separate matchers for loading and recording of samples.static <T> PersistentMatcher<T>equalsMatcher()Create aPersistentMatcherfor comparing two objects using their equals method.static <T> Tmatch(de.ppi.deepsampler.core.model.ParameterMatcher<T> recordingMatcher, PersistentMatcher<T> playingMatcher)Allows adding separate matchers for loading and recording of samples.static <T> PersistentMatcher<T>sameMatcher()Create aPersistentMatcherfor comparing two objects by memory address (objOne == objTwo).Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Method Details
-
anyRecorded
public static <T> T anyRecorded()Matches parameters during recording and during tests, that use previously recorded samples.- Recording: All parameters are accepted.
- Testing: The parameters, that are passed to the stubbed method during testing, are matched against recorded parameters.
Object.equals(Object)is used to match the parameter objects.
An Exception is thrown, if the parameter-object does not override
Object.equals(Object). In this caseanyRecorded(PersistentMatcher)can be used to define aPersistentMatcher, that will be used instead ofObject.equals(Object).- Type Parameters:
T- The type of the parameter that will be accepted- Returns:
- a matcher that accepts any recorded parameter value
-
anyRecorded
public static <T> T anyRecorded(java.lang.Class<T> type)Matches parameters during recording and during tests, that use previously recorded samples.This method essentially does the same thing as
anyRecorded(). However, if the method for which parameter matchers shall be defined is overloaded in a way, that the generic return type ofanyRecorded()cannot be resolved without a cast, this method allows to definde the type of the parameter, so that the generic return type is resolvable.- Type Parameters:
T- The type of the parameter that will be accepted- Parameters:
type- TheClassof the parameter that will be accepted independently of its concrete value.- Returns:
- a matcher that accepts any recorded parameter value
-
anyRecordedString
public static java.lang.String anyRecordedString()Matches string parameters during recording and during tests, that use previously recorded samples.- Recording: All strings are accepted.
- Testing: The Strings, that are passed to the stubbed method during testing, are matched against recorded Strings.
Object.equals(Object)is used to match the Strings.
- Returns:
- A Matcher, that accepts recorded Strings.
-
anyRecordedInt
public static int anyRecordedInt()Matches int parameters during recording and during tests, that use previously recorded samples.- Recording: All int parameters are accepted.
- Testing: The ints, that are passed to the stubbed method during testing, are matched against recorded ints.
Object.equals(Object)is used to match the ints.
- Returns:
- A Matcher, that accepts recorded ints.
-
anyRecordedLong
public static long anyRecordedLong()Matches long parameters during recording and during tests, that use previously recorded samples.- Recording: All long parameters are accepted.
- Testing: The longs, that are passed to the stubbed method during testing, are matched against recorded longs.
Object.equals(Object)is used to match the longs.
- Returns:
- A Matcher, that accepts recorded long-values.
-
anyRecordedDouble
public static double anyRecordedDouble()Matches double parameters during recording and during tests, that use previously recorded samples.- Recording: All double parameters are accepted.
- Testing: The double-values, that are passed to the stubbed method during testing, are matched against recorded doubles.
Object.equals(Object)is used to match the double-values.
- Returns:
- A Matcher, that accepts recorded double-values.
-
anyRecordedFloat
public static float anyRecordedFloat()Matches float parameters during recording and during tests, that use previously recorded samples.- Recording: All float parameters are accepted.
- Testing: The float-values, that are passed to the stubbed method during testing, are matched against recorded float-values.
Object.equals(Object)is used to match the float parameters.
- Returns:
- A Matcher, that accepts recorded float-values.
-
anyRecordedChar
public static char anyRecordedChar()Matches char parameters during recording and during tests, that use previously recorded samples.- Recording: All char parameters are accepted.
- Testing: The char parameters, that are passed to the stubbed method during testing, are matched against recorded chars.
Object.equals(Object)is used to match the chars.
- Returns:
- A Matcher, that accepts recorded chars.
-
anyRecordedBoolean
public static boolean anyRecordedBoolean()Matches boolean parameters during recording and during tests, that use previously recorded samples.- Recording: All boolean parameters are accepted.
- Testing: The booleans, that are passed to the stubbed method during testing, are matched against recorded booleans.
Object.equals(Object)is used to match the booleans.
- Returns:
- A Matcher, that accepts recorded booleans.
-
anyRecordedShort
public static short anyRecordedShort()Matches short parameters during recording and during tests, that use previously recorded samples.- Recording: All short parameters are accepted.
- Testing: The short-values, that are passed to the stubbed method during testing, are matched against recorded short-values.
Object.equals(Object)is used to match the short parameters.
- Returns:
- A Matcher, that accepts recorded shorts.
-
anyRecordedByte
public static byte anyRecordedByte()Matches byte parameters during recording and during tests, that use previously recorded samples.- Recording: All byte parameters are accepted.
- Testing: The byte-values, that are passed to the stubbed method during testing, are matched against recorded bytes.
Object.equals(Object)is used to match the byte parameters.
- Returns:
- A Matcher, that accepts recorded bytes.
-
anyRecorded
Matches all types of parameters during recording and during tests, that use previously recorded samples.- Recording: All parameters are accepted.
- Testing: The parameters, that are passed to the method during testing, are matched against recorded parameters using a custom
PersistentMatcher. This is especially useful, if the parameter objects do not overrideObject.equals(Object). ThePersistentMatchercan be used to replace the equals() in these cases. ThePersistentMatchermay conveniently be defined as a lambda or a method reference.
- Type Parameters:
T- The type of the parameter that will be accepted- Parameters:
persistentMatcher- A replacement for a (possibly) missingObject.equals(Object)-method.- Returns:
- A matcher using the passed
PersistentMatcher
-
match
public static <T> T match(de.ppi.deepsampler.core.model.ParameterMatcher<T> recordingMatcher, PersistentMatcher<T> playingMatcher)Allows adding separate matchers for loading and recording of samples.- Recording: The parameters, that are passed to a method during recording, are matched using recordingMatcher. A method-call is recorded only, if recordMatcher returns true for all parameters.
- Testing: The parameters, that actually appear during testing, are matched against recorded parameters using a custom
PersistentMatcher. This is especially useful, if the parameter objects do not overrideObject.equals(Object). ThePersistentMatchercan be used to replace the equals() in these cases. ThePersistentMatchermay conveniently be defined as a lambda or a method reference.
Please notice: The basic idea of persistent samples is, that the parameters, with which a stubbed method is called during a test, are compared to previously recorded parameters. So usually the playingMatcher is used to compare the expected parameters from the sample-file with the actual parameters during test. This method allows to change this behavior. We recommend using this method only after careful considerations.
- Type Parameters:
T- type to compare/match- Parameters:
recordingMatcher- this macher will be used during recording of samples.playingMatcher- this matcher will be used during replay.- Returns:
- always returns null
-
combo
Allows adding separate matchers for loading and recording of samples.Please notice: The basic idea of persistent samples is, that the parameters, with which a stubbed method is called during a test, are compared to previously recorded parameters. So usually the playingMatcher is used to compare the expected parameters from the sample-file with the actual parameters during test. This method allows to change this behavior. We recommend using this method only after careful considerations.
- Type Parameters:
T- type to compare/match- Parameters:
recordingMatcher- this macher will be used during recording of samples. The matcher can be created using the helper-methods inMatchersplayingMatcher- this matcher will be used during replay.- Returns:
- always returns null
-
equalsMatcher
Create aPersistentMatcherfor comparing two objects using their equals method.- Type Parameters:
T- type to compare- Returns:
- the created
PersistentMatcher
-
sameMatcher
Create aPersistentMatcherfor comparing two objects by memory address (objOne == objTwo).- Type Parameters:
T- type to compare- Returns:
- the
PersistentMatcher
-