Merge pull request #4044 from Doha2012/master

easymock minor fix
This commit is contained in:
Loredana Crusoveanu 2018-04-19 22:40:19 +03:00 committed by GitHub
commit a1b206ead8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 11 deletions

View File

@ -4,8 +4,6 @@ import java.util.List;
public interface IUserService {
public boolean addUser(User user);
public List<User> findByFirstName(String firstName);
public List<User> findByLastName(String lastName);
public List<User> findByAge(double age);
public List<User> findByEmail(String email);
public List<User> findByAge(double age);
}

View File

@ -60,11 +60,11 @@ public class ArgumentMatchersUnitTest {
//============= anyX
@Test
public void givenUserService_whenSearchForUserByFirstName_thenFound() {
expect(userService.findByFirstName(anyString())).andReturn(Collections.emptyList());
public void givenUserService_whenSearchForUserByEmail_thenFound() {
expect(userService.findByEmail(anyString())).andReturn(Collections.emptyList());
replay(userService);
List<User> result = userService.findByFirstName("joe");
List<User> result = userService.findByEmail("test@example.com");
verify(userService);
assertEquals(0,result.size());
}
@ -191,21 +191,21 @@ public class ArgumentMatchersUnitTest {
//================ custom matcher
@Test
public void givenUserService_whenSearchForUserByLastName_thenFound() {
expect(userService.findByLastName(charCount(3))).andReturn(Collections.emptyList());
public void givenUserService_whenSearchForUserByEmailCharCount_thenFound() {
expect(userService.findByEmail(minCharCount(5))).andReturn(Collections.emptyList());
replay(userService);
List<User> result = userService.findByLastName("doe");
List<User> result = userService.findByEmail("test@example.com");
verify(userService);
assertEquals(0,result.size());
}
public static String charCount(int value){
public static String minCharCount(int value){
EasyMock.reportMatcher(new IArgumentMatcher() {
@Override
public boolean matches(Object argument) {
return argument instanceof String
&& ((String) argument).length() == value;
&& ((String) argument).length() >= value;
}
@Override