Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/sun/security/ssl/SSLLogger/LoggerDateFormatterTest.java
41152 views
1
/*
2
* Copyright (c) 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
* @bug 8245306
27
* @summary Replace ThreadLocal date format with DateTimeFormatter
28
* @modules java.base/sun.security.ssl:+open
29
* @compile LoggerDateFormatterTest.java
30
* @run testng/othervm -Djavax.net.debug=all LoggerDateFormatterTest
31
*/
32
33
import org.testng.annotations.BeforeTest;
34
import org.testng.annotations.Test;
35
import sun.security.ssl.SSLLogger;
36
import java.io.ByteArrayOutputStream;
37
import java.io.IOException;
38
import java.io.OutputStream;
39
import java.io.PrintStream;
40
import java.util.regex.Matcher;
41
import java.util.regex.Pattern;
42
43
import static java.lang.System.out;
44
import static org.testng.Assert.fail;
45
46
public class LoggerDateFormatterTest {
47
48
SSLPrintStream sslStream;
49
static String year = "(\\|\\d\\d\\d\\d-\\d\\d-\\d\\d";
50
static String hour = "\\s\\d\\d:\\d\\d:\\d\\d\\.\\d\\d\\d\\s";
51
static String zone = "([A-Za-z]+([\\+\\-][0-2]?[0-9](\\:[0-5]?[0-9]))?))";
52
static Pattern pattern;
53
Matcher matcher;
54
55
@BeforeTest
56
public void setUp() {
57
sslStream = new SSLPrintStream(System.err);
58
System.setErr(sslStream);
59
String format = year + hour + zone;
60
pattern = Pattern.compile(format);
61
}
62
63
@Test
64
public void testDateFormat() {
65
SSLLogger.info("logging");
66
System.out.println("The value is: " + sslStream.bos.toString());
67
matcher = pattern.matcher(sslStream.bos.toString());
68
if (matcher.find()) {
69
out.println("Test Passed with value :" + matcher.group());
70
}
71
else {
72
fail("Test failed wrong SSL DateFormat");
73
}
74
}
75
76
public static class SSLPrintStream extends PrintStream {
77
78
public ByteArrayOutputStream bos; // Stream that accumulates System.err
79
80
public SSLPrintStream(OutputStream out) {
81
super(out);
82
bos = new ByteArrayOutputStream();
83
}
84
85
@Override
86
public void write(int b) {
87
super.write(b);
88
bos.write(b);
89
}
90
91
@Override
92
public void write(byte[] buf, int off, int len) {
93
super.write(buf, off, len);
94
bos.write(buf, off, len);
95
}
96
97
@Override
98
public void write(byte[] buf) throws IOException {
99
super.write(buf);
100
bos.write(buf);
101
}
102
103
@Override
104
public void writeBytes(byte[] buf) {
105
super.writeBytes(buf);
106
bos.writeBytes(buf);
107
}
108
}
109
110
}
111
112