Skip to content

Commit 4edde8a

Browse files
Merge pull request #18201 from AndreiBranza/feature/BAEL-7841-diff-between-isa-anyobject
feature/BAEL-7841-difference-between-isa-and-anyobject
2 parents 853a309 + 94233c3 commit 4edde8a

File tree

3 files changed

+75
-2
lines changed

3 files changed

+75
-2
lines changed

libraries-testing-2/pom.xml

-1
Original file line numberDiff line numberDiff line change
@@ -239,5 +239,4 @@
239239
<jgotesting.version>0.12</jgotesting.version>
240240
<javalite.version>1.4.13</javalite.version>
241241
</properties>
242-
243242
</project>

testing-modules/easymock/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
</dependencies>
2424

2525
<properties>
26-
<easymock.version>4.0.2</easymock.version>
26+
<easymock.version>5.5.0</easymock.version>
2727
</properties>
2828

2929
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.baeldung.testing.easymock;
2+
3+
import static org.easymock.EasyMock.*;
4+
import static org.junit.jupiter.api.Assertions.*;
5+
import org.junit.jupiter.api.Test;
6+
7+
public class MatchersUnitTest {
8+
9+
@Test
10+
void whenUsingIsA_thenMatchesTypeAndRejectsNull() {
11+
Service mock = mock(Service.class);
12+
mock.process(isA(String.class));
13+
expectLastCall().times(1);
14+
replay(mock);
15+
16+
mock.process("test");
17+
verify(mock);
18+
}
19+
20+
@Test
21+
void whenUsingIsAWithInheritance_thenMatchesSubclass() {
22+
Service mock = mock(Service.class);
23+
mock.handleRequest(isA(Request.class));
24+
expectLastCall().times(2);
25+
replay(mock);
26+
27+
mock.handleRequest(new Request("normal"));
28+
mock.handleRequest(new SpecialRequest());
29+
verify(mock);
30+
}
31+
32+
@Test
33+
void whenUsingIsAWithNull_thenFails() {
34+
Service mock = mock(Service.class);
35+
mock.process(isA(String.class));
36+
expectLastCall().times(1);
37+
replay(mock);
38+
39+
assertThrows(AssertionError.class, () -> {
40+
mock.process(null);
41+
verify(mock);
42+
});
43+
}
44+
45+
@Test
46+
void whenUsingAnyObject_thenMatchesNullAndAnyType() {
47+
Service mock = mock(Service.class);
48+
mock.process(anyObject());
49+
expectLastCall().times(2);
50+
replay(mock);
51+
52+
mock.process("test");
53+
mock.process(null);
54+
verify(mock);
55+
}
56+
57+
interface Service {
58+
void process(String input);
59+
void handleRequest(Request request);
60+
}
61+
62+
class Request {
63+
private String type;
64+
Request(String type) {
65+
this.type = type;
66+
}
67+
}
68+
69+
class SpecialRequest extends Request {
70+
SpecialRequest() {
71+
super("special");
72+
}
73+
}
74+
}

0 commit comments

Comments
 (0)