author | alanb |
Fri, 07 Apr 2017 08:05:54 +0000 | |
changeset 44545 | 83b611b88ac8 |
parent 44359 | c6761862ca0b |
child 45004 | ea3137042a61 |
permissions | -rw-r--r-- |
36511 | 1 |
/* |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
2 |
* Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved. |
36511 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
/** |
|
25 |
* @test |
|
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
26 |
* @modules java.base/jdk.internal.module |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
27 |
* java.base/jdk.internal.misc |
36511 | 28 |
* @run testng ModuleDescriptorTest |
29 |
* @summary Basic test for java.lang.module.ModuleDescriptor and its builder |
|
30 |
*/ |
|
31 |
||
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
32 |
import java.io.ByteArrayOutputStream; |
36511 | 33 |
import java.io.IOException; |
34 |
import java.io.InputStream; |
|
35 |
import java.lang.module.InvalidModuleDescriptorException; |
|
36 |
import java.lang.module.ModuleDescriptor; |
|
37 |
import java.lang.module.ModuleDescriptor.Builder; |
|
38 |
import java.lang.module.ModuleDescriptor.Exports; |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
39 |
import java.lang.module.ModuleDescriptor.Opens; |
36511 | 40 |
import java.lang.module.ModuleDescriptor.Requires; |
41 |
import java.lang.module.ModuleDescriptor.Provides; |
|
42 |
import java.lang.module.ModuleDescriptor.Requires.Modifier; |
|
43 |
import java.lang.module.ModuleDescriptor.Version; |
|
44 |
import java.nio.ByteBuffer; |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
45 |
import java.util.ArrayList; |
36511 | 46 |
import java.util.Collections; |
47 |
import java.util.EnumSet; |
|
48 |
import java.util.HashSet; |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
49 |
import java.util.Iterator; |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
50 |
import java.util.List; |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
51 |
import java.util.Objects; |
44359
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
52 |
import java.util.Optional; |
36511 | 53 |
import java.util.Set; |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
54 |
import java.util.stream.Collectors; |
36511 | 55 |
|
56 |
import static java.lang.module.ModuleDescriptor.Requires.Modifier.*; |
|
57 |
||
44359
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
58 |
import jdk.internal.misc.JavaLangModuleAccess; |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
59 |
import jdk.internal.misc.SharedSecrets; |
39050
9de41b79ec7e
8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents:
36511
diff
changeset
|
60 |
import jdk.internal.module.ModuleInfoWriter; |
36511 | 61 |
import org.testng.annotations.DataProvider; |
62 |
import org.testng.annotations.Test; |
|
63 |
import static org.testng.Assert.*; |
|
64 |
||
65 |
@Test |
|
66 |
public class ModuleDescriptorTest { |
|
67 |
||
68 |
@DataProvider(name = "invalidjavaidentifiers") |
|
69 |
public Object[][] invalidJavaIdentifiers() { |
|
70 |
return new Object[][]{ |
|
71 |
||
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
72 |
{ null, null }, |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
73 |
{ "1", null }, |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
74 |
{ "1foo", null }, |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
75 |
{ ".foo", null }, |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
76 |
{ "foo.", null }, |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
77 |
{ "[foo]", null }, |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
78 |
{ "foo.1", null }, |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
79 |
{ "1foo.bar", null }, |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
80 |
{ "foo.1bar", null }, |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
81 |
{ "foo.[bar]", null }, |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
82 |
{ "foo..bar", null }, |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
83 |
{ "foo.bar.1", null }, |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
84 |
{ "foo.bar.1gus", null }, |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
85 |
{ "foo.bar.[gus]", null }, |
36511 | 86 |
|
87 |
}; |
|
88 |
} |
|
89 |
||
90 |
||
91 |
// requires |
|
92 |
||
93 |
private Requires requires(Set<Modifier> mods, String mn) { |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
94 |
return requires(mods, mn, null); |
36511 | 95 |
} |
96 |
||
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
97 |
private Requires requires(Set<Modifier> mods, String mn, Version v) { |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
98 |
Builder builder = ModuleDescriptor.newModule("m"); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
99 |
if (v == null) { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
100 |
builder.requires(mods, mn); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
101 |
} else { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
102 |
builder.requires(mods, mn, v); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
103 |
} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
104 |
Set<Requires> requires = builder.build().requires(); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
105 |
assertTrue(requires.size() == 2); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
106 |
Iterator<Requires> iterator = requires.iterator(); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
107 |
Requires r = iterator.next(); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
108 |
if (r.name().equals("java.base")) { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
109 |
r = iterator.next(); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
110 |
} else { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
111 |
Requires other = iterator.next(); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
112 |
assertEquals(other.name(), "java.base"); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
113 |
} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
114 |
return r; |
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
115 |
} |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
116 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
117 |
private Requires requires(String mn) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
118 |
return requires(Collections.emptySet(), mn); |
36511 | 119 |
} |
120 |
||
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
121 |
public void testRequiresWithRequires() { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
122 |
Requires r1 = requires("foo"); |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
123 |
ModuleDescriptor descriptor = ModuleDescriptor.newModule("m").requires(r1).build(); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
124 |
Requires r2 = descriptor.requires().iterator().next(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
125 |
assertEquals(r1, r2); |
36511 | 126 |
} |
127 |
||
128 |
public void testRequiresWithNoModifiers() { |
|
129 |
Requires r = requires(EnumSet.noneOf(Requires.Modifier.class), "foo"); |
|
130 |
assertEquals(r, r); |
|
131 |
assertTrue(r.compareTo(r) == 0); |
|
132 |
assertTrue(r.modifiers().isEmpty()); |
|
133 |
assertEquals(r.name(), "foo"); |
|
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
134 |
assertFalse(r.compiledVersion().isPresent()); |
36511 | 135 |
} |
136 |
||
137 |
public void testRequiresWithOneModifier() { |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
138 |
Requires r = requires(EnumSet.of(TRANSITIVE), "foo"); |
36511 | 139 |
assertEquals(r, r); |
140 |
assertTrue(r.compareTo(r) == 0); |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
141 |
assertEquals(r.modifiers(), EnumSet.of(TRANSITIVE)); |
36511 | 142 |
assertEquals(r.name(), "foo"); |
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
143 |
assertFalse(r.compiledVersion().isPresent()); |
36511 | 144 |
} |
145 |
||
146 |
public void testRequiresWithTwoModifiers() { |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
147 |
Requires r = requires(EnumSet.of(TRANSITIVE, SYNTHETIC), "foo"); |
36511 | 148 |
assertEquals(r, r); |
149 |
assertTrue(r.compareTo(r) == 0); |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
150 |
assertEquals(r.modifiers(), EnumSet.of(TRANSITIVE, SYNTHETIC)); |
36511 | 151 |
assertEquals(r.name(), "foo"); |
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
152 |
assertFalse(r.compiledVersion().isPresent()); |
36511 | 153 |
} |
154 |
||
155 |
public void testRequiresWithAllModifiers() { |
|
156 |
Requires r = requires(EnumSet.allOf(Modifier.class), "foo"); |
|
157 |
assertEquals(r, r); |
|
158 |
assertTrue(r.compareTo(r) == 0); |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
159 |
assertEquals(r.modifiers(), EnumSet.of(TRANSITIVE, STATIC, SYNTHETIC, MANDATED)); |
36511 | 160 |
assertEquals(r.name(), "foo"); |
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
161 |
assertFalse(r.compiledVersion().isPresent()); |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
162 |
} |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
163 |
|
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
164 |
public void testRequiresWithCompiledVersion() { |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
165 |
Version v = Version.parse("1.0"); |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
166 |
Requires r = requires(Set.of(), "foo", v); |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
167 |
assertEquals(r, r); |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
168 |
assertTrue(r.compareTo(r) == 0); |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
169 |
assertEquals(r.modifiers(), Set.of()); |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
170 |
assertEquals(r.name(), "foo"); |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
171 |
assertTrue(r.compiledVersion().isPresent()); |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
172 |
assertEquals(r.compiledVersion().get().toString(), "1.0"); |
36511 | 173 |
} |
174 |
||
175 |
@Test(expectedExceptions = IllegalStateException.class) |
|
176 |
public void testRequiresWithDuplicatesRequires() { |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
177 |
Requires r = requires("foo"); |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
178 |
ModuleDescriptor.newModule("m").requires(r).requires(r); |
36511 | 179 |
} |
180 |
||
181 |
@Test(expectedExceptions = IllegalArgumentException.class) |
|
182 |
public void testRequiresSelfWithRequires() { |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
183 |
Requires r = requires("foo"); |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
184 |
ModuleDescriptor.newModule("foo").requires(r); |
36511 | 185 |
} |
186 |
||
187 |
@Test(expectedExceptions = IllegalArgumentException.class) |
|
188 |
public void testRequiresSelfWithNoModifier() { |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
189 |
ModuleDescriptor.newModule("m").requires("m"); |
36511 | 190 |
} |
191 |
||
192 |
@Test(expectedExceptions = IllegalArgumentException.class) |
|
193 |
public void testRequiresSelfWithOneModifier() { |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
194 |
ModuleDescriptor.newModule("m").requires(Set.of(TRANSITIVE), "m"); |
36511 | 195 |
} |
196 |
||
197 |
@Test(expectedExceptions = IllegalArgumentException.class) |
|
198 |
public void testRequiresSelfWithAllModifiers() { |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
199 |
ModuleDescriptor.newModule("m").requires(EnumSet.allOf(Modifier.class), "m"); |
36511 | 200 |
} |
201 |
||
202 |
@Test(dataProvider = "invalidjavaidentifiers", |
|
203 |
expectedExceptions = IllegalArgumentException.class ) |
|
204 |
public void testRequiresWithBadModuleName(String mn, String ignore) { |
|
205 |
requires(EnumSet.noneOf(Modifier.class), mn); |
|
206 |
} |
|
207 |
||
208 |
@Test(expectedExceptions = NullPointerException.class) |
|
209 |
public void testRequiresWithNullRequires() { |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
210 |
ModuleDescriptor.newModule("m").requires((Requires) null); |
36511 | 211 |
} |
212 |
||
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
213 |
@Test(expectedExceptions = NullPointerException.class) |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
214 |
public void testRequiresWithNullModifiers() { |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
215 |
ModuleDescriptor.newModule("m").requires(null, "foo"); |
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
216 |
} |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
217 |
|
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
218 |
@Test(expectedExceptions = NullPointerException.class) |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
219 |
public void testRequiresWithNullVersion() { |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
220 |
ModuleDescriptor.newModule("m").requires(Set.of(), "foo", null); |
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
221 |
} |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
222 |
|
36511 | 223 |
public void testRequiresCompare() { |
224 |
Requires r1 = requires(EnumSet.noneOf(Modifier.class), "foo"); |
|
225 |
Requires r2 = requires(EnumSet.noneOf(Modifier.class), "bar"); |
|
226 |
int n = "foo".compareTo("bar"); |
|
227 |
assertTrue(r1.compareTo(r2) == n); |
|
228 |
assertTrue(r2.compareTo(r1) == -n); |
|
229 |
} |
|
230 |
||
39064
45cbf2937973
8159762: Some minor test bugs in java/lang/module/ModuleDescriptorTest.java
mli
parents:
39050
diff
changeset
|
231 |
public void testRequiresCompareWithDifferentModifiers() { |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
232 |
Requires r1 = requires(EnumSet.of(TRANSITIVE), "foo"); |
39064
45cbf2937973
8159762: Some minor test bugs in java/lang/module/ModuleDescriptorTest.java
mli
parents:
39050
diff
changeset
|
233 |
Requires r2 = requires(EnumSet.of(SYNTHETIC), "foo"); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
234 |
int n = Integer.compare(1 << TRANSITIVE.ordinal(), 1 << SYNTHETIC.ordinal()); |
39064
45cbf2937973
8159762: Some minor test bugs in java/lang/module/ModuleDescriptorTest.java
mli
parents:
39050
diff
changeset
|
235 |
assertTrue(r1.compareTo(r2) == n); |
45cbf2937973
8159762: Some minor test bugs in java/lang/module/ModuleDescriptorTest.java
mli
parents:
39050
diff
changeset
|
236 |
assertTrue(r2.compareTo(r1) == -n); |
45cbf2937973
8159762: Some minor test bugs in java/lang/module/ModuleDescriptorTest.java
mli
parents:
39050
diff
changeset
|
237 |
} |
45cbf2937973
8159762: Some minor test bugs in java/lang/module/ModuleDescriptorTest.java
mli
parents:
39050
diff
changeset
|
238 |
|
45cbf2937973
8159762: Some minor test bugs in java/lang/module/ModuleDescriptorTest.java
mli
parents:
39050
diff
changeset
|
239 |
public void testRequiresCompareWithSameModifiers() { |
45cbf2937973
8159762: Some minor test bugs in java/lang/module/ModuleDescriptorTest.java
mli
parents:
39050
diff
changeset
|
240 |
Requires r1 = requires(EnumSet.of(SYNTHETIC), "foo"); |
45cbf2937973
8159762: Some minor test bugs in java/lang/module/ModuleDescriptorTest.java
mli
parents:
39050
diff
changeset
|
241 |
Requires r2 = requires(EnumSet.of(SYNTHETIC), "foo"); |
45cbf2937973
8159762: Some minor test bugs in java/lang/module/ModuleDescriptorTest.java
mli
parents:
39050
diff
changeset
|
242 |
assertTrue(r1.compareTo(r2) == 0); |
45cbf2937973
8159762: Some minor test bugs in java/lang/module/ModuleDescriptorTest.java
mli
parents:
39050
diff
changeset
|
243 |
assertTrue(r2.compareTo(r1) == 0); |
45cbf2937973
8159762: Some minor test bugs in java/lang/module/ModuleDescriptorTest.java
mli
parents:
39050
diff
changeset
|
244 |
} |
45cbf2937973
8159762: Some minor test bugs in java/lang/module/ModuleDescriptorTest.java
mli
parents:
39050
diff
changeset
|
245 |
|
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
246 |
public void testRequiresCompareWithSameCompiledVersion() { |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
247 |
Requires r1 = requires(Set.of(), "foo", Version.parse("2.0")); |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
248 |
Requires r2 = requires(Set.of(), "foo", Version.parse("2.0")); |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
249 |
assertTrue(r1.compareTo(r2) == 0); |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
250 |
assertTrue(r2.compareTo(r1) == 0); |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
251 |
} |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
252 |
|
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
253 |
public void testRequiresCompareWithDifferentCompiledVersion() { |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
254 |
Requires r1 = requires(Set.of(), "foo", Version.parse("1.0")); |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
255 |
Requires r2 = requires(Set.of(), "foo", Version.parse("2.0")); |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
256 |
assertTrue(r1.compareTo(r2) < 0); |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
257 |
assertTrue(r2.compareTo(r1) > 0); |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
258 |
} |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
259 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
260 |
public void testRequiresEqualsAndHashCode() { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
261 |
Requires r1 = requires("foo"); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
262 |
Requires r2 = requires("foo"); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
263 |
assertEquals(r1, r2); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
264 |
assertTrue(r1.hashCode() == r2.hashCode()); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
265 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
266 |
r1 = requires(EnumSet.allOf(Requires.Modifier.class), "foo"); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
267 |
r2 = requires(EnumSet.allOf(Requires.Modifier.class), "foo"); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
268 |
assertEquals(r1, r2); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
269 |
assertTrue(r1.hashCode() == r2.hashCode()); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
270 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
271 |
r1 = requires("foo"); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
272 |
r2 = requires("bar"); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
273 |
assertNotEquals(r1, r2); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
274 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
275 |
r1 = requires(EnumSet.allOf(Requires.Modifier.class), "foo"); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
276 |
r2 = requires(Set.of(), "foo"); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
277 |
assertNotEquals(r1, r2); |
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
278 |
|
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
279 |
Version v1 = Version.parse("1.0"); |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
280 |
r1 = requires(EnumSet.allOf(Requires.Modifier.class), "foo", v1); |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
281 |
r2 = requires(EnumSet.allOf(Requires.Modifier.class), "foo", v1); |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
282 |
assertEquals(r1, r2); |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
283 |
assertTrue(r1.hashCode() == r2.hashCode()); |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
284 |
|
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
285 |
Version v2 = Version.parse("2.0"); |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
286 |
r1 = requires(EnumSet.allOf(Requires.Modifier.class), "foo", v1); |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
287 |
r2 = requires(EnumSet.allOf(Requires.Modifier.class), "foo", v2); |
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
288 |
assertNotEquals(r1, r2); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
289 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
290 |
|
36511 | 291 |
public void testRequiresToString() { |
292 |
Requires r = requires(EnumSet.noneOf(Modifier.class), "foo"); |
|
293 |
assertTrue(r.toString().contains("foo")); |
|
294 |
} |
|
295 |
||
296 |
||
297 |
// exports |
|
298 |
||
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
299 |
private Exports exports(Set<Exports.Modifier> mods, String pn) { |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
300 |
return ModuleDescriptor.newModule("foo") |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
301 |
.exports(mods, pn) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
302 |
.build() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
303 |
.exports() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
304 |
.iterator() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
305 |
.next(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
306 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
307 |
|
36511 | 308 |
private Exports exports(String pn) { |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
309 |
return exports(Set.of(), pn); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
310 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
311 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
312 |
private Exports exports(Set<Exports.Modifier> mods, String pn, String target) { |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
313 |
return ModuleDescriptor.newModule("foo") |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
314 |
.exports(mods, pn, Set.of(target)) |
36511 | 315 |
.build() |
316 |
.exports() |
|
317 |
.iterator() |
|
318 |
.next(); |
|
319 |
} |
|
320 |
||
321 |
private Exports exports(String pn, String target) { |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
322 |
return exports(Set.of(), pn, target); |
36511 | 323 |
} |
324 |
||
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
325 |
|
36511 | 326 |
public void testExportsExports() { |
327 |
Exports e1 = exports("p"); |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
328 |
ModuleDescriptor descriptor = ModuleDescriptor.newModule("m").exports(e1).build(); |
36511 | 329 |
Exports e2 = descriptor.exports().iterator().next(); |
330 |
assertEquals(e1, e2); |
|
331 |
} |
|
332 |
||
333 |
public void testExportsToAll() { |
|
334 |
Exports e = exports("p"); |
|
335 |
assertEquals(e, e); |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
336 |
assertTrue(e.modifiers().isEmpty()); |
36511 | 337 |
assertEquals(e.source(), "p"); |
338 |
assertFalse(e.isQualified()); |
|
339 |
assertTrue(e.targets().isEmpty()); |
|
340 |
} |
|
341 |
||
342 |
public void testExportsToTarget() { |
|
343 |
Exports e = exports("p", "bar"); |
|
344 |
assertEquals(e, e); |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
345 |
assertTrue(e.modifiers().isEmpty()); |
36511 | 346 |
assertEquals(e.source(), "p"); |
347 |
assertTrue(e.isQualified()); |
|
348 |
assertTrue(e.targets().size() == 1); |
|
349 |
assertTrue(e.targets().contains("bar")); |
|
350 |
} |
|
351 |
||
352 |
public void testExportsToTargets() { |
|
353 |
Set<String> targets = new HashSet<>(); |
|
354 |
targets.add("bar"); |
|
355 |
targets.add("gus"); |
|
356 |
Exports e |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
357 |
= ModuleDescriptor.newModule("foo") |
36511 | 358 |
.exports("p", targets) |
359 |
.build() |
|
360 |
.exports() |
|
361 |
.iterator() |
|
362 |
.next(); |
|
363 |
assertEquals(e, e); |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
364 |
assertTrue(e.modifiers().isEmpty()); |
36511 | 365 |
assertEquals(e.source(), "p"); |
366 |
assertTrue(e.isQualified()); |
|
367 |
assertTrue(e.targets().size() == 2); |
|
368 |
assertTrue(e.targets().contains("bar")); |
|
369 |
assertTrue(e.targets().contains("gus")); |
|
370 |
} |
|
371 |
||
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
372 |
public void testExportsToAllWithModifier() { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
373 |
Exports e = exports(Set.of(Exports.Modifier.SYNTHETIC), "p"); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
374 |
assertEquals(e, e); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
375 |
assertTrue(e.modifiers().size() == 1); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
376 |
assertTrue(e.modifiers().contains(Exports.Modifier.SYNTHETIC)); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
377 |
assertEquals(e.source(), "p"); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
378 |
assertFalse(e.isQualified()); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
379 |
assertTrue(e.targets().isEmpty()); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
380 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
381 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
382 |
public void testExportsToTargetWithModifier() { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
383 |
Exports e = exports(Set.of(Exports.Modifier.SYNTHETIC), "p", "bar"); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
384 |
assertEquals(e, e); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
385 |
assertTrue(e.modifiers().size() == 1); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
386 |
assertTrue(e.modifiers().contains(Exports.Modifier.SYNTHETIC)); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
387 |
assertEquals(e.source(), "p"); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
388 |
assertTrue(e.isQualified()); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
389 |
assertTrue(e.targets().size() == 1); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
390 |
assertTrue(e.targets().contains("bar")); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
391 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
392 |
|
36511 | 393 |
@Test(expectedExceptions = IllegalStateException.class) |
394 |
public void testExportsWithDuplicate1() { |
|
395 |
Exports e = exports("p"); |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
396 |
ModuleDescriptor.newModule("foo").exports(e).exports(e); |
36511 | 397 |
} |
398 |
||
399 |
@Test(expectedExceptions = IllegalStateException.class) |
|
400 |
public void testExportsWithDuplicate2() { |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
401 |
ModuleDescriptor.newModule("foo").exports("p").exports("p"); |
36511 | 402 |
} |
403 |
||
404 |
@Test(expectedExceptions = IllegalArgumentException.class ) |
|
405 |
public void testExportsWithEmptySet() { |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
406 |
ModuleDescriptor.newModule("foo").exports("p", Collections.emptySet()); |
36511 | 407 |
} |
408 |
||
409 |
@Test(dataProvider = "invalidjavaidentifiers", |
|
410 |
expectedExceptions = IllegalArgumentException.class ) |
|
411 |
public void testExportsWithBadName(String pn, String ignore) { |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
412 |
ModuleDescriptor.newModule("foo").exports(pn); |
36511 | 413 |
} |
414 |
||
415 |
@Test(expectedExceptions = NullPointerException.class ) |
|
416 |
public void testExportsWithNullExports() { |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
417 |
ModuleDescriptor.newModule("foo").exports((Exports) null); |
36511 | 418 |
} |
419 |
||
420 |
@Test(expectedExceptions = NullPointerException.class ) |
|
421 |
public void testExportsWithNullTargets() { |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
422 |
ModuleDescriptor.newModule("foo").exports("p", (Set<String>) null); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
423 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
424 |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
425 |
public void testExportsCompare() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
426 |
Exports e1 = exports("p"); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
427 |
Exports e2 = exports("p"); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
428 |
assertEquals(e1, e2); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
429 |
assertTrue(e1.hashCode() == e2.hashCode()); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
430 |
assertTrue(e1.compareTo(e2) == 0); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
431 |
assertTrue(e2.compareTo(e1) == 0); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
432 |
} |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
433 |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
434 |
public void testExportsCompareWithSameModifiers() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
435 |
Exports e1 = exports(Set.of(Exports.Modifier.SYNTHETIC), "p"); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
436 |
Exports e2 = exports(Set.of(Exports.Modifier.SYNTHETIC), "p"); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
437 |
assertEquals(e1, e2); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
438 |
assertTrue(e1.hashCode() == e2.hashCode()); |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
439 |
assertTrue(e1.compareTo(e2) == 0); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
440 |
assertTrue(e2.compareTo(e1) == 0); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
441 |
} |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
442 |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
443 |
public void testExportsCompareWithDifferentModifiers() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
444 |
Exports e1 = exports(Set.of(Exports.Modifier.SYNTHETIC), "p"); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
445 |
Exports e2 = exports("p"); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
446 |
assertNotEquals(e1, e2); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
447 |
assertTrue(e1.compareTo(e2) == 1); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
448 |
assertTrue(e2.compareTo(e1) == -1); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
449 |
} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
450 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
451 |
public void testExportsCompareWithSameTargets() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
452 |
Exports e1 = exports("p", "x"); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
453 |
Exports e2 = exports("p", "x"); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
454 |
assertEquals(e1, e2); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
455 |
assertTrue(e1.hashCode() == e2.hashCode()); |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
456 |
assertTrue(e1.compareTo(e2) == 0); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
457 |
assertTrue(e2.compareTo(e1) == 0); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
458 |
} |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
459 |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
460 |
public void testExportsCompareWithDifferentTargets() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
461 |
Exports e1 = exports("p", "y"); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
462 |
Exports e2 = exports("p", "x"); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
463 |
assertNotEquals(e1, e2); |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
464 |
assertTrue(e1.compareTo(e2) == 1); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
465 |
assertTrue(e2.compareTo(e1) == -1); |
36511 | 466 |
} |
467 |
||
468 |
public void testExportsToString() { |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
469 |
String s = ModuleDescriptor.newModule("foo") |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
470 |
.exports("p1", Set.of("bar")) |
36511 | 471 |
.build() |
472 |
.exports() |
|
473 |
.iterator() |
|
474 |
.next() |
|
475 |
.toString(); |
|
476 |
assertTrue(s.contains("p1")); |
|
477 |
assertTrue(s.contains("bar")); |
|
478 |
} |
|
479 |
||
480 |
||
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
481 |
// opens |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
482 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
483 |
private Opens opens(Set<Opens.Modifier> mods, String pn) { |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
484 |
return ModuleDescriptor.newModule("foo") |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
485 |
.opens(mods, pn) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
486 |
.build() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
487 |
.opens() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
488 |
.iterator() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
489 |
.next(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
490 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
491 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
492 |
private Opens opens(String pn) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
493 |
return opens(Set.of(), pn); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
494 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
495 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
496 |
private Opens opens(Set<Opens.Modifier> mods, String pn, String target) { |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
497 |
return ModuleDescriptor.newModule("foo") |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
498 |
.opens(mods, pn, Set.of(target)) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
499 |
.build() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
500 |
.opens() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
501 |
.iterator() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
502 |
.next(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
503 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
504 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
505 |
private Opens opens(String pn, String target) { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
506 |
return opens(Set.of(), pn, target); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
507 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
508 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
509 |
public void testOpensOpens() { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
510 |
Opens o1 = opens("p"); |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
511 |
ModuleDescriptor descriptor = ModuleDescriptor.newModule("m").opens(o1).build(); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
512 |
Opens o2 = descriptor.opens().iterator().next(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
513 |
assertEquals(o1, o2); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
514 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
515 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
516 |
public void testOpensToAll() { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
517 |
Opens o = opens("p"); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
518 |
assertEquals(o, o); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
519 |
assertTrue(o.modifiers().isEmpty()); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
520 |
assertEquals(o.source(), "p"); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
521 |
assertFalse(o.isQualified()); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
522 |
assertTrue(o.targets().isEmpty()); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
523 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
524 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
525 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
526 |
public void testOpensToTarget() { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
527 |
Opens o = opens("p", "bar"); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
528 |
assertEquals(o, o); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
529 |
assertTrue(o.modifiers().isEmpty()); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
530 |
assertEquals(o.source(), "p"); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
531 |
assertTrue(o.isQualified()); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
532 |
assertTrue(o.targets().size() == 1); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
533 |
assertTrue(o.targets().contains("bar")); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
534 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
535 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
536 |
public void testOpensToTargets() { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
537 |
Set<String> targets = new HashSet<>(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
538 |
targets.add("bar"); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
539 |
targets.add("gus"); |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
540 |
Opens o = ModuleDescriptor.newModule("foo") |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
541 |
.opens("p", targets) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
542 |
.build() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
543 |
.opens() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
544 |
.iterator() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
545 |
.next(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
546 |
assertEquals(o, o); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
547 |
assertTrue(o.modifiers().isEmpty()); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
548 |
assertEquals(o.source(), "p"); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
549 |
assertTrue(o.isQualified()); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
550 |
assertTrue(o.targets().size() == 2); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
551 |
assertTrue(o.targets().contains("bar")); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
552 |
assertTrue(o.targets().contains("gus")); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
553 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
554 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
555 |
@Test(expectedExceptions = IllegalStateException.class) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
556 |
public void testOpensWithDuplicate1() { |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
557 |
Opens o = opens("p"); |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
558 |
ModuleDescriptor.newModule("foo").opens(o).opens(o); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
559 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
560 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
561 |
@Test(expectedExceptions = IllegalStateException.class) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
562 |
public void testOpensWithDuplicate2() { |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
563 |
ModuleDescriptor.newModule("foo").opens("p").opens("p"); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
564 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
565 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
566 |
@Test(expectedExceptions = IllegalArgumentException.class ) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
567 |
public void testOpensWithEmptySet() { |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
568 |
ModuleDescriptor.newModule("foo").opens("p", Collections.emptySet()); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
569 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
570 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
571 |
@Test(dataProvider = "invalidjavaidentifiers", |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
572 |
expectedExceptions = IllegalArgumentException.class ) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
573 |
public void testOpensWithBadName(String pn, String ignore) { |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
574 |
ModuleDescriptor.newModule("foo").opens(pn); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
575 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
576 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
577 |
@Test(expectedExceptions = NullPointerException.class ) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
578 |
public void testOpensWithNullExports() { |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
579 |
ModuleDescriptor.newModule("foo").opens((Opens) null); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
580 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
581 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
582 |
@Test(expectedExceptions = NullPointerException.class ) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
583 |
public void testOpensWithNullTargets() { |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
584 |
ModuleDescriptor.newModule("foo").opens("p", (Set<String>) null); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
585 |
} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
586 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
587 |
public void testOpensCompare() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
588 |
Opens o1 = opens("p"); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
589 |
Opens o2 = opens("p"); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
590 |
assertEquals(o1, o2); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
591 |
assertTrue(o1.hashCode() == o2.hashCode()); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
592 |
assertTrue(o1.compareTo(o2) == 0); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
593 |
assertTrue(o2.compareTo(o1) == 0); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
594 |
} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
595 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
596 |
public void testOpensCompareWithSameModifiers() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
597 |
Opens o1 = opens(Set.of(Opens.Modifier.SYNTHETIC), "p"); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
598 |
Opens o2 = opens(Set.of(Opens.Modifier.SYNTHETIC), "p"); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
599 |
assertEquals(o1, o2); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
600 |
assertTrue(o1.hashCode() == o2.hashCode()); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
601 |
assertTrue(o1.compareTo(o2) == 0); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
602 |
assertTrue(o2.compareTo(o1) == 0); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
603 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
604 |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
605 |
public void testOpensCompareWithDifferentModifiers() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
606 |
Opens o1 = opens(Set.of(Opens.Modifier.SYNTHETIC), "p"); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
607 |
Opens o2 = opens("p"); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
608 |
assertNotEquals(o1, o2); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
609 |
assertTrue(o1.compareTo(o2) == 1); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
610 |
assertTrue(o2.compareTo(o1) == -1); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
611 |
} |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
612 |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
613 |
public void testOpensCompareWithSameTargets() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
614 |
Opens o1 = opens("p", "x"); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
615 |
Opens o2 = opens("p", "x"); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
616 |
assertEquals(o1, o2); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
617 |
assertTrue(o1.hashCode() == o2.hashCode()); |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
618 |
assertTrue(o1.compareTo(o2) == 0); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
619 |
assertTrue(o2.compareTo(o1) == 0); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
620 |
} |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
621 |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
622 |
public void testOpensCompareWithDifferentTargets() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
623 |
Opens o1 = opens("p", "y"); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
624 |
Opens o2 = opens("p", "x"); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
625 |
assertNotEquals(o1, o2); |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
626 |
assertTrue(o1.compareTo(o2) == 1); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
627 |
assertTrue(o2.compareTo(o1) == -1); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
628 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
629 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
630 |
public void testOpensToString() { |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
631 |
String s = ModuleDescriptor.newModule("foo") |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
632 |
.opens("p1", Set.of("bar")) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
633 |
.build() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
634 |
.opens() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
635 |
.iterator() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
636 |
.next() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
637 |
.toString(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
638 |
assertTrue(s.contains("p1")); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
639 |
assertTrue(s.contains("bar")); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
640 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
641 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
642 |
|
36511 | 643 |
// uses |
644 |
||
645 |
public void testUses() { |
|
646 |
Set<String> uses |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
647 |
= ModuleDescriptor.newModule("foo") |
36511 | 648 |
.uses("p.S") |
649 |
.uses("q.S") |
|
650 |
.build() |
|
651 |
.uses(); |
|
652 |
assertTrue(uses.size() == 2); |
|
653 |
assertTrue(uses.contains("p.S")); |
|
654 |
assertTrue(uses.contains("q.S")); |
|
655 |
} |
|
656 |
||
657 |
@Test(expectedExceptions = IllegalStateException.class) |
|
658 |
public void testUsesWithDuplicate() { |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
659 |
ModuleDescriptor.newModule("foo").uses("p.S").uses("p.S"); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
660 |
} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
661 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
662 |
@Test(expectedExceptions = IllegalArgumentException.class) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
663 |
public void testUsesWithSimpleIdentifier() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
664 |
ModuleDescriptor.newModule("foo").uses("S"); |
36511 | 665 |
} |
666 |
||
667 |
@Test(dataProvider = "invalidjavaidentifiers", |
|
668 |
expectedExceptions = IllegalArgumentException.class ) |
|
669 |
public void testUsesWithBadName(String service, String ignore) { |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
670 |
ModuleDescriptor.newModule("foo").uses(service); |
36511 | 671 |
} |
672 |
||
673 |
||
674 |
// provides |
|
675 |
||
676 |
private Provides provides(String st, String pc) { |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
677 |
return ModuleDescriptor.newModule("foo") |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
678 |
.provides(st, List.of(pc)) |
36511 | 679 |
.build() |
680 |
.provides() |
|
681 |
.iterator() |
|
682 |
.next(); |
|
683 |
} |
|
684 |
||
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
685 |
private Provides provides(String st, List<String> pns) { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
686 |
return ModuleDescriptor.newModule("foo") |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
687 |
.provides(st, pns) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
688 |
.build() |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
689 |
.provides() |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
690 |
.iterator() |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
691 |
.next(); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
692 |
} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
693 |
|
36511 | 694 |
public void testProvidesWithProvides() { |
695 |
Provides p1 = provides("p.S", "q.S1"); |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
696 |
ModuleDescriptor descriptor = ModuleDescriptor.newModule("m") |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
697 |
.provides(p1) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
698 |
.build(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
699 |
Provides p2 = descriptor.provides().iterator().next(); |
36511 | 700 |
assertEquals(p1, p2); |
701 |
} |
|
702 |
||
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
703 |
|
36511 | 704 |
public void testProvides() { |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
705 |
Set<Provides> set = ModuleDescriptor.newModule("foo") |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
706 |
.provides("p.S", List.of("q.P1", "q.P2")) |
36511 | 707 |
.build() |
708 |
.provides(); |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
709 |
assertTrue(set.size() == 1); |
36511 | 710 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
711 |
Provides p = set.iterator().next(); |
36511 | 712 |
assertEquals(p, p); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
713 |
assertEquals(p.service(), "p.S"); |
36511 | 714 |
assertTrue(p.providers().size() == 2); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
715 |
assertEquals(p.providers().get(0), "q.P1"); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
716 |
assertEquals(p.providers().get(1), "q.P2"); |
36511 | 717 |
} |
718 |
||
719 |
@Test(expectedExceptions = IllegalStateException.class ) |
|
720 |
public void testProvidesWithDuplicateProvides() { |
|
721 |
Provides p = provides("p.S", "q.S2"); |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
722 |
ModuleDescriptor.newModule("m").provides("p.S", List.of("q.S1")).provides(p); |
36511 | 723 |
} |
724 |
||
725 |
@Test(expectedExceptions = IllegalArgumentException.class ) |
|
726 |
public void testProvidesWithEmptySet() { |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
727 |
ModuleDescriptor.newModule("foo").provides("p.Service", Collections.emptyList()); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
728 |
} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
729 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
730 |
@Test(expectedExceptions = IllegalArgumentException.class ) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
731 |
public void testProvidesWithSimpleIdentifier1() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
732 |
ModuleDescriptor.newModule("foo").provides("S", List.of("q.P")); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
733 |
} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
734 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
735 |
@Test(expectedExceptions = IllegalArgumentException.class ) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
736 |
public void testProvidesWithSimpleIdentifier2() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
737 |
ModuleDescriptor.newModule("foo").provides("p.S", List.of("P")); |
36511 | 738 |
} |
739 |
||
740 |
@Test(dataProvider = "invalidjavaidentifiers", |
|
741 |
expectedExceptions = IllegalArgumentException.class ) |
|
742 |
public void testProvidesWithBadService(String service, String ignore) { |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
743 |
ModuleDescriptor.newModule("foo").provides(service, List.of("p.Provider")); |
36511 | 744 |
} |
745 |
||
746 |
@Test(dataProvider = "invalidjavaidentifiers", |
|
747 |
expectedExceptions = IllegalArgumentException.class ) |
|
748 |
public void testProvidesWithBadProvider(String provider, String ignore) { |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
749 |
List<String> names = new ArrayList<>(); // allows nulls |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
750 |
names.add(provider); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
751 |
ModuleDescriptor.newModule("foo").provides("p.Service", names); |
36511 | 752 |
} |
753 |
||
754 |
@Test(expectedExceptions = NullPointerException.class ) |
|
755 |
public void testProvidesWithNullProvides() { |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
756 |
ModuleDescriptor.newModule("foo").provides((Provides) null); |
36511 | 757 |
} |
758 |
||
759 |
@Test(expectedExceptions = NullPointerException.class ) |
|
760 |
public void testProvidesWithNullProviders() { |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
761 |
ModuleDescriptor.newModule("foo").provides("p.S", (List<String>) null); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
762 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
763 |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
764 |
public void testProvidesCompare() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
765 |
Provides p1 = provides("p.S", "q.S1"); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
766 |
Provides p2 = provides("p.S", "q.S1"); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
767 |
assertEquals(p1, p2); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
768 |
assertTrue(p1.hashCode() == p2.hashCode()); |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
769 |
assertTrue(p1.compareTo(p2) == 0); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
770 |
assertTrue(p2.compareTo(p1) == 0); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
771 |
} |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
772 |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
773 |
public void testProvidesCompareWithDifferentService() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
774 |
Provides p1 = provides("p.S2", "q.S1"); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
775 |
Provides p2 = provides("p.S1", "q.S1"); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
776 |
assertNotEquals(p1, p2); |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
777 |
assertTrue(p1.compareTo(p2) == 1); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
778 |
assertTrue(p2.compareTo(p1) == -1); |
36511 | 779 |
} |
780 |
||
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
781 |
public void testProvidesCompareWithDifferentProviders1() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
782 |
Provides p1 = provides("p.S", "q.S2"); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
783 |
Provides p2 = provides("p.S", "q.S1"); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
784 |
assertNotEquals(p1, p2); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
785 |
assertTrue(p1.compareTo(p2) == 1); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
786 |
assertTrue(p2.compareTo(p1) == -1); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
787 |
} |
36511 | 788 |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
789 |
public void testProvidesCompareWithDifferentProviders2() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
790 |
Provides p1 = provides("p.S", List.of("q.S1", "q.S2")); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
791 |
Provides p2 = provides("p.S", "q.S1"); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
792 |
assertNotEquals(p1, p2); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
793 |
assertTrue(p1.compareTo(p2) == 1); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
794 |
assertTrue(p2.compareTo(p1) == -1); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
795 |
} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
796 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
797 |
// packages |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
798 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
799 |
public void testPackages1() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
800 |
Set<String> packages = ModuleDescriptor.newModule("foo") |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
801 |
.packages(Set.of("p", "q")) |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
802 |
.build() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
803 |
.packages(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
804 |
assertTrue(packages.size() == 2); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
805 |
assertTrue(packages.contains("p")); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
806 |
assertTrue(packages.contains("q")); |
36511 | 807 |
} |
808 |
||
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
809 |
public void testPackages2() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
810 |
Set<String> packages = ModuleDescriptor.newModule("foo") |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
811 |
.packages(Set.of("p")) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
812 |
.packages(Set.of("q")) |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
813 |
.build() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
814 |
.packages(); |
36511 | 815 |
assertTrue(packages.size() == 2); |
816 |
assertTrue(packages.contains("p")); |
|
817 |
assertTrue(packages.contains("q")); |
|
818 |
} |
|
819 |
||
820 |
||
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
821 |
public void testPackagesWithEmptySet() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
822 |
Set<String> packages = ModuleDescriptor.newModule("foo") |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
823 |
.packages(Collections.emptySet()) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
824 |
.build() |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
825 |
.packages(); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
826 |
assertTrue(packages.size() == 0); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
827 |
} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
828 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
829 |
public void testPackagesDuplicate() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
830 |
Set<String> packages = ModuleDescriptor.newModule("foo") |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
831 |
.packages(Set.of("p")) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
832 |
.packages(Set.of("p")) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
833 |
.build() |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
834 |
.packages(); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
835 |
assertTrue(packages.size() == 1); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
836 |
assertTrue(packages.contains("p")); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
837 |
} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
838 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
839 |
public void testPackagesAndExportsPackage1() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
840 |
Set<String> packages = ModuleDescriptor.newModule("foo") |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
841 |
.packages(Set.of("p")) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
842 |
.exports("p") |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
843 |
.build() |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
844 |
.packages(); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
845 |
assertTrue(packages.size() == 1); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
846 |
assertTrue(packages.contains("p")); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
847 |
} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
848 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
849 |
public void testPackagesAndExportsPackage2() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
850 |
Set<String> packages = ModuleDescriptor.newModule("foo") |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
851 |
.exports("p") |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
852 |
.packages(Set.of("p")) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
853 |
.build() |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
854 |
.packages(); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
855 |
assertTrue(packages.size() == 1); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
856 |
assertTrue(packages.contains("p")); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
857 |
} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
858 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
859 |
public void testPackagesAndOpensPackage1() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
860 |
Set<String> packages = ModuleDescriptor.newModule("foo") |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
861 |
.packages(Set.of("p")) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
862 |
.opens("p") |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
863 |
.build() |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
864 |
.packages(); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
865 |
assertTrue(packages.size() == 1); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
866 |
assertTrue(packages.contains("p")); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
867 |
} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
868 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
869 |
public void testPackagesAndOpensPackage2() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
870 |
Set<String> packages = ModuleDescriptor.newModule("foo") |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
871 |
.opens("p") |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
872 |
.packages(Set.of("p")) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
873 |
.build() |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
874 |
.packages(); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
875 |
assertTrue(packages.size() == 1); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
876 |
assertTrue(packages.contains("p")); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
877 |
} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
878 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
879 |
public void testPackagesAndProvides1() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
880 |
Set<String> packages = ModuleDescriptor.newModule("foo") |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
881 |
.packages(Set.of("p")) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
882 |
.provides("q.S", List.of("p.T")) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
883 |
.build() |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
884 |
.packages(); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
885 |
assertTrue(packages.size() == 1); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
886 |
assertTrue(packages.contains("p")); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
887 |
} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
888 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
889 |
public void testPackagesAndProvides2() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
890 |
Set<String> packages = ModuleDescriptor.newModule("foo") |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
891 |
.provides("q.S", List.of("p.T")) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
892 |
.packages(Set.of("p")) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
893 |
.build() |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
894 |
.packages(); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
895 |
assertTrue(packages.size() == 1); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
896 |
assertTrue(packages.contains("p")); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
897 |
} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
898 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
899 |
public void testPackagesAndMainClass1() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
900 |
Set<String> packages = ModuleDescriptor.newModule("foo") |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
901 |
.packages(Set.of("p")) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
902 |
.mainClass("p.Main") |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
903 |
.build() |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
904 |
.packages(); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
905 |
assertTrue(packages.size() == 1); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
906 |
assertTrue(packages.contains("p")); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
907 |
} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
908 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
909 |
public void testPackagesAndMainClass2() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
910 |
Set<String> packages = ModuleDescriptor.newModule("foo") |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
911 |
.mainClass("p.Main") |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
912 |
.packages(Set.of("p")) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
913 |
.build() |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
914 |
.packages(); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
915 |
assertTrue(packages.size() == 1); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
916 |
assertTrue(packages.contains("p")); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
917 |
} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
918 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
919 |
public void testPackagesAndAll() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
920 |
Set<String> packages = ModuleDescriptor.newModule("foo") |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
921 |
.exports("p1") |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
922 |
.opens("p2") |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
923 |
.packages(Set.of("p3")) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
924 |
.provides("q.S", List.of("p4.T")) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
925 |
.mainClass("p5.Main") |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
926 |
.build() |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
927 |
.packages(); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
928 |
assertTrue(Objects.equals(packages, Set.of("p1", "p2", "p3", "p4", "p5"))); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
929 |
} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
930 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
931 |
@Test(dataProvider = "invalidjavaidentifiers", |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
932 |
expectedExceptions = IllegalArgumentException.class ) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
933 |
public void testPackagesWithBadName(String pn, String ignore) { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
934 |
Set<String> pkgs = new HashSet<>(); // allows nulls |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
935 |
pkgs.add(pn); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
936 |
ModuleDescriptor.newModule("foo").packages(pkgs); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
937 |
} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
938 |
|
36511 | 939 |
// name |
940 |
||
941 |
public void testModuleName() { |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
942 |
String mn = ModuleDescriptor.newModule("foo").build().name(); |
36511 | 943 |
assertEquals(mn, "foo"); |
944 |
} |
|
945 |
||
946 |
@Test(dataProvider = "invalidjavaidentifiers", |
|
947 |
expectedExceptions = IllegalArgumentException.class ) |
|
948 |
public void testBadModuleName(String mn, String ignore) { |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
949 |
ModuleDescriptor.newModule(mn); |
36511 | 950 |
} |
951 |
||
952 |
||
953 |
// version |
|
954 |
||
955 |
public void testVersion1() { |
|
956 |
Version v1 = Version.parse("1.0"); |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
957 |
Version v2 = ModuleDescriptor.newModule("foo") |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
958 |
.version(v1) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
959 |
.build() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
960 |
.version() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
961 |
.get(); |
36511 | 962 |
assertEquals(v1, v2); |
963 |
} |
|
964 |
||
965 |
public void testVersion2() { |
|
966 |
String vs = "1.0"; |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
967 |
Version v1 = ModuleDescriptor.newModule("foo") |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
968 |
.version(vs) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
969 |
.build() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
970 |
.version() |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
971 |
.get(); |
36511 | 972 |
Version v2 = Version.parse(vs); |
973 |
assertEquals(v1, v2); |
|
974 |
} |
|
975 |
||
976 |
@Test(expectedExceptions = NullPointerException.class ) |
|
977 |
public void testNullVersion1() { |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
978 |
ModuleDescriptor.newModule("foo").version((Version) null); |
36511 | 979 |
} |
980 |
||
981 |
@Test(expectedExceptions = IllegalArgumentException.class ) |
|
982 |
public void testNullVersion2() { |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
983 |
ModuleDescriptor.newModule("foo").version((String) null); |
36511 | 984 |
} |
985 |
||
986 |
@Test(expectedExceptions = IllegalArgumentException.class ) |
|
987 |
public void testEmptyVersion() { |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
988 |
ModuleDescriptor.newModule("foo").version(""); |
36511 | 989 |
} |
990 |
||
991 |
||
44359
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
992 |
@DataProvider(name = "unparseableVersions") |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
993 |
public Object[][] unparseableVersions() { |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
994 |
return new Object[][]{ |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
995 |
|
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
996 |
{ null, "A1" }, // no version < unparseable |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
997 |
{ "A1", "A2" }, // unparseable < unparseable |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
998 |
{ "A1", "1.0" }, // unparseable < parseable |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
999 |
|
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1000 |
}; |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1001 |
} |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1002 |
|
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1003 |
/** |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1004 |
* Basic test for unparseable module versions |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1005 |
*/ |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1006 |
@Test(dataProvider = "unparseableVersions") |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1007 |
public void testUnparseableModuleVersion(String vs1, String vs2) { |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1008 |
ModuleDescriptor descriptor1 = newModule("m", vs1); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1009 |
ModuleDescriptor descriptor2 = newModule("m", vs2); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1010 |
|
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1011 |
if (vs1 != null && !isParsableVersion(vs1)) { |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1012 |
assertFalse(descriptor1.version().isPresent()); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1013 |
assertTrue(descriptor1.rawVersion().isPresent()); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1014 |
assertEquals(descriptor1.rawVersion().get(), vs1); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1015 |
} |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1016 |
|
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1017 |
if (vs2 != null && !isParsableVersion(vs2)) { |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1018 |
assertFalse(descriptor2.version().isPresent()); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1019 |
assertTrue(descriptor2.rawVersion().isPresent()); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1020 |
assertEquals(descriptor2.rawVersion().get(), vs2); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1021 |
} |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1022 |
|
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1023 |
assertFalse(descriptor1.equals(descriptor2)); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1024 |
assertFalse(descriptor2.equals(descriptor1)); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1025 |
assertTrue(descriptor1.compareTo(descriptor2) == -1); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1026 |
assertTrue(descriptor2.compareTo(descriptor1) == 1); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1027 |
} |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1028 |
|
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1029 |
/** |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1030 |
* Basic test for requiring a module with an unparseable version recorded |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1031 |
* at compile version. |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1032 |
*/ |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1033 |
@Test(dataProvider = "unparseableVersions") |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1034 |
public void testUnparseableCompiledVersion(String vs1, String vs2) { |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1035 |
Requires r1 = newRequires("m", vs1); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1036 |
Requires r2 = newRequires("m", vs2); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1037 |
|
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1038 |
if (vs1 != null && !isParsableVersion(vs1)) { |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1039 |
assertFalse(r1.compiledVersion().isPresent()); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1040 |
assertTrue(r1.rawCompiledVersion().isPresent()); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1041 |
assertEquals(r1.rawCompiledVersion().get(), vs1); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1042 |
} |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1043 |
|
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1044 |
if (vs2 != null && !isParsableVersion(vs2)) { |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1045 |
assertFalse(r2.compiledVersion().isPresent()); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1046 |
assertTrue(r2.rawCompiledVersion().isPresent()); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1047 |
assertEquals(r2.rawCompiledVersion().get(), vs2); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1048 |
} |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1049 |
|
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1050 |
assertFalse(r1.equals(r2)); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1051 |
assertFalse(r2.equals(r1)); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1052 |
assertTrue(r1.compareTo(r2) == -1); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1053 |
assertTrue(r2.compareTo(r1) == 1); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1054 |
} |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1055 |
|
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1056 |
private ModuleDescriptor newModule(String name, String vs) { |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1057 |
JavaLangModuleAccess JLMA = SharedSecrets.getJavaLangModuleAccess(); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1058 |
Builder builder = JLMA.newModuleBuilder(name, false, Set.of()); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1059 |
if (vs != null) |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1060 |
builder.version(vs); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1061 |
builder.requires("java.base"); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1062 |
ByteBuffer bb = ModuleInfoWriter.toByteBuffer(builder.build()); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1063 |
return ModuleDescriptor.read(bb); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1064 |
} |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1065 |
|
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1066 |
private Requires newRequires(String name, String vs) { |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1067 |
JavaLangModuleAccess JLMA = SharedSecrets.getJavaLangModuleAccess(); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1068 |
Builder builder = JLMA.newModuleBuilder("foo", false, Set.of()); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1069 |
if (vs == null) { |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1070 |
builder.requires(name); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1071 |
} else { |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1072 |
JLMA.requires(builder, Set.of(), name, vs); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1073 |
} |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1074 |
Set<ModuleDescriptor.Requires> requires = builder.build().requires(); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1075 |
Iterator<ModuleDescriptor.Requires> iterator = requires.iterator(); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1076 |
ModuleDescriptor.Requires r = iterator.next(); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1077 |
if (r.name().equals("java.base")) { |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1078 |
r = iterator.next(); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1079 |
} |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1080 |
return r; |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1081 |
} |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1082 |
|
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1083 |
private boolean isParsableVersion(String vs) { |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1084 |
try { |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1085 |
Version.parse(vs); |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1086 |
return true; |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1087 |
} catch (IllegalArgumentException e) { |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1088 |
return false; |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1089 |
} |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1090 |
} |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1091 |
|
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1092 |
|
36511 | 1093 |
// toNameAndVersion |
1094 |
||
1095 |
public void testToNameAndVersion() { |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1096 |
ModuleDescriptor md1 = ModuleDescriptor.newModule("foo").build(); |
36511 | 1097 |
assertEquals(md1.toNameAndVersion(), "foo"); |
1098 |
||
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1099 |
ModuleDescriptor md2 = ModuleDescriptor.newModule("foo").version("1.0").build(); |
36511 | 1100 |
assertEquals(md2.toNameAndVersion(), "foo@1.0"); |
1101 |
} |
|
1102 |
||
1103 |
||
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1104 |
// open modules |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1105 |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1106 |
public void testOpenModule() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1107 |
ModuleDescriptor descriptor = ModuleDescriptor.newOpenModule("foo") |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1108 |
.requires("bar") |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1109 |
.exports("p") |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1110 |
.provides("p.Service", List.of("q.ServiceImpl")) |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1111 |
.build(); |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1112 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1113 |
// modifiers |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1114 |
assertTrue(descriptor.modifiers().contains(ModuleDescriptor.Modifier.OPEN)); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1115 |
assertTrue(descriptor.isOpen()); |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1116 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1117 |
// requires |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1118 |
assertTrue(descriptor.requires().size() == 2); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1119 |
Set<String> names = descriptor.requires() |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1120 |
.stream() |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1121 |
.map(Requires::name) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1122 |
.collect(Collectors.toSet()); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1123 |
assertEquals(names, Set.of("bar", "java.base")); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1124 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1125 |
// packages |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1126 |
assertEquals(descriptor.packages(), Set.of("p", "q")); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1127 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1128 |
// exports |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1129 |
assertTrue(descriptor.exports().size() == 1); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1130 |
names = descriptor.exports() |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1131 |
.stream() |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1132 |
.map(Exports::source) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1133 |
.collect(Collectors.toSet()); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1134 |
assertEquals(names, Set.of("p")); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1135 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1136 |
// opens |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1137 |
assertTrue(descriptor.opens().isEmpty()); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1138 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1139 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1140 |
@Test(expectedExceptions = IllegalStateException.class) |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1141 |
public void testOpensOnOpenModule1() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1142 |
ModuleDescriptor.newOpenModule("foo").opens("p"); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1143 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1144 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1145 |
@Test(expectedExceptions = IllegalStateException.class) |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1146 |
public void testOpensOnOpenModule2() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1147 |
ModuleDescriptor.newOpenModule("foo").opens("p", Set.of("bar")); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1148 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1149 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1150 |
public void testIsOpen() { |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1151 |
assertFalse(ModuleDescriptor.newModule("m").build().isOpen()); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1152 |
assertFalse(ModuleDescriptor.newAutomaticModule("m").build().isOpen()); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1153 |
assertTrue(ModuleDescriptor.newOpenModule("m").build().isOpen()); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1154 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1155 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1156 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1157 |
// automatic modules |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1158 |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1159 |
public void testAutomaticModule() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1160 |
ModuleDescriptor descriptor = ModuleDescriptor.newAutomaticModule("foo") |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1161 |
.packages(Set.of("p")) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1162 |
.provides("p.Service", List.of("q.ServiceImpl")) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1163 |
.build(); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1164 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1165 |
// modifiers |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1166 |
assertTrue(descriptor.modifiers().contains(ModuleDescriptor.Modifier.AUTOMATIC)); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1167 |
assertTrue(descriptor.isAutomatic()); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1168 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1169 |
// requires |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1170 |
assertTrue(descriptor.requires().size() == 1); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1171 |
Set<String> names = descriptor.requires() |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1172 |
.stream() |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1173 |
.map(Requires::name) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1174 |
.collect(Collectors.toSet()); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1175 |
assertEquals(names, Set.of("java.base")); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1176 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1177 |
// packages |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1178 |
assertEquals(descriptor.packages(), Set.of("p", "q")); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1179 |
assertTrue(descriptor.exports().isEmpty()); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1180 |
assertTrue(descriptor.opens().isEmpty()); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1181 |
} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1182 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1183 |
@Test(expectedExceptions = IllegalStateException.class) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1184 |
public void testRequiresOnAutomaticModule() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1185 |
ModuleDescriptor.newAutomaticModule("foo").requires("java.base"); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1186 |
} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1187 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1188 |
@Test(expectedExceptions = IllegalStateException.class) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1189 |
public void testExportsOnAutomaticModule1() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1190 |
ModuleDescriptor.newAutomaticModule("foo").exports("p"); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1191 |
} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1192 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1193 |
@Test(expectedExceptions = IllegalStateException.class) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1194 |
public void testExportsOnAutomaticModule2() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1195 |
ModuleDescriptor.newAutomaticModule("foo").exports("p", Set.of("bar")); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1196 |
} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1197 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1198 |
@Test(expectedExceptions = IllegalStateException.class) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1199 |
public void testOpensOnAutomaticModule1() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1200 |
ModuleDescriptor.newAutomaticModule("foo").opens("p"); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1201 |
} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1202 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1203 |
@Test(expectedExceptions = IllegalStateException.class) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1204 |
public void testOpensOnAutomaticModule2() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1205 |
ModuleDescriptor.newAutomaticModule("foo").opens("p", Set.of("bar")); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1206 |
} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1207 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1208 |
@Test(expectedExceptions = IllegalStateException.class) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1209 |
public void testUsesOnAutomaticModule() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1210 |
ModuleDescriptor.newAutomaticModule("foo").uses("p.Service"); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1211 |
} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1212 |
|
36511 | 1213 |
public void testIsAutomatic() { |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1214 |
ModuleDescriptor descriptor1 = ModuleDescriptor.newModule("foo").build(); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1215 |
assertFalse(descriptor1.isAutomatic()); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1216 |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1217 |
ModuleDescriptor descriptor2 = ModuleDescriptor.newOpenModule("foo").build(); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1218 |
assertFalse(descriptor2.isAutomatic()); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1219 |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1220 |
ModuleDescriptor descriptor3 = ModuleDescriptor.newAutomaticModule("foo").build(); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1221 |
assertTrue(descriptor3.isAutomatic()); |
36511 | 1222 |
} |
1223 |
||
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1224 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1225 |
// newModule with modifiers |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1226 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1227 |
public void testNewModuleToBuildAutomaticModule() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1228 |
Set<ModuleDescriptor.Modifier> ms = Set.of(ModuleDescriptor.Modifier.AUTOMATIC); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1229 |
ModuleDescriptor descriptor = ModuleDescriptor.newModule("foo", ms).build(); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1230 |
assertTrue(descriptor.modifiers().equals(ms)); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1231 |
assertTrue(descriptor.isAutomatic()); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1232 |
} |
36511 | 1233 |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1234 |
public void testNewModuleToBuildOpenModule() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1235 |
Set<ModuleDescriptor.Modifier> ms = Set.of(ModuleDescriptor.Modifier.OPEN); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1236 |
ModuleDescriptor descriptor = ModuleDescriptor.newModule("foo", ms).build(); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1237 |
assertTrue(descriptor.modifiers().equals(ms)); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1238 |
assertTrue(descriptor.isOpen()); |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1239 |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1240 |
ms = Set.of(ModuleDescriptor.Modifier.OPEN, ModuleDescriptor.Modifier.SYNTHETIC); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1241 |
descriptor = ModuleDescriptor.newModule("foo", ms).build(); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1242 |
assertTrue(descriptor.modifiers().equals(ms)); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1243 |
assertTrue(descriptor.isOpen()); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1244 |
} |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1245 |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1246 |
@Test(expectedExceptions = IllegalArgumentException.class) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1247 |
public void testNewModuleToBuildAutomaticAndOpenModule() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1248 |
Set<ModuleDescriptor.Modifier> ms = Set.of(ModuleDescriptor.Modifier.AUTOMATIC, |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1249 |
ModuleDescriptor.Modifier.OPEN); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1250 |
ModuleDescriptor.newModule("foo", ms); |
36511 | 1251 |
} |
1252 |
||
1253 |
||
1254 |
// mainClass |
|
1255 |
||
1256 |
public void testMainClass() { |
|
1257 |
String mainClass |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1258 |
= ModuleDescriptor.newModule("foo").mainClass("p.Main").build().mainClass().get(); |
36511 | 1259 |
assertEquals(mainClass, "p.Main"); |
1260 |
} |
|
1261 |
||
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1262 |
@Test(expectedExceptions = IllegalArgumentException.class) |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1263 |
public void testMainClassWithSimpleIdentifier() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1264 |
ModuleDescriptor.newModule("foo").mainClass("Main"); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1265 |
} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1266 |
|
36511 | 1267 |
@Test(dataProvider = "invalidjavaidentifiers", |
1268 |
expectedExceptions = IllegalArgumentException.class ) |
|
1269 |
public void testMainClassWithBadName(String mainClass, String ignore) { |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1270 |
Builder builder = ModuleDescriptor.newModule("foo"); |
36511 | 1271 |
builder.mainClass(mainClass); |
1272 |
} |
|
1273 |
||
1274 |
||
1275 |
// reads |
|
1276 |
||
1277 |
private static InputStream EMPTY_INPUT_STREAM = new InputStream() { |
|
1278 |
@Override |
|
1279 |
public int read() { |
|
1280 |
return -1; |
|
1281 |
} |
|
1282 |
}; |
|
1283 |
||
1284 |
private static InputStream FAILING_INPUT_STREAM = new InputStream() { |
|
1285 |
@Override |
|
1286 |
public int read() throws IOException { |
|
1287 |
throw new IOException(); |
|
1288 |
} |
|
1289 |
}; |
|
1290 |
||
44359
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1291 |
/** |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1292 |
* Basic test reading module-info.class |
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1293 |
*/ |
42703
20c39ea4a507
8170987: Module system implementation refresh (12/2016)
alanb
parents:
42338
diff
changeset
|
1294 |
public void testRead() throws Exception { |
36511 | 1295 |
Module base = Object.class.getModule(); |
1296 |
||
1297 |
try (InputStream in = base.getResourceAsStream("module-info.class")) { |
|
1298 |
ModuleDescriptor descriptor = ModuleDescriptor.read(in); |
|
1299 |
assertTrue(in.read() == -1); // all bytes read |
|
1300 |
assertEquals(descriptor.name(), "java.base"); |
|
1301 |
} |
|
1302 |
||
1303 |
try (InputStream in = base.getResourceAsStream("module-info.class")) { |
|
1304 |
ByteBuffer bb = ByteBuffer.wrap(in.readAllBytes()); |
|
1305 |
ModuleDescriptor descriptor = ModuleDescriptor.read(bb); |
|
1306 |
assertFalse(bb.hasRemaining()); // no more remaining bytes |
|
1307 |
assertEquals(descriptor.name(), "java.base"); |
|
1308 |
} |
|
1309 |
} |
|
44359
c6761862ca0b
8174823: Module system implementation refresh (3/2017)
alanb
parents:
43712
diff
changeset
|
1310 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1311 |
/** |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1312 |
* Test ModuleDescriptor with a packager finder |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1313 |
*/ |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1314 |
public void testReadsWithPackageFinder() throws Exception { |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1315 |
ModuleDescriptor descriptor = ModuleDescriptor.newModule("foo") |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1316 |
.requires("java.base") |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1317 |
.build(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1318 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1319 |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1320 |
ModuleInfoWriter.write(descriptor, baos); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1321 |
ByteBuffer bb = ByteBuffer.wrap(baos.toByteArray()); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1322 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1323 |
descriptor = ModuleDescriptor.read(bb, () -> Set.of("p", "q")); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1324 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1325 |
assertTrue(descriptor.packages().size() == 2); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1326 |
assertTrue(descriptor.packages().contains("p")); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1327 |
assertTrue(descriptor.packages().contains("q")); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1328 |
} |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1329 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1330 |
/** |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1331 |
* Test ModuleDescriptor with a packager finder that doesn't return the |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1332 |
* complete set of packages. |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1333 |
*/ |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1334 |
@Test(expectedExceptions = InvalidModuleDescriptorException.class) |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1335 |
public void testReadsWithBadPackageFinder() throws Exception { |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1336 |
ModuleDescriptor descriptor = ModuleDescriptor.newModule("foo") |
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1337 |
.requires("java.base") |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1338 |
.exports("p") |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1339 |
.build(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1340 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1341 |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1342 |
ModuleInfoWriter.write(descriptor, baos); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1343 |
ByteBuffer bb = ByteBuffer.wrap(baos.toByteArray()); |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1344 |
|
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1345 |
// package finder returns a set that doesn't include p |
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39064
diff
changeset
|
1346 |
ModuleDescriptor.read(bb, () -> Set.of("q")); |
36511 | 1347 |
} |
1348 |
||
1349 |
@Test(expectedExceptions = InvalidModuleDescriptorException.class) |
|
1350 |
public void testReadFromEmptyInputStream() throws Exception { |
|
1351 |
ModuleDescriptor.read(EMPTY_INPUT_STREAM); |
|
1352 |
} |
|
1353 |
||
1354 |
@Test(expectedExceptions = IOException.class) |
|
1355 |
public void testReadFromFailingInputStream() throws Exception { |
|
1356 |
ModuleDescriptor.read(FAILING_INPUT_STREAM); |
|
1357 |
} |
|
1358 |
||
1359 |
@Test(expectedExceptions = InvalidModuleDescriptorException.class) |
|
1360 |
public void testReadFromEmptyBuffer() { |
|
1361 |
ByteBuffer bb = ByteBuffer.allocate(0); |
|
1362 |
ModuleDescriptor.read(bb); |
|
1363 |
} |
|
1364 |
||
39050
9de41b79ec7e
8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents:
36511
diff
changeset
|
1365 |
// The requires table for java.base must be 0 length |
9de41b79ec7e
8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents:
36511
diff
changeset
|
1366 |
@Test(expectedExceptions = InvalidModuleDescriptorException.class) |
9de41b79ec7e
8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents:
36511
diff
changeset
|
1367 |
public void testReadOfJavaBaseWithRequires() { |
9de41b79ec7e
8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents:
36511
diff
changeset
|
1368 |
ModuleDescriptor descriptor |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1369 |
= ModuleDescriptor.newModule("java.base") |
39050
9de41b79ec7e
8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents:
36511
diff
changeset
|
1370 |
.requires("other") |
9de41b79ec7e
8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents:
36511
diff
changeset
|
1371 |
.build(); |
9de41b79ec7e
8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents:
36511
diff
changeset
|
1372 |
ByteBuffer bb = ModuleInfoWriter.toByteBuffer(descriptor); |
9de41b79ec7e
8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents:
36511
diff
changeset
|
1373 |
ModuleDescriptor.read(bb); |
9de41b79ec7e
8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents:
36511
diff
changeset
|
1374 |
} |
9de41b79ec7e
8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents:
36511
diff
changeset
|
1375 |
|
9de41b79ec7e
8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents:
36511
diff
changeset
|
1376 |
// The requires table must have an entry for java.base |
9de41b79ec7e
8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents:
36511
diff
changeset
|
1377 |
@Test(expectedExceptions = InvalidModuleDescriptorException.class) |
9de41b79ec7e
8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents:
36511
diff
changeset
|
1378 |
public void testReadWithEmptyRequires() { |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1379 |
ModuleDescriptor descriptor = SharedSecrets.getJavaLangModuleAccess() |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1380 |
.newModuleBuilder("m1", false, Set.of()).build(); |
39050
9de41b79ec7e
8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents:
36511
diff
changeset
|
1381 |
ByteBuffer bb = ModuleInfoWriter.toByteBuffer(descriptor); |
9de41b79ec7e
8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents:
36511
diff
changeset
|
1382 |
ModuleDescriptor.read(bb); |
9de41b79ec7e
8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents:
36511
diff
changeset
|
1383 |
} |
9de41b79ec7e
8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents:
36511
diff
changeset
|
1384 |
|
9de41b79ec7e
8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents:
36511
diff
changeset
|
1385 |
// The requires table must have an entry for java.base |
9de41b79ec7e
8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents:
36511
diff
changeset
|
1386 |
@Test(expectedExceptions = InvalidModuleDescriptorException.class) |
9de41b79ec7e
8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents:
36511
diff
changeset
|
1387 |
public void testReadWithNoRequiresBase() { |
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1388 |
ModuleDescriptor descriptor = SharedSecrets.getJavaLangModuleAccess() |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1389 |
.newModuleBuilder("m1", false, Set.of()).requires("m2").build(); |
39050
9de41b79ec7e
8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents:
36511
diff
changeset
|
1390 |
ByteBuffer bb = ModuleInfoWriter.toByteBuffer(descriptor); |
9de41b79ec7e
8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents:
36511
diff
changeset
|
1391 |
ModuleDescriptor.read(bb); |
9de41b79ec7e
8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents:
36511
diff
changeset
|
1392 |
} |
9de41b79ec7e
8158456: ModuleDescriptor.read does not verify dependence on java.base in module-info.class
alanb
parents:
36511
diff
changeset
|
1393 |
|
36511 | 1394 |
public void testReadWithNull() throws Exception { |
1395 |
Module base = Object.class.getModule(); |
|
1396 |
||
1397 |
try { |
|
1398 |
ModuleDescriptor.read((InputStream)null); |
|
1399 |
assertTrue(false); |
|
1400 |
} catch (NullPointerException expected) { } |
|
1401 |
||
1402 |
||
1403 |
try (InputStream in = base.getResourceAsStream("module-info.class")) { |
|
1404 |
try { |
|
1405 |
ModuleDescriptor.read(in, null); |
|
1406 |
assertTrue(false); |
|
1407 |
} catch (NullPointerException expected) { } |
|
1408 |
} |
|
1409 |
||
1410 |
try { |
|
1411 |
ModuleDescriptor.read((ByteBuffer)null); |
|
1412 |
assertTrue(false); |
|
1413 |
} catch (NullPointerException expected) { } |
|
1414 |
||
1415 |
||
1416 |
try (InputStream in = base.getResourceAsStream("module-info.class")) { |
|
1417 |
ByteBuffer bb = ByteBuffer.wrap(in.readAllBytes()); |
|
1418 |
try { |
|
1419 |
ModuleDescriptor.read(bb, null); |
|
1420 |
assertTrue(false); |
|
1421 |
} catch (NullPointerException expected) { } |
|
1422 |
} |
|
1423 |
} |
|
1424 |
||
1425 |
||
1426 |
// equals/hashCode/compareTo/toString |
|
1427 |
||
1428 |
public void testEqualsAndHashCode() { |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1429 |
ModuleDescriptor md1 = ModuleDescriptor.newModule("m").build(); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1430 |
ModuleDescriptor md2 = ModuleDescriptor.newModule("m").build(); |
36511 | 1431 |
assertEquals(md1, md1); |
1432 |
assertEquals(md1.hashCode(), md2.hashCode()); |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1433 |
assertTrue(md1.compareTo(md2) == 0); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1434 |
assertTrue(md2.compareTo(md1) == 0); |
36511 | 1435 |
} |
1436 |
||
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1437 |
@DataProvider(name = "sortedModuleDescriptors") |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1438 |
public Object[][] sortedModuleDescriptors() { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1439 |
return new Object[][]{ |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1440 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1441 |
{ ModuleDescriptor.newModule("m2").build(), |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1442 |
ModuleDescriptor.newModule("m1").build() |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1443 |
}, |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1444 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1445 |
{ ModuleDescriptor.newModule("m").version("2").build(), |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1446 |
ModuleDescriptor.newModule("m").version("1").build() |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1447 |
}, |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1448 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1449 |
{ ModuleDescriptor.newModule("m").version("1").build(), |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1450 |
ModuleDescriptor.newModule("m").build() |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1451 |
}, |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1452 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1453 |
{ ModuleDescriptor.newOpenModule("m").build(), |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1454 |
ModuleDescriptor.newModule("m").build() |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1455 |
}, |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1456 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1457 |
}; |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1458 |
} |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1459 |
|
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1460 |
@Test(dataProvider = "sortedModuleDescriptors") |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1461 |
public void testCompare(ModuleDescriptor md1, ModuleDescriptor md2) { |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1462 |
assertNotEquals(md1, md2); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1463 |
assertTrue(md1.compareTo(md2) == 1); |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1464 |
assertTrue(md2.compareTo(md1) == -1); |
36511 | 1465 |
} |
1466 |
||
1467 |
public void testToString() { |
|
43712
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1468 |
String s = ModuleDescriptor.newModule("m1") |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1469 |
.requires("m2") |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1470 |
.exports("p1") |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1471 |
.build() |
5dfd0950317c
8173393: Module system implementation refresh (2/2017)
alanb
parents:
42703
diff
changeset
|
1472 |
.toString(); |
36511 | 1473 |
assertTrue(s.contains("m1")); |
1474 |
assertTrue(s.contains("m2")); |
|
1475 |
assertTrue(s.contains("p1")); |
|
1476 |
} |
|
1477 |
||
1478 |
} |