1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package io.earcam.instrumental.module.jpms;
20
21 import static io.earcam.instrumental.module.jpms.Access.ACC_MANDATED;
22 import static io.earcam.instrumental.module.jpms.Access.ACC_SYNTHETIC;
23 import static io.earcam.instrumental.module.jpms.Access.ACC_TRANSITIVE;
24 import static org.hamcrest.MatcherAssert.assertThat;
25 import static org.hamcrest.Matchers.contains;
26 import static org.hamcrest.Matchers.containsInAnyOrder;
27 import static org.hamcrest.Matchers.equalTo;
28 import static org.hamcrest.Matchers.is;
29 import static org.hamcrest.Matchers.not;
30 import static org.junit.jupiter.api.Assertions.assertFalse;
31
32 import org.junit.jupiter.api.Test;
33
34 public class RequireTest {
35
36 private static final String VERSION = "42.0.1";
37
38 private static final String MODULE = "module";
39
40 Require require = new Require(MODULE, ACC_MANDATED, VERSION);
41
42
43 @Test
44 public void notEqualWhenModuleDiffers()
45 {
46 assertThat(require, is(not(equalTo(new Require("an.other", ACC_MANDATED, VERSION)))));
47 }
48
49
50 @Test
51 public void notEqualWhenAccessDiffers()
52 {
53 assertThat(require, is(not(equalTo(new Require(MODULE, 0, VERSION)))));
54 }
55
56
57 @Test
58 public void notEqualWhenVersionDiffers()
59 {
60 assertThat(require, is(not(equalTo(new Require(MODULE, ACC_MANDATED, "1.0.1")))));
61 }
62
63
64 @Test
65 public void notEqualToNullType()
66 {
67 assertFalse(require.equals((Require) null));
68 }
69
70
71 @Test
72 public void notEqualToNullObject()
73 {
74 assertFalse(require.equals((Object) null));
75 }
76
77
78 @Test
79 public void modifierIsMappedFromAccess()
80 {
81 Require r = new Require(MODULE, ACC_TRANSITIVE, VERSION);
82
83 assertThat(r.modifiers(), contains(RequireModifier.TRANSITIVE));
84 }
85
86
87 @Test
88 public void modifiersAreMappedFromAccess()
89 {
90 Require r = new Require(MODULE, ACC_TRANSITIVE | ACC_SYNTHETIC, VERSION);
91
92 assertThat(r.modifiers(), containsInAnyOrder(RequireModifier.SYNTHETIC, RequireModifier.TRANSITIVE));
93 }
94
95
96 @Test
97 public void equal()
98 {
99 Require identical = new Require(MODULE, ACC_MANDATED, VERSION);
100 assertThat(require, is(equalTo(identical)));
101 assertThat(require.hashCode(), is(equalTo(identical.hashCode())));
102 }
103 }