public class StartsWith extends Object implements ArgumentMatcher<String>, Serializable
Constructor and Description |
---|
StartsWith(String prefix) |
public StartsWith(String prefix)
public boolean matches(Object actual)
ArgumentMatcher
The method should never assert if the argument doesn't match. It should only return false.
The argument is not using the generic type in order to force explicit casting in the implementation.
This way it is easier to debug when incompatible arguments are passed to the matchers.
You have to trust us on this one. If we used parametrized type then ClassCastException
would be thrown in certain scenarios.
For example:
//test, method accepts Collection argument and ArgumentMatcher<List> is used
when(mock.useCollection(someListMatcher())).thenDoNothing();
//production code, yields confusing ClassCastException
//although Set extends Collection but is not compatible with ArgumentMatcher<List>
mock.useCollection(new HashSet());
See the example in the top level javadoc for ArgumentMatcher
matches
in interface ArgumentMatcher<String>
actual
- the argument