Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/security/Provider/ChangeProviders.java
41149 views
1
/*
2
* Copyright (c) 2003, 2016, 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
* @bug 4856968 7054918 8130181
27
* @library ../testlibrary
28
* @summary make sure add/insert/removeProvider() work correctly
29
* @author Andreas Sterbenz
30
*/
31
32
import java.util.*;
33
34
import java.security.*;
35
36
public class ChangeProviders extends Provider {
37
38
private ChangeProviders() {
39
super("Foo", "47.23", "none");
40
}
41
42
private static int plen() {
43
return Security.getProviders().length;
44
}
45
46
public static void main(String[] args) throws Exception {
47
ProvidersSnapshot snapshot = ProvidersSnapshot.create();
48
try {
49
main0(args);
50
} finally {
51
snapshot.restore();
52
}
53
}
54
55
public static void main0(String[] args) throws Exception {
56
long start = System.currentTimeMillis();
57
Provider p = new ChangeProviders();
58
59
int n = plen();
60
Security.addProvider(p);
61
if (plen() != n + 1) {
62
throw new Exception("Provider not added");
63
}
64
Security.addProvider(p);
65
if (plen() != n + 1) {
66
throw new Exception("Provider readded");
67
}
68
Security.insertProviderAt(p, 1);
69
if (plen() != n + 1) {
70
throw new Exception("Provider readded");
71
}
72
Security.removeProvider(p.getName());
73
if ((plen() != n) || (Security.getProvider(p.getName()) != null)) {
74
throw new Exception("Provider not removed");
75
}
76
Security.insertProviderAt(p, 1);
77
if (plen() != n + 1) {
78
throw new Exception("Provider not added");
79
}
80
if (Security.getProviders()[0] != p) {
81
throw new Exception("Provider not at pos 1");
82
}
83
84
System.out.println("All tests passed.");
85
}
86
87
}
88
89