diff --git a/build.gradle b/build.gradle index 0ce8188..d31576a 100644 --- a/build.gradle +++ b/build.gradle @@ -20,7 +20,7 @@ dependencies { compile group: 'org.json', name: 'json', version: '20160212' // http://mvnrepository.com/artifact/org.skyscreamer/jsonassert - compile group: 'org.skyscreamer', name: 'jsonassert', version: '1.2.3' + testCompile group: 'org.skyscreamer', name: 'jsonassert', version: '1.2.3' testCompile group: 'junit', name: 'junit', version: '4.11' } diff --git a/src/main/java/moe/imvery/utils/xlsx2json/ExcelParserMain.java b/src/main/java/moe/imvery/utils/xlsx2json/ExcelParserMain.java index 928a2e1..d779157 100644 --- a/src/main/java/moe/imvery/utils/xlsx2json/ExcelParserMain.java +++ b/src/main/java/moe/imvery/utils/xlsx2json/ExcelParserMain.java @@ -3,10 +3,7 @@ import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.ss.usermodel.*; import org.json.JSONArray; -import org.json.JSONException; import org.json.JSONObject; -import org.skyscreamer.jsonassert.JSONAssert; -import org.skyscreamer.jsonassert.JSONParser; import java.io.*; import java.nio.file.Files; @@ -116,32 +113,6 @@ public static void parseExcelFile(String targetName, String[] sheetList, boolean } } - /** - * Validate two json file. If it isn't it throws an {@link AssertionError}. - * @param expectedFileName Expected JSON file - * @param targetFileName File to compare - * @param strict Enables strict checking - * @throws JSONException - */ - public static void validateJson(String expectedFileName, String targetFileName, boolean strict) { - try { - System.out.println("Checking " + targetFileName + " ... "); - Path path = Paths.get(targetFileName); - BufferedReader reader = Files.newBufferedReader(path); - String jsonText = reader.readLine(); - - path = Paths.get(expectedFileName); - reader = Files.newBufferedReader(path); - String expected = reader.readLine(); - - JSONAssert.assertEquals(expected, jsonText, false); - - System.out.println("Passed."); - } catch (IOException e) { - e.printStackTrace(); - } - } - public static void main(String[] args) throws Exception{ String[] configs = args; if (args.length == 1) { diff --git a/src/test/java/moe/imvery/utils/xlsx2json/ExcelParserMainTest.java b/src/test/java/moe/imvery/utils/xlsx2json/ExcelParserMainTest.java index 6e8aeb8..a0407ff 100644 --- a/src/test/java/moe/imvery/utils/xlsx2json/ExcelParserMainTest.java +++ b/src/test/java/moe/imvery/utils/xlsx2json/ExcelParserMainTest.java @@ -1,9 +1,11 @@ package moe.imvery.utils.xlsx2json; +import org.json.JSONException; import org.junit.Test; import org.skyscreamer.jsonassert.JSONAssert; import java.io.BufferedReader; +import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -15,32 +17,58 @@ */ public class ExcelParserMainTest { + /** + * Validate two json file. If it isn't it throws an {@link AssertionError}. + * @param expectedFileName Expected JSON file + * @param targetFileName File to compare + * @param strict Enables strict checking + * @throws JSONException + */ + public static void validateJson(String expectedFileName, String targetFileName, boolean strict) { + try { + System.out.println("Checking " + targetFileName + " ... "); + Path path = Paths.get(targetFileName); + BufferedReader reader = Files.newBufferedReader(path); + String jsonText = reader.readLine(); + + path = Paths.get(expectedFileName); + reader = Files.newBufferedReader(path); + String expected = reader.readLine(); + + JSONAssert.assertEquals(expected, jsonText, false); + + System.out.println("Passed."); + } catch (IOException e) { + e.printStackTrace(); + } + } + @Test public void main() throws Exception { ExcelParserMain.main(new String[]{"testcases/test.xlsx", "map", "true"}); - ExcelParserMain.validateJson("testcases/test3.expected.json", "testcases/test.json", false); + validateJson("testcases/test3.expected.json", "testcases/test.json", false); } @Test public void mainMultisheets() throws Exception { ExcelParserMain.main(new String[]{"testcases/test.xlsx", "weaponStuffs skillStuffs essenceStuffs", "true"}); - ExcelParserMain.validateJson("testcases/test4.expected.json", "testcases/test.json", false); + validateJson("testcases/test4.expected.json", "testcases/test.json", false); } @Test public void mainHideSheetName() throws Exception { ExcelParserMain.main(new String[]{"testcases/test.xlsx", "map", "false"}); - ExcelParserMain.validateJson("testcases/test5.expected.json", "testcases/test.json", false); + validateJson("testcases/test5.expected.json", "testcases/test.json", false); } @Test public void mainMultiSheetsAndHideSheetName() throws Exception { ExcelParserMain.main(new String[]{"testcases/test.xlsx", "map monster", "false"}); - ExcelParserMain.validateJson("testcases/test6.expected.json", "testcases/test.json", false); + validateJson("testcases/test6.expected.json", "testcases/test.json", false); } @Test(expected=IllegalArgumentException.class)