author | alanb |
Thu, 01 Dec 2016 08:57:53 +0000 | |
changeset 42338 | a60f280f803c |
parent 39124 | 2f46f5082cd7 |
child 42703 | 20c39ea4a507 |
permissions | -rw-r--r-- |
36511 | 1 |
/* |
39124
2f46f5082cd7
8159879: Some typo and minor test bugs in ava/lang/module/ModuleReferenceTest.java and ConfigurationTest.java
mli
parents:
36511
diff
changeset
|
2 |
* Copyright (c) 2014, 2016, 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 |
|
26 |
* @run testng ModuleReferenceTest |
|
27 |
* @summary Basic tests for java.lang.module.ModuleReference |
|
28 |
*/ |
|
29 |
||
30 |
import java.lang.module.ModuleDescriptor; |
|
31 |
import java.lang.module.ModuleReader; |
|
32 |
import java.lang.module.ModuleReference; |
|
33 |
import java.net.URI; |
|
34 |
import java.util.function.Supplier; |
|
35 |
||
36 |
import org.testng.annotations.Test; |
|
37 |
import static org.testng.Assert.*; |
|
38 |
||
39 |
@Test |
|
40 |
public class ModuleReferenceTest { |
|
41 |
||
42 |
private Supplier<ModuleReader> makeSupplier() { |
|
43 |
return () -> { throw new UnsupportedOperationException(); }; |
|
44 |
} |
|
45 |
||
46 |
public void testBasic() throws Exception { |
|
47 |
ModuleDescriptor descriptor |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39124
diff
changeset
|
48 |
= ModuleDescriptor.module("m") |
36511 | 49 |
.exports("p") |
50 |
.exports("q") |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39124
diff
changeset
|
51 |
.contains("p.internal") |
36511 | 52 |
.build(); |
53 |
||
54 |
URI uri = URI.create("module:/m"); |
|
55 |
||
56 |
Supplier<ModuleReader> supplier = makeSupplier(); |
|
57 |
||
58 |
ModuleReference mref = new ModuleReference(descriptor, uri, supplier); |
|
59 |
||
60 |
assertTrue(mref.descriptor().equals(descriptor)); |
|
61 |
assertTrue(mref.location().get().equals(uri)); |
|
62 |
||
63 |
// check that the supplier is called |
|
64 |
try { |
|
65 |
mref.open(); |
|
66 |
assertTrue(false); |
|
67 |
} catch (UnsupportedOperationException expected) { } |
|
68 |
} |
|
69 |
||
70 |
||
71 |
@Test(expectedExceptions = { NullPointerException.class }) |
|
72 |
public void testNullDescriptor() throws Exception { |
|
73 |
URI location = URI.create("module:/m"); |
|
74 |
new ModuleReference(null, location, makeSupplier()); |
|
75 |
} |
|
76 |
||
77 |
public void testNullLocation() { |
|
78 |
ModuleDescriptor descriptor |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39124
diff
changeset
|
79 |
= ModuleDescriptor.module("m") |
36511 | 80 |
.exports("p") |
81 |
.build(); |
|
82 |
Supplier<ModuleReader> supplier = makeSupplier(); |
|
83 |
ModuleReference mref = new ModuleReference(descriptor, null, supplier); |
|
84 |
assertTrue(!mref.location().isPresent()); |
|
85 |
} |
|
86 |
||
87 |
@Test(expectedExceptions = { NullPointerException.class }) |
|
88 |
public void testNullSupplier() throws Exception { |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39124
diff
changeset
|
89 |
ModuleDescriptor descriptor = ModuleDescriptor.module("m").build(); |
36511 | 90 |
URI location = URI.create("module:/m"); |
91 |
new ModuleReference(descriptor, location, null); |
|
92 |
} |
|
93 |
||
94 |
||
95 |
public void testEqualsAndHashCode() { |
|
96 |
ModuleDescriptor descriptor1 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39124
diff
changeset
|
97 |
= ModuleDescriptor.module("m1") |
36511 | 98 |
.exports("p") |
99 |
.build(); |
|
100 |
ModuleDescriptor descriptor2 |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39124
diff
changeset
|
101 |
= ModuleDescriptor.module("m1") |
36511 | 102 |
.exports("p") |
103 |
.build(); |
|
104 |
||
105 |
URI uri = URI.create("module:/m1"); |
|
106 |
Supplier<ModuleReader> supplier = makeSupplier(); |
|
107 |
||
108 |
ModuleReference mref1 = new ModuleReference(descriptor1, uri, supplier); |
|
109 |
ModuleReference mref2 = new ModuleReference(descriptor2, uri, supplier); |
|
110 |
ModuleReference mref3 = new ModuleReference(descriptor1, null, supplier); |
|
111 |
||
112 |
assertTrue(mref1.equals(mref1)); |
|
39124
2f46f5082cd7
8159879: Some typo and minor test bugs in ava/lang/module/ModuleReferenceTest.java and ConfigurationTest.java
mli
parents:
36511
diff
changeset
|
113 |
assertTrue(mref1.equals(mref2)); |
36511 | 114 |
assertTrue(mref2.equals(mref1)); |
115 |
assertTrue(mref1.hashCode() == mref2.hashCode()); |
|
116 |
||
117 |
assertTrue(mref3.equals(mref3)); |
|
118 |
assertFalse(mref3.equals(mref1)); |
|
119 |
assertFalse(mref1.equals(mref3)); |
|
120 |
} |
|
121 |
||
122 |
||
123 |
public void testToString() { |
|
42338
a60f280f803c
8169069: Module system implementation refresh (11/2016)
alanb
parents:
39124
diff
changeset
|
124 |
ModuleDescriptor descriptor = ModuleDescriptor.module("m1").build(); |
36511 | 125 |
URI uri = URI.create("module:/m1"); |
126 |
Supplier<ModuleReader> supplier = makeSupplier(); |
|
127 |
ModuleReference mref = new ModuleReference(descriptor, uri, supplier); |
|
128 |
String s = mref.toString(); |
|
129 |
assertTrue(s.contains("m1")); |
|
130 |
assertTrue(s.contains(uri.toString())); |
|
131 |
} |
|
132 |
||
133 |
} |