The following issues were found

src/test/java/com/alibaba/json/bvt/serializer/FieldOrderTest.java
3 issues
JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 10

               * Created by wenshao on 2016/11/2.
 */
public class FieldOrderTest extends TestCase {
    public void test_field_order() throws Exception {
        Person p = new Person();
        p.setName("njb");
        School s = new School();
        s.setName("llyz");
        p.setSchool(s);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 17

                      s.setName("llyz");
        p.setSchool(s);
        String json = JSON.toJSONString(p);
        assertEquals("{\"name\":\"njb\",\"school\":{\"name\":\"llyz\"}}", json);
    }

    public static class Person {
        private String name;
        private School school;

            

Reported by PMD.

The class 'Person' is suspected to be a Data Class (WOC=0.000%, NOPA=0, NOAM=5, WMC=5)
Design

Line: 20

                      assertEquals("{\"name\":\"njb\",\"school\":{\"name\":\"llyz\"}}", json);
    }

    public static class Person {
        private String name;
        private School school;

        public boolean isSchool() {
            return false;

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/serializer/filters/AfterFilterTest.java
3 issues
JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 12

              import com.alibaba.fastjson.serializer.BeforeFilter;

public class AfterFilterTest extends TestCase {
    public void test_afterFilter() throws Exception {
        AfterFilter filter = new AfterFilter() {
            
            @Override
            public void writeAfter(Object object) {
                this.writeKeyValue("id", 123);

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 23

                      Assert.assertEquals("{\"id\":123}",JSON.toJSONString( new VO(), filter));
    }
    
    public void test_afterFilter2() throws Exception {
        AfterFilter filter = new AfterFilter() {
            
            @Override
            public void writeAfter(Object object) {
                this.writeKeyValue("id", 123);

            

Reported by PMD.

Avoid unused imports such as 'com.alibaba.fastjson.serializer.BeforeFilter'
Design

Line: 9

              
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.AfterFilter;
import com.alibaba.fastjson.serializer.BeforeFilter;

public class AfterFilterTest extends TestCase {
    public void test_afterFilter() throws Exception {
        AfterFilter filter = new AfterFilter() {
            

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/serializer/ExtendsTest.java
3 issues
JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 11

              
public class ExtendsTest extends TestCase {

    public void test_extends() throws Exception {
        B b = new B();
        b.setId(123);
        b.setName("加爵");

        JSONObject json = JSON.parseObject(JSON.toJSONString(b));

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 17

                      b.setName("加爵");

        JSONObject json = JSON.parseObject(JSON.toJSONString(b));
        Assert.assertEquals(b.getId(), json.get("id"));
        Assert.assertEquals(b.getName(), json.get("name"));
    }

    public static class A {


            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 18

              
        JSONObject json = JSON.parseObject(JSON.toJSONString(b));
        Assert.assertEquals(b.getId(), json.get("id"));
        Assert.assertEquals(b.getName(), json.get("name"));
    }

    public static class A {

        private int id;

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/serializer/ErrorGetterTest.java
3 issues
JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 9

              
public class ErrorGetterTest extends TestCase {

    public void test_0() throws Exception {
        Model m = new Model();

        Exception error = null;
        try {
            JSON.toJSONString(m);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 18

                      } catch (JSONException ex) {
            error = ex;
        }
        assertNotNull(error);
    }

    private static class Model {
        public int getValue() {
            throw new UnsupportedOperationException();

            

Reported by PMD.

Found 'DD'-anomaly for variable 'error' (lines '12'-'16').
Error

Line: 12

                  public void test_0() throws Exception {
        Model m = new Model();

        Exception error = null;
        try {
            JSON.toJSONString(m);
        } catch (JSONException ex) {
            error = ex;
        }

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_1600/Issue1649.java
3 issues
System.out.println is used
Design

Line: 56

                      }

        public static void main(String[] args) {
            System.out.println(JSON.toJSONString(new Apple()));
        }
    }
}

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 9

              import junit.framework.TestCase;

public class Issue1649 extends TestCase {
    public void test_for_issue() throws Exception {
        Apple apple = new Apple();
        String json = JSON.toJSONString(apple);
        assertEquals("{\"color\":\"\",\"productCity\":\"\",\"size\":0}", json);
    }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 12

                  public void test_for_issue() throws Exception {
        Apple apple = new Apple();
        String json = JSON.toJSONString(apple);
        assertEquals("{\"color\":\"\",\"productCity\":\"\",\"size\":0}", json);
    }

    @JSONType(serialzeFeatures = {SerializerFeature.WriteNullStringAsEmpty,SerializerFeature.WriteMapNullValue})
    public static class Apple {


            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_1600/Issue1649_private.java
3 issues
System.out.println is used
Design

Line: 56

                      }

        public static void main(String[] args) {
            System.out.println(JSON.toJSONString(new Apple()));
        }
    }
}

            

Reported by PMD.

JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 9

              import junit.framework.TestCase;

public class Issue1649_private extends TestCase {
    public void test_for_issue() throws Exception {
        Apple apple = new Apple();
        String json = JSON.toJSONString(apple);
        assertEquals("{\"color\":\"\",\"productCity\":\"\",\"size\":0}", json);
    }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 12

                  public void test_for_issue() throws Exception {
        Apple apple = new Apple();
        String json = JSON.toJSONString(apple);
        assertEquals("{\"color\":\"\",\"productCity\":\"\",\"size\":0}", json);
    }

    @JSONType(serialzeFeatures = {SerializerFeature.WriteNullStringAsEmpty,SerializerFeature.WriteMapNullValue})
    private static class Apple {


            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/JSONArrayParseTest.java
3 issues
JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 13

              import com.alibaba.fastjson.TypeReference;

public class JSONArrayParseTest extends TestCase {
    public void test_array() throws Exception {
        String text = "[{id:123}]";
        List<Map<String, Integer>> array = JSON.parseObject(text, new TypeReference<List<Map<String, Integer>>>() {});
        Assert.assertEquals(1, array.size());
        Map<String, Integer> map  = array.get(0);
        Assert.assertEquals(123, map.get("id").intValue());

            

Reported by PMD.

Potential violation of Law of Demeter (method chain calls)
Design

Line: 18

                      List<Map<String, Integer>> array = JSON.parseObject(text, new TypeReference<List<Map<String, Integer>>>() {});
        Assert.assertEquals(1, array.size());
        Map<String, Integer> map  = array.get(0);
        Assert.assertEquals(123, map.get("id").intValue());
    }
}

            

Reported by PMD.

Potential violation of Law of Demeter (object not created locally)
Design

Line: 18

                      List<Map<String, Integer>> array = JSON.parseObject(text, new TypeReference<List<Map<String, Integer>>>() {});
        Assert.assertEquals(1, array.size());
        Map<String, Integer> map  = array.get(0);
        Assert.assertEquals(123, map.get("id").intValue());
    }
}

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_1200/Issue1222.java
3 issues
JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 12

               * Created by wenshao on 01/06/2017.
 */
public class Issue1222 extends TestCase {
    public void test_for_issue() throws Exception {
        Model model = new Model();
        model.type = Type.A;
        String text = JSON.toJSONString(model, SerializerFeature.WriteEnumUsingToString);
        assertEquals("{\"type\":\"TypeA\"}", text);
    }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 16

                      Model model = new Model();
        model.type = Type.A;
        String text = JSON.toJSONString(model, SerializerFeature.WriteEnumUsingToString);
        assertEquals("{\"type\":\"TypeA\"}", text);
    }

    public static class Model {
        public Type type;
    }

            

Reported by PMD.

Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 20

                  }

    public static class Model {
        public Type type;
    }

    public static enum Type implements JSONAware {
        A, B;


            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_3600/Issue3655.java
3 issues
System.out.println is used
Design

Line: 19

                  public void test_inherit_from_abstract_class_1() {
        issue3655_b b = new issue3655_b(null, null, null, null, null, null, null, null, null);
        String result = JSON.toJSONString(b, SerializerFeature.WriteNullStringAsEmpty);
        System.out.println(result);
        Assert.assertEquals(jsonStr, result);
    }

    @Test
    public void test_inherit_from_abstract_class_2() {

            

Reported by PMD.

System.out.println is used
Design

Line: 27

                  public void test_inherit_from_abstract_class_2() {
        issue3655_c c = new issue3655_c(null, null, null, null, null, null, null, null, null);
        String result = JSON.toJSONString(c, SerializerFeature.WriteNullStringAsEmpty);
        System.out.println(result);
        Assert.assertEquals(jsonStr, result);
    }

    public static class issue3655_b extends issue3655_a {
        private String data;

            

Reported by PMD.

The class 'issue3655_b' is suspected to be a Data Class (WOC=0.000%, NOPA=0, NOAM=18, WMC=19)
Design

Line: 31

                      Assert.assertEquals(jsonStr, result);
    }

    public static class issue3655_b extends issue3655_a {
        private String data;
        private String data2;
        private String data3;
        private String data4;
        private String data5;

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/JSONLexerTest_10.java
3 issues
JUnit 4 tests that execute tests should use the @Test annotation, JUnit 5 tests should use @Test, @RepeatedTest, @TestFactory, @TestTemplate or @ParameterizedTest
Design

Line: 11

              
public class JSONLexerTest_10 extends TestCase {

    public void test_a() throws Exception {
        Exception error = null;
        try {
            JSON.parseObject("{\"type\":\"AAA", VO.class);
        } catch (Exception ex) {
            error = ex;

            

Reported by PMD.

Avoid catching generic exceptions such as NullPointerException, RuntimeException, Exception in try-catch block
Design

Line: 15

                      Exception error = null;
        try {
            JSON.parseObject("{\"type\":\"AAA", VO.class);
        } catch (Exception ex) {
            error = ex;
        }
        Assert.assertNotNull(error);
    }


            

Reported by PMD.

Found 'DD'-anomaly for variable 'error' (lines '12'-'16').
Error

Line: 12

              public class JSONLexerTest_10 extends TestCase {

    public void test_a() throws Exception {
        Exception error = null;
        try {
            JSON.parseObject("{\"type\":\"AAA", VO.class);
        } catch (Exception ex) {
            error = ex;
        }

            

Reported by PMD.