Skip to content

Commit

Permalink
Merge pull request #73 from tunnelvisionlabs/fix-warnings
Browse files Browse the repository at this point in the history
Fix build warnings related to obsolete APIs
  • Loading branch information
sharwell authored Dec 29, 2020
2 parents 71b8806 + 98fb770 commit c0f9a7a
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,20 @@
import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.function.ThrowingRunnable;

import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeTrue;

public class Antlr4MojoTest {
@Rule
public ExpectedException thrown = ExpectedException.none();

@Rule
public final TestResources resources = new TestResources();

Expand Down Expand Up @@ -347,9 +346,9 @@ public void processWhenDependencyRemoved() throws Exception {

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

MavenProject project = maven.readMavenProject(baseDir);
MavenSession session = maven.newMavenSession(project);
MojoExecution exec = maven.newMojoExecution("antlr4");
final MavenProject project = maven.readMavenProject(baseDir);
final MavenSession session = maven.newMavenSession(project);
final MojoExecution exec = maven.newMojoExecution("antlr4");

maven.executeMojo(session, project, exec);

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

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

maven.executeMojo(session, project, exec);
assertEquals("ANTLR 4 caught 1 build errors.", t.getMessage());
} finally {
temp.close();
}
Expand Down
62 changes: 41 additions & 21 deletions runtime/Java/test/org/antlr/v4/runtime/TestCodePointCharStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@
package org.antlr.v4.runtime;

import org.antlr.v4.runtime.misc.Interval;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.function.ThrowingRunnable;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

public class TestCodePointCharStream {
@Rule
public ExpectedException thrown = ExpectedException.none();

@Test
public void emptyBytesHasSize0() {
CodePointCharStream s = CharStreams.fromString("");
Expand All @@ -34,10 +31,15 @@ public void emptyBytesLookAheadReturnsEOF() {

@Test
public void consumingEmptyStreamShouldThrow() {
CodePointCharStream s = CharStreams.fromString("");
thrown.expect(IllegalStateException.class);
thrown.expectMessage("cannot consume EOF");
s.consume();
final CodePointCharStream s = CharStreams.fromString("");
Throwable t = assertThrows(IllegalStateException.class, new ThrowingRunnable() {
@Override
public void run() throws Throwable {
s.consume();
}
});

assertEquals("cannot consume EOF", t.getMessage());
}

@Test
Expand All @@ -56,11 +58,17 @@ public void consumingSingleLatinCodePointShouldMoveIndex() {

@Test
public void consumingPastSingleLatinCodePointShouldThrow() {
CodePointCharStream s = CharStreams.fromString("X");
s.consume();
thrown.expect(IllegalStateException.class);
thrown.expectMessage("cannot consume EOF");
final CodePointCharStream s = CharStreams.fromString("X");
s.consume();

Throwable t = assertThrows(IllegalStateException.class, new ThrowingRunnable() {
@Override
public void run() throws Throwable {
s.consume();
}
});

assertEquals("cannot consume EOF", t.getMessage());
}

@Test
Expand Down Expand Up @@ -104,11 +112,17 @@ public void consumingSingleCJKCodePointShouldMoveIndex() {

@Test
public void consumingPastSingleCJKCodePointShouldThrow() {
CodePointCharStream s = CharStreams.fromString("\u611B");
s.consume();
thrown.expect(IllegalStateException.class);
thrown.expectMessage("cannot consume EOF");
final CodePointCharStream s = CharStreams.fromString("\u611B");
s.consume();

Throwable t = assertThrows(IllegalStateException.class, new ThrowingRunnable() {
@Override
public void run() throws Throwable {
s.consume();
}
});

assertEquals("cannot consume EOF", t.getMessage());
}

@Test
Expand Down Expand Up @@ -144,14 +158,20 @@ public void consumingSingleEmojiCodePointShouldMoveIndex() {

@Test
public void consumingPastEndOfEmojiCodePointWithShouldThrow() {
CodePointCharStream s = CharStreams.fromString(
final CodePointCharStream s = CharStreams.fromString(
new StringBuilder().appendCodePoint(0x1F4A9).toString());
assertEquals(0, s.index());
s.consume();
assertEquals(1, s.index());
thrown.expect(IllegalStateException.class);
thrown.expectMessage("cannot consume EOF");
s.consume();

Throwable t = assertThrows(IllegalStateException.class, new ThrowingRunnable() {
@Override
public void run() throws Throwable {
s.consume();
}
});

assertEquals("cannot consume EOF", t.getMessage());
}

@Test
Expand Down
16 changes: 9 additions & 7 deletions tool/test/org/antlr/v4/test/tool/TestCharStreams.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.antlr.v4.runtime.misc.Utils;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.function.ThrowingRunnable;
import org.junit.rules.TemporaryFolder;

import java.io.File;
Expand All @@ -25,14 +25,12 @@
import java.nio.charset.CodingErrorAction;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThrows;

public class TestCharStreams {
@Rule
public TemporaryFolder folder = new TemporaryFolder();

@Rule
public ExpectedException thrown = ExpectedException.none();

@Test
public void fromBMPStringHasExpectedSize() {
CharStream s = CharStreams.fromString("hello");
Expand Down Expand Up @@ -164,10 +162,14 @@ public void fromInvalidUTF8BytesThrowsInReportMode() throws Exception {
File p = folder.newFile();
byte[] toWrite = new byte[] { (byte)0xCA, (byte)0xFE };
Utils.writeFile(p, toWrite);
ReadableByteChannel c = Channels.newChannel(new FileInputStream(p));
final ReadableByteChannel c = Channels.newChannel(new FileInputStream(p));
try {
thrown.expect(CharacterCodingException.class);
CharStreams.fromChannel(c, 4096, CodingErrorAction.REPORT, "foo");
assertThrows(CharacterCodingException.class, new ThrowingRunnable() {
@Override
public void run() throws Throwable {
CharStreams.fromChannel(c, 4096, CodingErrorAction.REPORT, "foo");
}
});
}
finally {
c.close();
Expand Down
29 changes: 18 additions & 11 deletions tool/test/org/antlr/v4/test/tool/TestIntegerList.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@

import org.antlr.v4.runtime.misc.IntegerList;
import org.antlr.v4.runtime.misc.Utils;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.function.ThrowingRunnable;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertThrows;

public class TestIntegerList {
@Rule
public ExpectedException thrown = ExpectedException.none();

@Test
public void emptyListToEmptyCharArray() {
IntegerList l = new IntegerList();
Expand All @@ -26,10 +23,15 @@ public void emptyListToEmptyCharArray() {

@Test
public void negativeIntegerToCharArrayThrows() {
IntegerList l = new IntegerList();
final IntegerList l = new IntegerList();
l.add(-42);
thrown.expect(IllegalArgumentException.class);
Utils.toCharArray(l);

assertThrows(IllegalArgumentException.class, new ThrowingRunnable() {
@Override
public void run() throws Throwable {
Utils.toCharArray(l);
}
});
}

@Test
Expand All @@ -44,10 +46,15 @@ public void surrogateRangeIntegerToCharArray() {

@Test
public void tooLargeIntegerToCharArrayThrows() {
IntegerList l = new IntegerList();
final IntegerList l = new IntegerList();
l.add(0x110000);
thrown.expect(IllegalArgumentException.class);
Utils.toCharArray(l);

assertThrows(IllegalArgumentException.class, new ThrowingRunnable() {
@Override
public void run() throws Throwable {
Utils.toCharArray(l);
}
});
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion tool/test/org/antlr/v4/test/tool/TestPerformance.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
import java.util.logging.Logger;

import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertTrue;

public class TestPerformance extends BaseTest {
Expand Down
19 changes: 11 additions & 8 deletions tool/test/org/antlr/v4/test/tool/TestUnicodeData.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@
package org.antlr.v4.test.tool;

import org.antlr.v4.unicode.UnicodeData;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.function.ThrowingRunnable;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;

public class TestUnicodeData {
@Rule
public ExpectedException thrown = ExpectedException.none();

@Test
public void testUnicodeGeneralCategoriesLatin() {
assertTrue(UnicodeData.getPropertyCodePoints("Lu").contains('X'));
Expand Down Expand Up @@ -208,8 +206,13 @@ public void testPropertyDashSameAsUnderscore() {

@Test
public void modifyingUnicodeDataShouldThrow() {
thrown.expect(IllegalStateException.class);
thrown.expectMessage("can't alter readonly IntervalSet");
UnicodeData.getPropertyCodePoints("L").add(0x12345);
Throwable t = assertThrows(IllegalStateException.class, new ThrowingRunnable() {
@Override
public void run() throws Throwable {
UnicodeData.getPropertyCodePoints("L").add(0x12345);
}
});

assertEquals("can't alter readonly IntervalSet", t.getMessage());
}
}

0 comments on commit c0f9a7a

Please sign in to comment.