1 /* |
1 /* |
2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
26 * @bug 8159855 |
26 * @bug 8159855 |
27 * @summary test ToolProvider SPI |
27 * @summary test ToolProvider SPI |
28 * @run main/othervm ToolProviderTest |
28 * @run main/othervm ToolProviderTest |
29 */ |
29 */ |
30 |
30 |
31 import java.io.File; |
|
32 import java.io.IOException; |
31 import java.io.IOException; |
33 import java.io.PrintWriter; |
32 import java.io.PrintWriter; |
34 import java.nio.file.Files; |
33 import java.nio.file.Files; |
35 import java.nio.file.Path; |
34 import java.nio.file.Path; |
36 import java.nio.file.Paths; |
35 import java.nio.file.Paths; |
58 private void test() throws Exception { |
61 private void test() throws Exception { |
59 ToolProvider testProvider = ToolProvider.findFirst("test").get(); |
62 ToolProvider testProvider = ToolProvider.findFirst("test").get(); |
60 int rc = testProvider.run(System.out, System.err, "hello test"); |
63 int rc = testProvider.run(System.out, System.err, "hello test"); |
61 if (rc != 0) { |
64 if (rc != 0) { |
62 throw new Exception("unexpected exit code: " + rc); |
65 throw new Exception("unexpected exit code: " + rc); |
|
66 } |
|
67 } |
|
68 |
|
69 private void testNullArgs() { |
|
70 ToolProvider testProvider = ToolProvider.findFirst("test").get(); |
|
71 |
|
72 // out null check |
|
73 expectNullPointerException(() -> testProvider.run(null, System.err)); |
|
74 |
|
75 // err null check |
|
76 expectNullPointerException(() -> testProvider.run(System.out, null)); |
|
77 |
|
78 // args array null check |
|
79 expectNullPointerException(() -> |
|
80 testProvider.run(System.out, System.err, (String[]) null)); |
|
81 |
|
82 // args array elements null check |
|
83 expectNullPointerException(() -> |
|
84 testProvider.run(System.out, System.err, (String) null)); |
|
85 } |
|
86 |
|
87 private static void expectNullPointerException(Runnable test) { |
|
88 try { |
|
89 test.run(); |
|
90 throw new Error("NullPointerException not thrown"); |
|
91 } catch (NullPointerException e) { |
|
92 // expected |
63 } |
93 } |
64 } |
94 } |
65 |
95 |
66 private void initServices() throws IOException { |
96 private void initServices() throws IOException { |
67 Path testClasses = Paths.get(System.getProperty("test.classes")); |
97 Path testClasses = Paths.get(System.getProperty("test.classes")); |