Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/util/ServiceLoader/ReloadTest.java
41149 views
1
/*
2
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
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
* @modules java.scripting
27
* @library modules classpath/pearscript
28
* @build ReloadTest org.pear.PearScript org.pear.PearScriptEngineFactory bananascript/*
29
* @run testng/othervm ReloadTest
30
* @summary Basic test of ServiceLoader.reload
31
*/
32
33
import java.util.ConcurrentModificationException;
34
import java.util.Iterator;
35
import java.util.List;
36
import java.util.ServiceLoader;
37
import java.util.ServiceLoader.Provider;
38
import java.util.Spliterator;
39
import java.util.stream.Collectors;
40
import java.util.stream.Stream;
41
import static java.util.ServiceLoader.*;
42
import javax.script.ScriptEngineFactory;
43
import org.testng.annotations.Test;
44
import static org.testng.Assert.*;
45
46
@Test
47
public class ReloadTest {
48
49
public void testReload() {
50
ServiceLoader<ScriptEngineFactory> sl = load(ScriptEngineFactory.class);
51
List<String> names1 = sl.stream()
52
.map(Provider::get)
53
.map(ScriptEngineFactory::getEngineName)
54
.collect(Collectors.toList());
55
assertFalse(names1.isEmpty());
56
sl.reload();
57
List<String> names2 = sl.stream()
58
.map(Provider::get)
59
.map(ScriptEngineFactory::getEngineName)
60
.collect(Collectors.toList());
61
assertEquals(names1, names2);
62
}
63
64
@Test(expectedExceptions = { ConcurrentModificationException.class })
65
public void testIteratorHasNext() {
66
ServiceLoader<ScriptEngineFactory> sl = load(ScriptEngineFactory.class);
67
Iterator<ScriptEngineFactory> iterator = sl.iterator();
68
sl.reload();
69
iterator.hasNext();
70
}
71
72
@Test(expectedExceptions = { ConcurrentModificationException.class })
73
public void testIteratorNext() {
74
ServiceLoader<ScriptEngineFactory> sl = load(ScriptEngineFactory.class);
75
Iterator<ScriptEngineFactory> iterator = sl.iterator();
76
assertTrue(iterator.hasNext());
77
sl.reload();
78
iterator.next();
79
}
80
81
@Test(expectedExceptions = { ConcurrentModificationException.class })
82
public void testStreamFindAny() {
83
ServiceLoader<ScriptEngineFactory> sl = load(ScriptEngineFactory.class);
84
Stream<Provider<ScriptEngineFactory>> stream = sl.stream();
85
sl.reload();
86
stream.findAny();
87
}
88
89
@Test(expectedExceptions = { ConcurrentModificationException.class })
90
public void testSpliteratorTryAdvance() {
91
ServiceLoader<ScriptEngineFactory> sl = load(ScriptEngineFactory.class);
92
Stream<Provider<ScriptEngineFactory>> stream = sl.stream();
93
Spliterator<Provider<ScriptEngineFactory>> spliterator = stream.spliterator();
94
sl.reload();
95
spliterator.tryAdvance(System.out::println);
96
}
97
98
}
99
100