From 5d7a713576c8ade0a5201b8d670c448eb33ee160 Mon Sep 17 00:00:00 2001 From: Shuhei Iitsuka Date: Fri, 17 Mar 2023 15:42:37 +0900 Subject: [PATCH] Java code improvement (#133) * More specific assertion error * Add RunWith annotation to tests --- java/src/main/java/com/google/budoux/HTMLProcessor.java | 2 +- java/src/main/java/com/google/budoux/Parser.java | 2 +- java/src/test/java/com/google/budoux/HTMLProcessorTest.java | 3 +++ java/src/test/java/com/google/budoux/ParserTest.java | 3 +++ 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/java/src/main/java/com/google/budoux/HTMLProcessor.java b/java/src/main/java/com/google/budoux/HTMLProcessor.java index 6fdc8b27..b72d9555 100644 --- a/java/src/main/java/com/google/budoux/HTMLProcessor.java +++ b/java/src/main/java/com/google/budoux/HTMLProcessor.java @@ -51,7 +51,7 @@ private HTMLProcessor() {} String[] skipNodesStrings = gson.fromJson(reader, String[].class); skipNodes = new HashSet<>(Arrays.asList(skipNodesStrings)); } catch (JsonSyntaxException | JsonIOException | IOException e) { - throw new RuntimeException(e); + throw new AssertionError(e); } } diff --git a/java/src/main/java/com/google/budoux/Parser.java b/java/src/main/java/com/google/budoux/Parser.java index 383f45a9..4f3c381a 100644 --- a/java/src/main/java/com/google/budoux/Parser.java +++ b/java/src/main/java/com/google/budoux/Parser.java @@ -98,7 +98,7 @@ public static Parser loadByFileName(String modelFileName) { Map> model = gson.fromJson(reader, type); return new Parser(model); } catch (JsonIOException | JsonSyntaxException | IOException e) { - throw new RuntimeException(e); + throw new AssertionError(e); } } diff --git a/java/src/test/java/com/google/budoux/HTMLProcessorTest.java b/java/src/test/java/com/google/budoux/HTMLProcessorTest.java index cfe183f4..d0462ec4 100644 --- a/java/src/test/java/com/google/budoux/HTMLProcessorTest.java +++ b/java/src/test/java/com/google/budoux/HTMLProcessorTest.java @@ -21,8 +21,11 @@ import java.util.Arrays; import java.util.List; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; /** Unit tests for {@link HTMLProcessor}. */ +@RunWith(JUnit4.class) public class HTMLProcessorTest { @Test diff --git a/java/src/test/java/com/google/budoux/ParserTest.java b/java/src/test/java/com/google/budoux/ParserTest.java index 4b477621..a0218955 100644 --- a/java/src/test/java/com/google/budoux/ParserTest.java +++ b/java/src/test/java/com/google/budoux/ParserTest.java @@ -23,8 +23,11 @@ import java.util.List; import java.util.Map; import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.JUnit4; /** Unit tests for {@link Parser}. */ +@RunWith(JUnit4.class) public class ParserTest { @Test