Questions tagged [matcher]

Matchers are objects used among other things by testing libraries to check, if an object matches an abstract description of an expected state. Do not use this tag for use of the Matcher class for regular expression matching, use [regex] instead.

The most basic matcher is a function from an object to boolean, where the return value denotes whether the argument matches the description represented by the matcher. Apart from doing the actual matching matchers most of the time also provide some information about why a matcher did not match, and they can be combined using methods or functions, that take matchers as an argument and return new matchers (see the example below).

Matchers allow expectations to be written in an internal DSL. For example using Hamcrest and JUnit assertions can be written like this:

assertThat("nuts", biscuit.nutCount(), allOf(greaterThan(3), evenNumber()));

This is relatively easy to understand, even without knowing how it exactly works, and it will provide failure messages that explain the reason why the assertion failed. In the above example allOf(), greaterThan() and evenNumber() are all methods returning matchers.

Matchers are also used in other libraries, for example mock libraries use matchers in order to formulate expectations about calls to mocks, stubs or spies, like in the following example with Mockito.

when(mockedList.get(anyInt())).thenReturn("element");

Here anyInt() returns a matcher that matches any Integer or int.

458 questions
-1
votes
1 answer

Spacy Matcher weirdness

I use next pattern on the explosion web site in demos "Rule-based Matcher Explorer" pattern = [{'LEMMA': 'museum'}] Text is museums in madrid And this is work, Okay. Then i do next in code: import spacy from spacy.matcher import Matcher nlp =…
Andrew
  • 145
  • 1
  • 1
  • 6
-1
votes
1 answer

How to loosely match words in between with exception using Spacy Matcher

The code I have is from spacy.matcher import Matcher matcher = Matcher(nlp.vocab, validate=True) pattern = [{'LOWER': 'play'}, {'OP': '*'}, {'OP': '!', 'LOWER': 'store'}, {'LOWER': {'IN': ["game", "pacman"]}} …
-1
votes
1 answer

Get an expression from a string meeting a certain pattern

I get a string into a variable user_input that is generated from the user, this string has different characters and line separators, within the string there is an expression that has this pattern (abcd efgh ijkl) where the letters are random…
John Kaita
  • 15
  • 9
-1
votes
1 answer

I have a problem with the java SSHClient class, specifically the Expect method does not return data as espected, what could be happening?

I have used the SSHClient class of java to connect to a Juniper router, when entering the console in the putty console it returns the result without problem, but when doing it from the Java code it does not save what is returned by the command, or…
Esteban
  • 71
  • 1
  • 9
-1
votes
1 answer

Espresso Matcher multiple child custom views

I'm hoping some could help shed some light custom view machers for me. I ran the Record Espresso Test and android-studio generated the following code. ViewInteraction textInputEditText = onView( …
Shawn
  • 1,222
  • 1
  • 18
  • 41
-1
votes
2 answers

Mockito Matchers List
I need to create a mockito that test if he gets a list of Object in entrance. But I find only Matchers.anyList. I need to specify a List. Can anyone help plz ?
Sue
  • 2,380
  • 2
  • 10
  • 11
-1
votes
1 answer

Mockito Invalid use of matchers Mock(Object.class) & anyString()

Ola, I'm busy writing a unit test like monitor.severe(mock(MonitorEventType.class), anyString()); When I execute this I get: Invalid use of argument matchers. 0 matchers expected, 1 recorded. So I…
Bgvv1983
  • 1,256
  • 1
  • 13
  • 27
-1
votes
2 answers

Matcher only matches first result

right now i'm trying to learn how to use Matcher, Patterns and all that stuff, but i'm having a problem and i can't manage to solve it, i'm sure i'm doing something wrong but i don't know what, so i came here to ask for some help, here is my code:…
MaTaMoR_
  • 23
  • 12
-1
votes
1 answer

The Matcher-value in java

I would like to get the value that is inside the tags txt4="