The following issues were found

src/test/java/com/alibaba/json/bvt/bug/Bug_for_javaeye_litterJava.java
4 issues
JUnit tests should include assert() or fail()
Design

Line: 11

              import com.alibaba.fastjson.JSON;

public class Bug_for_javaeye_litterJava extends TestCase {
    public void test_for_bug() throws Exception {
        Group group = new Group();
        group.setId(123L);
        group.setName("xxx");
        group.getClzes().add(Group.class);
        

            

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: 11

              import com.alibaba.fastjson.JSON;

public class Bug_for_javaeye_litterJava extends TestCase {
    public void test_for_bug() throws Exception {
        Group group = new Group();
        group.setId(123L);
        group.setName("xxx");
        group.getClzes().add(Group.class);
        

            

Reported by PMD.

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

Line: 15

                      Group group = new Group();
        group.setId(123L);
        group.setName("xxx");
        group.getClzes().add(Group.class);
        
        String text = JSON.toJSONString(group);
        JSON.parseObject(text, Group.class);
    }


            

Reported by PMD.

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

Line: 21

                      JSON.parseObject(text, Group.class);
    }

    public static class Group {

        private Long        id;
        private String      name;
        private List<Class> clzes = new ArrayList<Class>();


            

Reported by PMD.

src/test/java/com/alibaba/fastjson/deserializer/issue1463/beans/Person.java
4 issues
Found non-transient, non-static member. Please mark as transient or provide accessors.
Error

Line: 16

              
    private static final long serialVersionUID = 248616267815851026L;

    private String name;

    private Integer age;

    public Person(String name, Integer age) {
        this.name = name;

            

Reported by PMD.

Private field 'name' could be made final; it is only initialized in the declaration or constructor.
Design

Line: 16

              
    private static final long serialVersionUID = 248616267815851026L;

    private String name;

    private Integer age;

    public Person(String name, Integer age) {
        this.name = name;

            

Reported by PMD.

Private field 'age' could be made final; it is only initialized in the declaration or constructor.
Design

Line: 18

              
    private String name;

    private Integer age;

    public Person(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

            

Reported by PMD.

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

Line: 18

              
    private String name;

    private Integer age;

    public Person(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/bug/Issue804.java
4 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

              import java.util.List;

public class Issue804 extends TestCase {
    public void test_issue() throws Exception {
        String json = "{\n" +
                "    \"@type\":\"com.alibaba.json.bvt.bug.Issue804$Room\",\n" +
                "    \"children\":[],\n" +
                "    \"name\":\"Room2_1\",\n" +
                "    \"parent\":{\n" +

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 40

              
        Room room = (Room) JSON.parse(json);

        assertSame(room, room.parent.children.get(0));
    }

    @JSONType
    public static class Node {
        protected String name;

            

Reported by PMD.

Potential violation of Law of Demeter (static property access)
Design

Line: 40

              
        Room room = (Room) JSON.parse(json);

        assertSame(room, room.parent.children.get(0));
    }

    @JSONType
    public static class Node {
        protected String name;

            

Reported by PMD.

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

Line: 44

                  }

    @JSONType
    public static class Node {
        protected String name;
        protected Node parent;
        protected List<Node> children = new ArrayList<Node>();

        public String getName() {

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/bug/bug201806/Bug_for_weiqiang.java
4 issues
System.out.println is used
Design

Line: 15

                      sw.config(SerializerFeature.WriteNullStringAsEmpty, Boolean.TRUE);
        JSONSerializer js = new JSONSerializer(sw);
        js.write(JSON.parseObject("{'operator':null, 'status':1}"));
        System.out.println(js);

        String json2 = JSON.toJSONString(JSON.parseObject("{'operator':null, 'status':1}"), SerializerFeature.WriteNullStringAsEmpty);
        System.out.println(json2);
    }
}

            

Reported by PMD.

System.out.println is used
Design

Line: 18

                      System.out.println(js);

        String json2 = JSON.toJSONString(JSON.parseObject("{'operator':null, 'status':1}"), SerializerFeature.WriteNullStringAsEmpty);
        System.out.println(json2);
    }
}

            

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: 10

              import junit.framework.TestCase;

public class Bug_for_weiqiang extends TestCase {
    public void test_for_bug() throws Exception {
        SerializeWriter sw = new SerializeWriter();
        sw.config(SerializerFeature.WriteNullStringAsEmpty, Boolean.TRUE);
        JSONSerializer js = new JSONSerializer(sw);
        js.write(JSON.parseObject("{'operator':null, 'status':1}"));
        System.out.println(js);

            

Reported by PMD.

JUnit tests should include assert() or fail()
Design

Line: 10

              import junit.framework.TestCase;

public class Bug_for_weiqiang extends TestCase {
    public void test_for_bug() throws Exception {
        SerializeWriter sw = new SerializeWriter();
        sw.config(SerializerFeature.WriteNullStringAsEmpty, Boolean.TRUE);
        JSONSerializer js = new JSONSerializer(sw);
        js.write(JSON.parseObject("{'operator':null, 'status':1}"));
        System.out.println(js);

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/bug/Bug_for_xiayucai2012.java
4 issues
JUnit 4 tests that set up tests should use the @Before annotation, JUnit5 tests should use @BeforeEach or @BeforeAll
Design

Line: 16

              

public class Bug_for_xiayucai2012 extends TestCase {
    protected void setUp() throws Exception {
        JSON.defaultTimeZone = TimeZone.getTimeZone("Asia/Shanghai");
        JSON.defaultLocale = Locale.CHINA;
    }
    
    public void test_for_xiayucai2012() throws Exception {

            

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: 21

                      JSON.defaultLocale = Locale.CHINA;
    }
    
    public void test_for_xiayucai2012() throws Exception {
        String text = "{\"date\":\"0000-00-00 00:00:00\"}";
        JSONObject json = JSON.parseObject(text);
        Date date = json.getObject("date", Date.class);
        
        SimpleDateFormat dateFormat = new SimpleDateFormat(JSON.DEFFAULT_DATE_FORMAT, JSON.defaultLocale);

            

Reported by PMD.

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

Line: 24

                  public void test_for_xiayucai2012() throws Exception {
        String text = "{\"date\":\"0000-00-00 00:00:00\"}";
        JSONObject json = JSON.parseObject(text);
        Date date = json.getObject("date", Date.class);
        
        SimpleDateFormat dateFormat = new SimpleDateFormat(JSON.DEFFAULT_DATE_FORMAT, JSON.defaultLocale);
        dateFormat.setTimeZone(JSON.defaultTimeZone);
        
        Assert.assertEquals(dateFormat.parse(json.getString("date")), date);

            

Reported by PMD.

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

Line: 29

                      SimpleDateFormat dateFormat = new SimpleDateFormat(JSON.DEFFAULT_DATE_FORMAT, JSON.defaultLocale);
        dateFormat.setTimeZone(JSON.defaultTimeZone);
        
        Assert.assertEquals(dateFormat.parse(json.getString("date")), date);
    }
}

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/bug/Issue801.java
4 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

               * Created by wenshao on 16/9/2.
 */
public class Issue801 extends TestCase {
    public void test_for_issue() throws Exception {
        String json = "{\"date\":\"0001-01-01T00:00:00\"}";
        Model model = JSON.parseObject(json, Model.class);
    }

    public static class Model {

            

Reported by PMD.

JUnit tests should include assert() or fail()
Design

Line: 13

               * Created by wenshao on 16/9/2.
 */
public class Issue801 extends TestCase {
    public void test_for_issue() throws Exception {
        String json = "{\"date\":\"0001-01-01T00:00:00\"}";
        Model model = JSON.parseObject(json, Model.class);
    }

    public static class Model {

            

Reported by PMD.

Avoid unused local variables such as 'model'.
Design

Line: 15

              public class Issue801 extends TestCase {
    public void test_for_issue() throws Exception {
        String json = "{\"date\":\"0001-01-01T00:00:00\"}";
        Model model = JSON.parseObject(json, Model.class);
    }

    public static class Model {
        @JSONField(format = "yyyy-MM-ddTHH:mm:ss.SSS")
        public Date date;

            

Reported by PMD.

Found 'DU'-anomaly for variable 'model' (lines '15'-'16').
Error

Line: 15

              public class Issue801 extends TestCase {
    public void test_for_issue() throws Exception {
        String json = "{\"date\":\"0001-01-01T00:00:00\"}";
        Model model = JSON.parseObject(json, Model.class);
    }

    public static class Model {
        @JSONField(format = "yyyy-MM-ddTHH:mm:ss.SSS")
        public Date date;

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/ListFloatFieldTest.java
4 issues
System.out.println is used
Design

Line: 19

                      user.getValue().add(1F);

        String text = JSON.toJSONString(user);
        System.out.println(text);

        User user1 = JSON.parseObject(text, User.class);

        Assert.assertEquals(user1.getValue(), user.getValue());
    }

            

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: 13

              
public class ListFloatFieldTest extends TestCase {

    public void test_codec() throws Exception {
        User user = new User();
        user.setValue(new ArrayList<Float>());
        user.getValue().add(1F);

        String text = JSON.toJSONString(user);

            

Reported by PMD.

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

Line: 16

                  public void test_codec() throws Exception {
        User user = new User();
        user.setValue(new ArrayList<Float>());
        user.getValue().add(1F);

        String text = JSON.toJSONString(user);
        System.out.println(text);

        User user1 = JSON.parseObject(text, User.class);

            

Reported by PMD.

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

Line: 23

              
        User user1 = JSON.parseObject(text, User.class);

        Assert.assertEquals(user1.getValue(), user.getValue());
    }

    public static class User {

        private List<Float> value;

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/bug/Issue798_1.java
4 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: 19

               */
public class Issue798_1 extends TestCase {
    
    public void test_for_issue() throws Exception {
        String str = "<p>主要学校:密歇根大学 安娜堡分校、东密西根大学、 克莱利学院、康考迪亚学院 、瓦什特洛社区学院</p>";
        String json = JSON.toJSONString(str);
        assertEquals("\"<p>主要学校:密歇根大学 安娜堡分校、东密西根大学、 克莱利学院\\u007F、康考迪亚学院 \\u007F、瓦什特洛社区学院\\u007F</p>\"", json);

        String parsedStr = (String) JSON.parse(json);

            

Reported by PMD.

Unit tests should not contain more than 1 assert(s).
Design

Line: 19

               */
public class Issue798_1 extends TestCase {
    
    public void test_for_issue() throws Exception {
        String str = "<p>主要学校:密歇根大学 安娜堡分校、东密西根大学、 克莱利学院、康考迪亚学院 、瓦什特洛社区学院</p>";
        String json = JSON.toJSONString(str);
        assertEquals("\"<p>主要学校:密歇根大学 安娜堡分校、东密西根大学、 克莱利学院\\u007F、康考迪亚学院 \\u007F、瓦什特洛社区学院\\u007F</p>\"", json);

        String parsedStr = (String) JSON.parse(json);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 22

                  public void test_for_issue() throws Exception {
        String str = "<p>主要学校:密歇根大学 安娜堡分校、东密西根大学、 克莱利学院、康考迪亚学院 、瓦什特洛社区学院</p>";
        String json = JSON.toJSONString(str);
        assertEquals("\"<p>主要学校:密歇根大学 安娜堡分校、东密西根大学、 克莱利学院\\u007F、康考迪亚学院 \\u007F、瓦什特洛社区学院\\u007F</p>\"", json);

        String parsedStr = (String) JSON.parse(json);
        assertEquals(str, parsedStr);
    }
}

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 25

                      assertEquals("\"<p>主要学校:密歇根大学 安娜堡分校、东密西根大学、 克莱利学院\\u007F、康考迪亚学院 \\u007F、瓦什特洛社区学院\\u007F</p>\"", json);

        String parsedStr = (String) JSON.parse(json);
        assertEquals(str, parsedStr);
    }
}

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_3600/Issue3629.java
4 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: 8

              import junit.framework.TestCase;

public class Issue3629 extends TestCase {
    public void test_for_issue() throws Exception {
        String text1 = "[\n" +
                "    {\n" +
                "        \"author\": \"Nigel Rees\",\n" +
                "        \"category\": \"reference\",\n" +
                "        \"price\": 8.95,\n" +

            

Reported by PMD.

The String literal ' {\n' appears 4 times in this file; the first occurrence is on line 10
Error

Line: 10

              public class Issue3629 extends TestCase {
    public void test_for_issue() throws Exception {
        String text1 = "[\n" +
                "    {\n" +
                "        \"author\": \"Nigel Rees\",\n" +
                "        \"category\": \"reference\",\n" +
                "        \"price\": 8.95,\n" +
                "        \"title\": \"Sayings of the Century\"\n" +
                "    },\n" +

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 40

              

        List<Object> extract = (List) JSONPath.extract(text1, "$..[?(@.price < 10)]");
        assertEquals(2, extract.size());
    }
}

            

Reported by PMD.

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

Line: 40

              

        List<Object> extract = (List) JSONPath.extract(text1, "$..[?(@.price < 10)]");
        assertEquals(2, extract.size());
    }
}

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_2400/Issue2428.java
4 issues
Unit tests should not contain more than 1 assert(s).
Design

Line: 24

                      private String myId;
    }

    public void test_for_issue() {
        Issue2428 demoBean = new Issue2428();
        demoBean.setMyName("test name");
        demoBean.setNestedBean(new NestedBean("test id"));
        String text = JSON.toJSONString(JSON.toJSON(demoBean), SerializerFeature.SortField);
        assertEquals("{\"nestedBean\":{\"myId\":\"test id\"},\"myName\":\"test name\"}", text);

            

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: 24

                      private String myId;
    }

    public void test_for_issue() {
        Issue2428 demoBean = new Issue2428();
        demoBean.setMyName("test name");
        demoBean.setNestedBean(new NestedBean("test id"));
        String text = JSON.toJSONString(JSON.toJSON(demoBean), SerializerFeature.SortField);
        assertEquals("{\"nestedBean\":{\"myId\":\"test id\"},\"myName\":\"test name\"}", text);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 29

                      demoBean.setMyName("test name");
        demoBean.setNestedBean(new NestedBean("test id"));
        String text = JSON.toJSONString(JSON.toJSON(demoBean), SerializerFeature.SortField);
        assertEquals("{\"nestedBean\":{\"myId\":\"test id\"},\"myName\":\"test name\"}", text);

        SerializeConfig serializeConfig = new SerializeConfig();
        serializeConfig.propertyNamingStrategy = PropertyNamingStrategy.SnakeCase;
        text = JSON.toJSONString(JSON.toJSON(demoBean, serializeConfig), SerializerFeature.SortField);
        assertEquals("{\"my_name\":\"test name\",\"nested_bean\":{\"my_id\":\"test id\"}}", text);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 34

                      SerializeConfig serializeConfig = new SerializeConfig();
        serializeConfig.propertyNamingStrategy = PropertyNamingStrategy.SnakeCase;
        text = JSON.toJSONString(JSON.toJSON(demoBean, serializeConfig), SerializerFeature.SortField);
        assertEquals("{\"my_name\":\"test name\",\"nested_bean\":{\"my_id\":\"test id\"}}", text);
    }
}

            

Reported by PMD.