Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
arunvariyath committed Feb 10, 2025
2 parents feb4b3b + 4edde8a commit 1fda670
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 2 deletions.
1 change: 0 additions & 1 deletion libraries-testing-2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -239,5 +239,4 @@
<jgotesting.version>0.12</jgotesting.version>
<javalite.version>1.4.13</javalite.version>
</properties>

</project>
2 changes: 1 addition & 1 deletion testing-modules/easymock/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</dependencies>

<properties>
<easymock.version>4.0.2</easymock.version>
<easymock.version>5.5.0</easymock.version>
</properties>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.baeldung.testing.easymock;

import static org.easymock.EasyMock.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;

public class MatchersUnitTest {

@Test
void whenUsingIsA_thenMatchesTypeAndRejectsNull() {
Service mock = mock(Service.class);
mock.process(isA(String.class));
expectLastCall().times(1);
replay(mock);

mock.process("test");
verify(mock);
}

@Test
void whenUsingIsAWithInheritance_thenMatchesSubclass() {
Service mock = mock(Service.class);
mock.handleRequest(isA(Request.class));
expectLastCall().times(2);
replay(mock);

mock.handleRequest(new Request("normal"));
mock.handleRequest(new SpecialRequest());
verify(mock);
}

@Test
void whenUsingIsAWithNull_thenFails() {
Service mock = mock(Service.class);
mock.process(isA(String.class));
expectLastCall().times(1);
replay(mock);

assertThrows(AssertionError.class, () -> {
mock.process(null);
verify(mock);
});
}

@Test
void whenUsingAnyObject_thenMatchesNullAndAnyType() {
Service mock = mock(Service.class);
mock.process(anyObject());
expectLastCall().times(2);
replay(mock);

mock.process("test");
mock.process(null);
verify(mock);
}

interface Service {
void process(String input);
void handleRequest(Request request);
}

class Request {
private String type;
Request(String type) {
this.type = type;
}
}

class SpecialRequest extends Request {
SpecialRequest() {
super("special");
}
}
}

0 comments on commit 1fda670

Please sign in to comment.