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.ExportModifier.SYNTHETIC;
24  import static org.hamcrest.MatcherAssert.assertThat;
25  import static org.hamcrest.Matchers.contains;
26  import static org.hamcrest.Matchers.equalTo;
27  import static org.hamcrest.Matchers.is;
28  import static org.hamcrest.Matchers.not;
29  import static org.junit.jupiter.api.Assertions.assertFalse;
30  
31  import org.junit.jupiter.api.Test;
32  
33  public class ExportTest {
34  
35  	private static final String PACKAGE = "com.acme.paquet";
36  	private static final String[] MODULES = { "mod.a", "mod.b", "mod.c" };
37  
38  	private final Export export = new Export(PACKAGE, ACC_MANDATED, MODULES);
39  
40  
41  	@Test
42  	public void notEqualWhenPackageDiffers()
43  	{
44  		assertThat(export, is(not(equalTo(new Export("org.acme", ACC_MANDATED, MODULES)))));
45  	}
46  
47  
48  	@Test
49  	public void notEqualWhenAccessDiffers()
50  	{
51  		assertThat(export, is(not(equalTo(new Export(PACKAGE, 0, MODULES)))));
52  	}
53  
54  
55  	@Test
56  	public void notEqualWhenModulesDiffer()
57  	{
58  		assertThat(export, is(not(equalTo(new Export(PACKAGE, ACC_MANDATED, "mod.x", "mod.y", "mod.z")))));
59  	}
60  
61  
62  	@Test
63  	public void notEqualToNullType()
64  	{
65  		assertFalse(export.equals((Export) null));
66  	}
67  
68  
69  	@Test
70  	public void notEqualToNullObject()
71  	{
72  		assertFalse(export.equals((Object) null));
73  	}
74  
75  
76  	@Test
77  	public void modifierIsMappedFromAccess()
78  	{
79  		Export e = new Export(PACKAGE, ACC_SYNTHETIC, MODULES);
80  
81  		assertThat(e.modifiers(), contains(SYNTHETIC));
82  	}
83  
84  
85  	@Test
86  	public void equal()
87  	{
88  		Export identical = new Export(PACKAGE, ACC_MANDATED, MODULES);
89  		assertThat(export, is(equalTo(identical)));
90  		assertThat(export.hashCode(), is(equalTo(identical.hashCode())));
91  	}
92  }