diff --git a/testing-modules/mocks/mock-comparisons/src/main/java/com/baeldung/easymock/IUserService.java b/testing-modules/mocks/mock-comparisons/src/main/java/com/baeldung/easymock/IUserService.java index 4bb74abb64..96609bdf9d 100644 --- a/testing-modules/mocks/mock-comparisons/src/main/java/com/baeldung/easymock/IUserService.java +++ b/testing-modules/mocks/mock-comparisons/src/main/java/com/baeldung/easymock/IUserService.java @@ -4,8 +4,6 @@ import java.util.List; public interface IUserService { public boolean addUser(User user); - public List findByFirstName(String firstName); - public List findByLastName(String lastName); + public List findByEmail(String email); public List findByAge(double age); - public List findByEmail(String email); } diff --git a/testing-modules/mocks/mock-comparisons/src/test/java/com/baeldung/easymock/ArgumentMatchersUnitTest.java b/testing-modules/mocks/mock-comparisons/src/test/java/com/baeldung/easymock/ArgumentMatchersUnitTest.java index 6d4f4c09f5..6205def27b 100644 --- a/testing-modules/mocks/mock-comparisons/src/test/java/com/baeldung/easymock/ArgumentMatchersUnitTest.java +++ b/testing-modules/mocks/mock-comparisons/src/test/java/com/baeldung/easymock/ArgumentMatchersUnitTest.java @@ -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 result = userService.findByFirstName("joe"); + List 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 result = userService.findByLastName("doe"); + List 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