Skip to content

Commit

Permalink
Merge pull request #527 from johnjaylward/GithubAction
Browse files Browse the repository at this point in the history
Fixes for Unit tests and supports GitHub Actions
  • Loading branch information
stleary authored Jun 5, 2020
2 parents dced1b4 + c11c006 commit 601114e
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 190 deletions.
74 changes: 74 additions & 0 deletions .github/workflows/pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven

name: Java CI with Maven

on:
push:
# branches: [ master ]
pull_request:
branches: [ master ]

jobs:
# old-school build and jar method. No tests run or compiled.
build-1_6:
runs-on: ubuntu-16.04
strategy:
matrix:
# build for java 1.6, however don't run any tests
java: [ 1.6 ]
name: Java ${{ matrix.java }}
steps:
- uses: actions/checkout@v2
- name: Setup java
uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java }}
- name: Compile Java ${{ matrix.java }}
run: |
mkdir -p target/classes
javac -d target/classes/ src/main/java/org/json/*.java
- name: Create java ${{ matrix.java }} JAR
run: |
jar cvf target/org.json.jar -C target/classes .
- name: Upload Java ${{ matrix.java }} JAR
uses: actions/upload-artifact@v1
with:
name: Java ${{ matrix.java }} JAR
path: target/org.json.jar

build:
runs-on: ubuntu-16.04
strategy:
matrix:
# build against supported Java LTS versions:
java: [ 1.7, 8, 11 ]
name: Java ${{ matrix.java }}
steps:
- uses: actions/checkout@v2
- name: Setup java
uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java }}
- name: Compile Java ${{ matrix.java }}
run: mvn clean compile -Dmaven.compiler.source=${{ matrix.java }} -Dmaven.compiler.target=${{ matrix.java }} -Dmaven.test.skip=true -Dmaven.site.skip=true -Dmaven.javadoc.skip=true
- name: Run Tests ${{ matrix.java }}
run: |
mvn test -Dmaven.compiler.source=${{ matrix.java }} -Dmaven.compiler.target=${{ matrix.java }}
- name: Build Test Report ${{ matrix.java }}
if: ${{ always() }}
run: |
mvn surefire-report:report-only -Dmaven.compiler.source=${{ matrix.java }} -Dmaven.compiler.target=${{ matrix.java }}
mvn site -DgenerateReports=false -Dmaven.compiler.source=${{ matrix.java }} -Dmaven.compiler.target=${{ matrix.java }}
- name: Upload Test Results ${{ matrix.java }}
if: ${{ always() }}
uses: actions/upload-artifact@v1
with:
name: Test Results ${{ matrix.java }}
path: target/surefire-reports/
- name: Upload Test Report ${{ matrix.java }}
if: ${{ always() }}
uses: actions/upload-artifact@v1
with:
name: Test Report ${{ matrix.java }}
path: target/site/
56 changes: 34 additions & 22 deletions src/test/java/org/json/junit/JSONObjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1856,10 +1856,12 @@ public void jsonObjectToStringIndent() {
" ]\n" +
"}";
JSONObject jsonObject = new JSONObject(jsonObject0Str);
assertEquals("toString()",jsonObject0Str, jsonObject.toString());
assertEquals("toString(0)",jsonObject0Str, jsonObject.toString(0));
assertEquals("toString(1)",jsonObject1Str, jsonObject.toString(1));
assertEquals("toString(4)",jsonObject4Str, jsonObject.toString(4));
// contents are tested in other methods, in this case just validate the spacing by
// checking length
assertEquals("toString() length",jsonObject0Str.length(), jsonObject.toString().length());
assertEquals("toString(0) length",jsonObject0Str.length(), jsonObject.toString(0).length());
assertEquals("toString(1) length",jsonObject1Str.length(), jsonObject.toString(1).length());
assertEquals("toString(4) length",jsonObject4Str.length(), jsonObject.toString(4).length());

JSONObject jo = new JSONObject().put("TABLE", new JSONObject().put("yhoo", new JSONObject()));
assertEquals("toString(2)","{\"TABLE\": {\"yhoo\": {}}}", jo.toString(2));
Expand Down Expand Up @@ -2630,9 +2632,10 @@ public void write() throws IOException {
JSONObject jsonObject = new JSONObject(str);
try (StringWriter stringWriter = new StringWriter()) {
String actualStr = jsonObject.write(stringWriter).toString();
assertTrue("write() expected " +expectedStr+
" but found " +actualStr,
expectedStr.equals(actualStr));
// key order may change. verify length and individual key content
assertEquals("length", expectedStr.length(), actualStr.length());
assertTrue("key1", actualStr.contains("\"key1\":\"value1\""));
assertTrue("key2", actualStr.contains("\"key2\":[1,2,3]"));
}
}

Expand Down Expand Up @@ -2734,16 +2737,25 @@ public void write3Param() throws IOException {
" ]\n" +
" }";
JSONObject jsonObject = new JSONObject(str0);
String expectedStr = str0;
try (StringWriter stringWriter = new StringWriter();) {
String actualStr = jsonObject.write(stringWriter,0,0).toString();
assertEquals(expectedStr, actualStr);

assertEquals("length", str0.length(), actualStr.length());
assertTrue("key1", actualStr.contains("\"key1\":\"value1\""));
assertTrue("key2", actualStr.contains("\"key2\":[1,false,3.14]"));
}

expectedStr = str2;

try (StringWriter stringWriter = new StringWriter();) {
String actualStr = jsonObject.write(stringWriter,2,1).toString();
assertEquals(expectedStr, actualStr);

assertEquals("length", str2.length(), actualStr.length());
assertTrue("key1", actualStr.contains(" \"key1\": \"value1\""));
assertTrue("key2", actualStr.contains(" \"key2\": [\n" +
" 1,\n" +
" false,\n" +
" 3.14\n" +
" ]")
);
}
}

Expand Down Expand Up @@ -2978,9 +2990,9 @@ public void toMap() {
@Test
public void testSingletonBean() {
final JSONObject jo = new JSONObject(Singleton.getInstance());
// assertEquals(jo.keySet().toString(), 1, jo.length());
// assertEquals(0, jo.get("someInt"));
// assertEquals(null, jo.opt("someString"));
assertEquals(jo.keySet().toString(), 1, jo.length());
assertEquals(0, jo.get("someInt"));
assertEquals(null, jo.opt("someString"));

// Update the singleton values
Singleton.getInstance().setSomeInt(42);
Expand All @@ -2991,8 +3003,8 @@ public void testSingletonBean() {
assertEquals("Something", jo2.get("someString"));

// ensure our original jo hasn't changed.
// assertEquals(0, jo.get("someInt"));
// assertEquals(null, jo.opt("someString"));
assertEquals(0, jo.get("someInt"));
assertEquals(null, jo.opt("someString"));
}

/**
Expand All @@ -3002,9 +3014,9 @@ public void testSingletonBean() {
@Test
public void testSingletonEnumBean() {
final JSONObject jo = new JSONObject(SingletonEnum.getInstance());
// assertEquals(jo.keySet().toString(), 1, jo.length());
// assertEquals(0, jo.get("someInt"));
// assertEquals(null, jo.opt("someString"));
assertEquals(jo.keySet().toString(), 1, jo.length());
assertEquals(0, jo.get("someInt"));
assertEquals(null, jo.opt("someString"));

// Update the singleton values
SingletonEnum.getInstance().setSomeInt(42);
Expand All @@ -3015,8 +3027,8 @@ public void testSingletonEnumBean() {
assertEquals("Something", jo2.get("someString"));

// ensure our original jo hasn't changed.
// assertEquals(0, jo.get("someInt"));
// assertEquals(null, jo.opt("someString"));
assertEquals(0, jo.get("someInt"));
assertEquals(null, jo.opt("someString"));
}

/**
Expand Down
49 changes: 0 additions & 49 deletions src/test/java/org/json/junit/JunitTestSuite.java

This file was deleted.

43 changes: 0 additions & 43 deletions src/test/java/org/json/junit/TestRunner.java

This file was deleted.

Loading

0 comments on commit 601114e

Please sign in to comment.