Skip to content

Commit c0f9a7a

Browse files
authored
Merge pull request #73 from tunnelvisionlabs/fix-warnings
Fix build warnings related to obsolete APIs
2 parents 71b8806 + 98fb770 commit c0f9a7a

File tree

6 files changed

+93
-58
lines changed

6 files changed

+93
-58
lines changed

antlr4-maven-plugin/src/test/java/org/antlr/mojo/antlr4/Antlr4MojoTest.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,20 @@
1616
import org.codehaus.plexus.util.xml.Xpp3Dom;
1717
import org.junit.Rule;
1818
import org.junit.Test;
19-
import org.junit.rules.ExpectedException;
19+
import org.junit.function.ThrowingRunnable;
2020

2121
import java.io.Closeable;
2222
import java.io.File;
2323
import java.io.IOException;
2424
import java.util.Arrays;
2525

26+
import static org.junit.Assert.assertEquals;
2627
import static org.junit.Assert.assertFalse;
28+
import static org.junit.Assert.assertThrows;
2729
import static org.junit.Assert.assertTrue;
2830
import static org.junit.Assume.assumeTrue;
2931

3032
public class Antlr4MojoTest {
31-
@Rule
32-
public ExpectedException thrown = ExpectedException.none();
33-
3433
@Rule
3534
public final TestResources resources = new TestResources();
3635

@@ -347,9 +346,9 @@ public void processWhenDependencyRemoved() throws Exception {
347346

348347
File baseGrammar = new File(antlrDir, "imports/HelloBase.g4");
349348

350-
MavenProject project = maven.readMavenProject(baseDir);
351-
MavenSession session = maven.newMavenSession(project);
352-
MojoExecution exec = maven.newMojoExecution("antlr4");
349+
final MavenProject project = maven.readMavenProject(baseDir);
350+
final MavenSession session = maven.newMavenSession(project);
351+
final MojoExecution exec = maven.newMojoExecution("antlr4");
353352

354353
maven.executeMojo(session, project, exec);
355354

@@ -358,10 +357,14 @@ public void processWhenDependencyRemoved() throws Exception {
358357
// if the base grammar no longer exists, processing must be performed
359358
assertTrue(baseGrammar.delete());
360359

361-
thrown.expect(MojoExecutionException.class);
362-
thrown.expectMessage("ANTLR 4 caught 1 build errors.");
360+
Throwable t = assertThrows(MojoExecutionException.class, new ThrowingRunnable() {
361+
@Override
362+
public void run() throws Throwable {
363+
maven.executeMojo(session, project, exec);
364+
}
365+
});
363366

364-
maven.executeMojo(session, project, exec);
367+
assertEquals("ANTLR 4 caught 1 build errors.", t.getMessage());
365368
} finally {
366369
temp.close();
367370
}

runtime/Java/test/org/antlr/v4/runtime/TestCodePointCharStream.java

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,14 @@
66
package org.antlr.v4.runtime;
77

88
import org.antlr.v4.runtime.misc.Interval;
9-
import org.junit.Rule;
109
import org.junit.Test;
11-
import org.junit.rules.ExpectedException;
10+
import org.junit.function.ThrowingRunnable;
1211

1312
import static org.junit.Assert.assertEquals;
13+
import static org.junit.Assert.assertThrows;
1414
import static org.junit.Assert.assertTrue;
1515

1616
public class TestCodePointCharStream {
17-
@Rule
18-
public ExpectedException thrown = ExpectedException.none();
19-
2017
@Test
2118
public void emptyBytesHasSize0() {
2219
CodePointCharStream s = CharStreams.fromString("");
@@ -34,10 +31,15 @@ public void emptyBytesLookAheadReturnsEOF() {
3431

3532
@Test
3633
public void consumingEmptyStreamShouldThrow() {
37-
CodePointCharStream s = CharStreams.fromString("");
38-
thrown.expect(IllegalStateException.class);
39-
thrown.expectMessage("cannot consume EOF");
40-
s.consume();
34+
final CodePointCharStream s = CharStreams.fromString("");
35+
Throwable t = assertThrows(IllegalStateException.class, new ThrowingRunnable() {
36+
@Override
37+
public void run() throws Throwable {
38+
s.consume();
39+
}
40+
});
41+
42+
assertEquals("cannot consume EOF", t.getMessage());
4143
}
4244

4345
@Test
@@ -56,11 +58,17 @@ public void consumingSingleLatinCodePointShouldMoveIndex() {
5658

5759
@Test
5860
public void consumingPastSingleLatinCodePointShouldThrow() {
59-
CodePointCharStream s = CharStreams.fromString("X");
60-
s.consume();
61-
thrown.expect(IllegalStateException.class);
62-
thrown.expectMessage("cannot consume EOF");
61+
final CodePointCharStream s = CharStreams.fromString("X");
6362
s.consume();
63+
64+
Throwable t = assertThrows(IllegalStateException.class, new ThrowingRunnable() {
65+
@Override
66+
public void run() throws Throwable {
67+
s.consume();
68+
}
69+
});
70+
71+
assertEquals("cannot consume EOF", t.getMessage());
6472
}
6573

6674
@Test
@@ -104,11 +112,17 @@ public void consumingSingleCJKCodePointShouldMoveIndex() {
104112

105113
@Test
106114
public void consumingPastSingleCJKCodePointShouldThrow() {
107-
CodePointCharStream s = CharStreams.fromString("\u611B");
108-
s.consume();
109-
thrown.expect(IllegalStateException.class);
110-
thrown.expectMessage("cannot consume EOF");
115+
final CodePointCharStream s = CharStreams.fromString("\u611B");
111116
s.consume();
117+
118+
Throwable t = assertThrows(IllegalStateException.class, new ThrowingRunnable() {
119+
@Override
120+
public void run() throws Throwable {
121+
s.consume();
122+
}
123+
});
124+
125+
assertEquals("cannot consume EOF", t.getMessage());
112126
}
113127

114128
@Test
@@ -144,14 +158,20 @@ public void consumingSingleEmojiCodePointShouldMoveIndex() {
144158

145159
@Test
146160
public void consumingPastEndOfEmojiCodePointWithShouldThrow() {
147-
CodePointCharStream s = CharStreams.fromString(
161+
final CodePointCharStream s = CharStreams.fromString(
148162
new StringBuilder().appendCodePoint(0x1F4A9).toString());
149163
assertEquals(0, s.index());
150164
s.consume();
151165
assertEquals(1, s.index());
152-
thrown.expect(IllegalStateException.class);
153-
thrown.expectMessage("cannot consume EOF");
154-
s.consume();
166+
167+
Throwable t = assertThrows(IllegalStateException.class, new ThrowingRunnable() {
168+
@Override
169+
public void run() throws Throwable {
170+
s.consume();
171+
}
172+
});
173+
174+
assertEquals("cannot consume EOF", t.getMessage());
155175
}
156176

157177
@Test

tool/test/org/antlr/v4/test/tool/TestCharStreams.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import org.antlr.v4.runtime.misc.Utils;
1111
import org.junit.Rule;
1212
import org.junit.Test;
13-
import org.junit.rules.ExpectedException;
13+
import org.junit.function.ThrowingRunnable;
1414
import org.junit.rules.TemporaryFolder;
1515

1616
import java.io.File;
@@ -25,14 +25,12 @@
2525
import java.nio.charset.CodingErrorAction;
2626

2727
import static org.junit.Assert.assertEquals;
28+
import static org.junit.Assert.assertThrows;
2829

2930
public class TestCharStreams {
3031
@Rule
3132
public TemporaryFolder folder = new TemporaryFolder();
3233

33-
@Rule
34-
public ExpectedException thrown = ExpectedException.none();
35-
3634
@Test
3735
public void fromBMPStringHasExpectedSize() {
3836
CharStream s = CharStreams.fromString("hello");
@@ -164,10 +162,14 @@ public void fromInvalidUTF8BytesThrowsInReportMode() throws Exception {
164162
File p = folder.newFile();
165163
byte[] toWrite = new byte[] { (byte)0xCA, (byte)0xFE };
166164
Utils.writeFile(p, toWrite);
167-
ReadableByteChannel c = Channels.newChannel(new FileInputStream(p));
165+
final ReadableByteChannel c = Channels.newChannel(new FileInputStream(p));
168166
try {
169-
thrown.expect(CharacterCodingException.class);
170-
CharStreams.fromChannel(c, 4096, CodingErrorAction.REPORT, "foo");
167+
assertThrows(CharacterCodingException.class, new ThrowingRunnable() {
168+
@Override
169+
public void run() throws Throwable {
170+
CharStreams.fromChannel(c, 4096, CodingErrorAction.REPORT, "foo");
171+
}
172+
});
171173
}
172174
finally {
173175
c.close();

tool/test/org/antlr/v4/test/tool/TestIntegerList.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,13 @@
88

99
import org.antlr.v4.runtime.misc.IntegerList;
1010
import org.antlr.v4.runtime.misc.Utils;
11-
import org.junit.Rule;
1211
import org.junit.Test;
13-
import org.junit.rules.ExpectedException;
12+
import org.junit.function.ThrowingRunnable;
1413

1514
import static org.junit.Assert.assertArrayEquals;
15+
import static org.junit.Assert.assertThrows;
1616

1717
public class TestIntegerList {
18-
@Rule
19-
public ExpectedException thrown = ExpectedException.none();
20-
2118
@Test
2219
public void emptyListToEmptyCharArray() {
2320
IntegerList l = new IntegerList();
@@ -26,10 +23,15 @@ public void emptyListToEmptyCharArray() {
2623

2724
@Test
2825
public void negativeIntegerToCharArrayThrows() {
29-
IntegerList l = new IntegerList();
26+
final IntegerList l = new IntegerList();
3027
l.add(-42);
31-
thrown.expect(IllegalArgumentException.class);
32-
Utils.toCharArray(l);
28+
29+
assertThrows(IllegalArgumentException.class, new ThrowingRunnable() {
30+
@Override
31+
public void run() throws Throwable {
32+
Utils.toCharArray(l);
33+
}
34+
});
3335
}
3436

3537
@Test
@@ -44,10 +46,15 @@ public void surrogateRangeIntegerToCharArray() {
4446

4547
@Test
4648
public void tooLargeIntegerToCharArrayThrows() {
47-
IntegerList l = new IntegerList();
49+
final IntegerList l = new IntegerList();
4850
l.add(0x110000);
49-
thrown.expect(IllegalArgumentException.class);
50-
Utils.toCharArray(l);
51+
52+
assertThrows(IllegalArgumentException.class, new ThrowingRunnable() {
53+
@Override
54+
public void run() throws Throwable {
55+
Utils.toCharArray(l);
56+
}
57+
});
5158
}
5259

5360
@Test

tool/test/org/antlr/v4/test/tool/TestPerformance.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@
9090
import java.util.logging.Logger;
9191

9292
import static org.hamcrest.CoreMatchers.instanceOf;
93-
import static org.junit.Assert.assertThat;
93+
import static org.hamcrest.MatcherAssert.assertThat;
9494
import static org.junit.Assert.assertTrue;
9595

9696
public class TestPerformance extends BaseTest {

tool/test/org/antlr/v4/test/tool/TestUnicodeData.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,15 @@
77
package org.antlr.v4.test.tool;
88

99
import org.antlr.v4.unicode.UnicodeData;
10-
import org.junit.Rule;
1110
import org.junit.Test;
12-
import org.junit.rules.ExpectedException;
11+
import org.junit.function.ThrowingRunnable;
1312

13+
import static org.junit.Assert.assertEquals;
1414
import static org.junit.Assert.assertFalse;
15+
import static org.junit.Assert.assertThrows;
1516
import static org.junit.Assert.assertTrue;
1617

1718
public class TestUnicodeData {
18-
@Rule
19-
public ExpectedException thrown = ExpectedException.none();
20-
2119
@Test
2220
public void testUnicodeGeneralCategoriesLatin() {
2321
assertTrue(UnicodeData.getPropertyCodePoints("Lu").contains('X'));
@@ -208,8 +206,13 @@ public void testPropertyDashSameAsUnderscore() {
208206

209207
@Test
210208
public void modifyingUnicodeDataShouldThrow() {
211-
thrown.expect(IllegalStateException.class);
212-
thrown.expectMessage("can't alter readonly IntervalSet");
213-
UnicodeData.getPropertyCodePoints("L").add(0x12345);
209+
Throwable t = assertThrows(IllegalStateException.class, new ThrowingRunnable() {
210+
@Override
211+
public void run() throws Throwable {
212+
UnicodeData.getPropertyCodePoints("L").add(0x12345);
213+
}
214+
});
215+
216+
assertEquals("can't alter readonly IntervalSet", t.getMessage());
214217
}
215218
}

0 commit comments

Comments
 (0)