Skip to content

Commit

Permalink
only test compile json assert to reduce size
Browse files Browse the repository at this point in the history
  • Loading branch information
noahzark committed May 6, 2018
1 parent 6db3099 commit a9f30b0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 34 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down
29 changes: 0 additions & 29 deletions src/main/java/moe/imvery/utils/xlsx2json/ExcelParserMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
36 changes: 32 additions & 4 deletions src/test/java/moe/imvery/utils/xlsx2json/ExcelParserMainTest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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)
Expand Down

0 comments on commit a9f30b0

Please sign in to comment.