# Unit Testing and good use of matchers

I been having discussion with colleagues recently about good use of matchers. Consider the following sample:

@RunWith(MockitoJUnitRunner.class)

@Mock

@InjectMocks

@Before
public void setUp() throws Exception {
}

@Test
// Given

// When

// Then
}

@Test
// Given

// When

// Then
}
}


Note this is just a sample. Normally we would use a spring MVC for unit testing a REST service. But is the use of anyString() valid. Does it mean we are being too broad with the mocking criteria?

Is there anything else that is wrong with this style?

• Note this is just a sample. we review real, working code, I fear this is off-topic... Sorry Aug 27 '15 at 11:44
• Valid point, I just omitted the inclusion of the spring MVC stuff to make the code more shorter to read. I can edit it with the original code if that preferred Aug 27 '15 at 14:11

Especially for the successfull test I would use the actual expected parameters instead of anyString. For the not successfull test you could do the same, return a result with false if the login data is the expected value (otherwise it will be null).