View Javadoc
1   /*-
2    * #%L
3    * io.earcam.instrumental.module.jpms
4    * %%
5    * Copyright (C) 2018 earcam
6    * %%
7    * SPDX-License-Identifier: (BSD-3-Clause OR EPL-1.0 OR Apache-2.0 OR MIT)
8    * 
9    * You <b>must</b> choose to accept, in full - any individual or combination of 
10   * the following licenses:
11   * <ul>
12   * 	<li><a href="https://opensource.org/licenses/BSD-3-Clause">BSD-3-Clause</a></li>
13   * 	<li><a href="https://www.eclipse.org/legal/epl-v10.html">EPL-1.0</a></li>
14   * 	<li><a href="https://www.apache.org/licenses/LICENSE-2.0">Apache-2.0</a></li>
15   * 	<li><a href="https://opensource.org/licenses/MIT">MIT</a></li>
16   * </ul>
17   * #L%
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 }