|
16 | 16 |
|
17 | 17 | package com.google.common.io;
|
18 | 18 |
|
| 19 | +import static com.google.common.collect.Iterables.getOnlyElement; |
19 | 20 | import static com.google.common.truth.Truth.assertThat;
|
| 21 | +import static java.lang.Integer.parseInt; |
20 | 22 |
|
21 | 23 | import com.google.common.base.MoreObjects;
|
22 | 24 | import com.google.common.base.Objects;
|
23 | 25 | import com.google.common.base.Splitter;
|
24 | 26 | import com.google.common.base.Throwables;
|
25 | 27 | import com.google.common.collect.ImmutableList;
|
26 | 28 | import com.google.common.collect.ImmutableSet;
|
27 |
| -import com.google.common.collect.Iterables; |
28 | 29 | import com.google.common.collect.Lists;
|
29 | 30 | import com.google.common.testing.TestLogHandler;
|
30 | 31 | import java.io.Closeable;
|
@@ -52,16 +53,29 @@ protected void setUp() throws Exception {
|
52 | 53 | @AndroidIncompatible // TODO(cpovirk): Look up Build.VERSION.SDK_INT reflectively.
|
53 | 54 | public void testCreate() {
|
54 | 55 | Closer closer = Closer.create();
|
55 |
| - String javaVersion = System.getProperty("java.version"); |
56 |
| - String secondPart = Iterables.get(Splitter.on('.').split(javaVersion), 1); |
57 |
| - int versionNumber = Integer.parseInt(secondPart); |
| 56 | + int versionNumber = parseInt(javaVersion()); |
58 | 57 | if (versionNumber < 7) {
|
59 | 58 | assertThat(closer.suppressor).isInstanceOf(Closer.LoggingSuppressor.class);
|
60 | 59 | } else {
|
61 | 60 | assertThat(closer.suppressor).isInstanceOf(Closer.SuppressingSuppressor.class);
|
62 | 61 | }
|
63 | 62 | }
|
64 | 63 |
|
| 64 | + @AndroidIncompatible // TODO(cpovirk): Look up Build.VERSION.SDK_INT reflectively. |
| 65 | + private static String javaVersion() { |
| 66 | + String javaVersion = System.getProperty("java.version"); |
| 67 | + List<String> parts = Splitter.on('.').splitToList(javaVersion); |
| 68 | + // Format varies by version: http://openjdk.java.net/jeps/223 |
| 69 | + if (parts.size() == 1) { |
| 70 | + // Java 9 style: majorversion-foo |
| 71 | + String major = getOnlyElement(parts); |
| 72 | + return major.replaceFirst("-.*", ""); |
| 73 | + } else { |
| 74 | + // pre-Java 8 style: 1.majorversion |
| 75 | + return parts.get(1); |
| 76 | + } |
| 77 | + } |
| 78 | + |
65 | 79 | public void testNoExceptionsThrown() throws IOException {
|
66 | 80 | Closer closer = new Closer(suppressor);
|
67 | 81 |
|
|
0 commit comments