The following issues were found

src/test/java/com/alibaba/json/bvt/serializer/JSONFieldTest_unwrapped_4.java
15 issues
Unit tests should not contain more than 1 assert(s).
Design

Line: 13

              
public class JSONFieldTest_unwrapped_4 extends TestCase {

    public void test_jsonField() throws Exception {
        Health vo = new Health();
        vo.id = 123;
        vo.border = 234;
        vo.details.put("latitude", 37);
        vo.details.put("longitude", 127);

            

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 JSONFieldTest_unwrapped_4 extends TestCase {

    public void test_jsonField() throws Exception {
        Health vo = new Health();
        vo.id = 123;
        vo.border = 234;
        vo.details.put("latitude", 37);
        vo.details.put("longitude", 127);

            

Reported by PMD.

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

Line: 17

                      Health vo = new Health();
        vo.id = 123;
        vo.border = 234;
        vo.details.put("latitude", 37);
        vo.details.put("longitude", 127);

        String text = JSON.toJSONString(vo);
        Assert.assertEquals("{\"border\":234,\"latitude\":37,\"longitude\":127,\"id\":123}", text);


            

Reported by PMD.

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

Line: 18

                      vo.id = 123;
        vo.border = 234;
        vo.details.put("latitude", 37);
        vo.details.put("longitude", 127);

        String text = JSON.toJSONString(vo);
        Assert.assertEquals("{\"border\":234,\"latitude\":37,\"longitude\":127,\"id\":123}", text);

        Health vo2 = JSON.parseObject(text, Health.class);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 24

                      Assert.assertEquals("{\"border\":234,\"latitude\":37,\"longitude\":127,\"id\":123}", text);

        Health vo2 = JSON.parseObject(text, Health.class);
        assertNotNull(vo2.details);
        assertEquals(37, vo2.details.get("latitude"));
        assertEquals(127, vo2.details.get("longitude"));

    }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 25

              
        Health vo2 = JSON.parseObject(text, Health.class);
        assertNotNull(vo2.details);
        assertEquals(37, vo2.details.get("latitude"));
        assertEquals(127, vo2.details.get("longitude"));

    }

    public void test_null() throws Exception {

            

Reported by PMD.

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

Line: 25

              
        Health vo2 = JSON.parseObject(text, Health.class);
        assertNotNull(vo2.details);
        assertEquals(37, vo2.details.get("latitude"));
        assertEquals(127, vo2.details.get("longitude"));

    }

    public void test_null() throws Exception {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 26

                      Health vo2 = JSON.parseObject(text, Health.class);
        assertNotNull(vo2.details);
        assertEquals(37, vo2.details.get("latitude"));
        assertEquals(127, vo2.details.get("longitude"));

    }

    public void test_null() throws Exception {
        Health vo = new Health();

            

Reported by PMD.

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

Line: 26

                      Health vo2 = JSON.parseObject(text, Health.class);
        assertNotNull(vo2.details);
        assertEquals(37, vo2.details.get("latitude"));
        assertEquals(127, vo2.details.get("longitude"));

    }

    public void test_null() throws Exception {
        Health vo = new Health();

            

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

              
    }

    public void test_null() throws Exception {
        Health vo = new Health();
        vo.id = 123;
        vo.border = 234;
        vo.details = null;


            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/bug/Issue1023.java
15 issues
Unit tests should not contain more than 1 assert(s).
Design

Line: 18

               * Created by wenshao on 11/03/2017.
 */
public class Issue1023 extends TestCase {
    public void test_for_issue() throws Exception {
        Date now = new Date();

        GregorianCalendar gregorianCalendar = (GregorianCalendar) GregorianCalendar.getInstance();
        gregorianCalendar.setTime(now);


            

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

               * Created by wenshao on 11/03/2017.
 */
public class Issue1023 extends TestCase {
    public void test_for_issue() throws Exception {
        Date now = new Date();

        GregorianCalendar gregorianCalendar = (GregorianCalendar) GregorianCalendar.getInstance();
        gregorianCalendar.setTime(now);


            

Reported by PMD.

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

Line: 22

                      Date now = new Date();

        GregorianCalendar gregorianCalendar = (GregorianCalendar) GregorianCalendar.getInstance();
        gregorianCalendar.setTime(now);

        XMLGregorianCalendar calendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar);

        String jsonString = JSON.toJSONString(calendar);
        // success

            

Reported by PMD.

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

Line: 24

                      GregorianCalendar gregorianCalendar = (GregorianCalendar) GregorianCalendar.getInstance();
        gregorianCalendar.setTime(now);

        XMLGregorianCalendar calendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregorianCalendar);

        String jsonString = JSON.toJSONString(calendar);
        // success
        calendar = JSON.parseObject(jsonString, XMLGregorianCalendar.class);


            

Reported by PMD.

Avoid unused local variables such as 'toJSON1'.
Design

Line: 30

                      // success
        calendar = JSON.parseObject(jsonString, XMLGregorianCalendar.class);

        Object toJSON1 = JSON.toJSON(calendar); // debug看到是 Long 类型
        // 所以这里会报错:
        // error: java.lang.ClassCastException: java.lang.Long cannot be cast to com.alibaba.fastjson.JSONObject
        //JSONObject jsonObject = (JSONObject) JSON.toJSON(calendar);
        // 所以 这里肯定会报错, 因为 jsonObject 不是JSONObject类型
        //calendar = jsonObject.toJavaObject(XMLGregorianCalendar.class);

            

Reported by PMD.

Avoid unused local variables such as 'toJSON2'.
Design

Line: 42

                      calendarList.add(calendar);
        calendarList.add(calendar);

        Object toJSON2 = JSON.toJSON(calendarList); // debug 看到是 JSONArray 类型

        // success: 通过 JSONArray.parseArray 方法可以正确转换
        JSONArray jsonArray = (JSONArray) JSON.toJSON(calendarList);
        jsonString = jsonArray.toJSONString();
        List<XMLGregorianCalendar> calendarList1 = JSONArray.parseArray(jsonString, XMLGregorianCalendar.class);

            

Reported by PMD.

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

Line: 46

              
        // success: 通过 JSONArray.parseArray 方法可以正确转换
        JSONArray jsonArray = (JSONArray) JSON.toJSON(calendarList);
        jsonString = jsonArray.toJSONString();
        List<XMLGregorianCalendar> calendarList1 = JSONArray.parseArray(jsonString, XMLGregorianCalendar.class);

        // 通过 jsonArray.toJavaList 无法转换
        // error: com.alibaba.fastjson.JSONException: can not cast to : javax.xml.datatype.XMLGregorianCalendar
        List<XMLGregorianCalendar> calendarList2 = jsonArray.toJavaList(XMLGregorianCalendar.class);

            

Reported by PMD.

Avoid unused local variables such as 'calendarList1'.
Design

Line: 47

                      // success: 通过 JSONArray.parseArray 方法可以正确转换
        JSONArray jsonArray = (JSONArray) JSON.toJSON(calendarList);
        jsonString = jsonArray.toJSONString();
        List<XMLGregorianCalendar> calendarList1 = JSONArray.parseArray(jsonString, XMLGregorianCalendar.class);

        // 通过 jsonArray.toJavaList 无法转换
        // error: com.alibaba.fastjson.JSONException: can not cast to : javax.xml.datatype.XMLGregorianCalendar
        List<XMLGregorianCalendar> calendarList2 = jsonArray.toJavaList(XMLGregorianCalendar.class);
        assertNotNull(calendarList2);

            

Reported by PMD.

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

Line: 51

              
        // 通过 jsonArray.toJavaList 无法转换
        // error: com.alibaba.fastjson.JSONException: can not cast to : javax.xml.datatype.XMLGregorianCalendar
        List<XMLGregorianCalendar> calendarList2 = jsonArray.toJavaList(XMLGregorianCalendar.class);
        assertNotNull(calendarList2);
        assertEquals(3, calendarList2.size());
    }
}

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 52

                      // 通过 jsonArray.toJavaList 无法转换
        // error: com.alibaba.fastjson.JSONException: can not cast to : javax.xml.datatype.XMLGregorianCalendar
        List<XMLGregorianCalendar> calendarList2 = jsonArray.toJavaList(XMLGregorianCalendar.class);
        assertNotNull(calendarList2);
        assertEquals(3, calendarList2.size());
    }
}

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/bug/Bug_for_zhongyin.java
15 issues
System.out.println is used
Design

Line: 21

                      for (char c = '\u0000'; c < '\u0020'; c++) {
            String s = String.valueOf(c) + "entity";
            String jsons = JSON.toJSONString(new VO(s));
            System.out.println(jsons);
            VO v = JSON.parseObject(jsons, VO.class);
            Assert.assertEquals(s, v.getName());
        }
    }


            

Reported by PMD.

System.out.println is used
Design

Line: 31

                      for (char c = '\u0000'; c < '\u0020'; c++) {
            String s = String.valueOf(c) + "map";
            String jsons = JSON.toJSONString(Collections.singletonMap("value", s));
            System.out.println(jsons);

            JSONObject o = JSON.parseObject(jsons);
            Assert.assertEquals(s, o.getString("value"));
        }
    }

            

Reported by PMD.

System.out.println is used
Design

Line: 45

                      Map <String , Object>map = new HashMap<String, Object>();
        map.put("aaa" , result);
        String stringV = JSON.toJSONString(map);
        System.out.println(stringV);
        JSONObject o = JSON.parseObject(stringV);
        System.out.println(o.getString("aaa"));
        
    }
    

            

Reported by PMD.

System.out.println is used
Design

Line: 47

                      String stringV = JSON.toJSONString(map);
        System.out.println(stringV);
        JSONObject o = JSON.parseObject(stringV);
        System.out.println(o.getString("aaa"));
        
    }
    
    private String getHexStr(String hex) throws UnsupportedEncodingException {
        byte []bytes = new byte[hex.length() / 2];

            

Reported by PMD.

System.out.println is used
Design

Line: 58

                          bytes[i] = (byte)Integer.parseInt(v , 16);
        }
        String str = new String(bytes , "UTF-8");
        System.out.println(str);
        return str;
    }

    public static class VO {


            

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

              
public class Bug_for_zhongyin extends TestCase {

    public void test_entity() throws Exception {
        for (char c = '\u0000'; c < '\u0020'; c++) {
            String s = String.valueOf(c) + "entity";
            String jsons = JSON.toJSONString(new VO(s));
            System.out.println(jsons);
            VO v = JSON.parseObject(jsons, VO.class);

            

Reported by PMD.

No need to call String.valueOf to append to a string.
Performance

Line: 19

              
    public void test_entity() throws Exception {
        for (char c = '\u0000'; c < '\u0020'; c++) {
            String s = String.valueOf(c) + "entity";
            String jsons = JSON.toJSONString(new VO(s));
            System.out.println(jsons);
            VO v = JSON.parseObject(jsons, VO.class);
            Assert.assertEquals(s, v.getName());
        }

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 20

                  public void test_entity() throws Exception {
        for (char c = '\u0000'; c < '\u0020'; c++) {
            String s = String.valueOf(c) + "entity";
            String jsons = JSON.toJSONString(new VO(s));
            System.out.println(jsons);
            VO v = JSON.parseObject(jsons, VO.class);
            Assert.assertEquals(s, v.getName());
        }
    }

            

Reported by PMD.

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

Line: 23

                          String jsons = JSON.toJSONString(new VO(s));
            System.out.println(jsons);
            VO v = JSON.parseObject(jsons, VO.class);
            Assert.assertEquals(s, v.getName());
        }
    }

    public void test_map() throws Exception {
        for (char c = '\u0000'; c < '\u0020'; c++) {

            

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

                      }
    }

    public void test_map() throws Exception {
        for (char c = '\u0000'; c < '\u0020'; c++) {
            String s = String.valueOf(c) + "map";
            String jsons = JSON.toJSONString(Collections.singletonMap("value", s));
            System.out.println(jsons);


            

Reported by PMD.

src/test/java/com/alibaba/json/demo/hibernate/LazyLoadingTest.java
15 issues
System.out.println is used
Design

Line: 41

                          Customer customer = em.find(Customer.class, 103);
            // assertFalse(Hibernate.isInitialized(customer.getPayments()));
            String json = JSON.toJSONString(customer);
        System.out.println(json);
            // should not force loading...
            Set<Payment> payments = customer.getPayments();
            /*
            System.out.println("--- JSON ---");
            System.out.println(json);

            

Reported by PMD.

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

Line: 19

              import org.junit.Test;

public class LazyLoadingTest extends TestCase {
    EntityManagerFactory emf;

    protected void setUp() throws Exception {
        emf = Persistence.createEntityManagerFactory("persistenceUnit");
    }


            

Reported by PMD.

JUnit 4 tests that set up tests should use the @Before annotation, JUnit5 tests should use @BeforeEach or @BeforeAll
Design

Line: 21

              public class LazyLoadingTest extends TestCase {
    EntityManagerFactory emf;

    protected void setUp() throws Exception {
        emf = Persistence.createEntityManagerFactory("persistenceUnit");
    }

    protected void tearDown() throws Exception {
        if (emf != null) {

            

Reported by PMD.

JUnit 4 tests that clean up tests should use the @After annotation, JUnit5 tests should use @AfterEach or @AfterAll
Design

Line: 25

                      emf = Persistence.createEntityManagerFactory("persistenceUnit");
    }

    protected void tearDown() throws Exception {
        if (emf != null) {
            emf.close();
        }
    }


            

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

                      }
    }

    public void testGetCustomerJson() throws Exception {

            EntityManager em = emf.createEntityManager();
            
            // false -> no forcing of lazy loading
            //ObjectMapper mapper = mapperWithModule(false);

            

Reported by PMD.

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

Line: 38

                          // false -> no forcing of lazy loading
            //ObjectMapper mapper = mapperWithModule(false);
            
            Customer customer = em.find(Customer.class, 103);
            // assertFalse(Hibernate.isInitialized(customer.getPayments()));
            String json = JSON.toJSONString(customer);
        System.out.println(json);
            // should not force loading...
            Set<Payment> payments = customer.getPayments();

            

Reported by PMD.

Avoid unused local variables such as 'payments'.
Design

Line: 43

                          String json = JSON.toJSONString(customer);
        System.out.println(json);
            // should not force loading...
            Set<Payment> payments = customer.getPayments();
            /*
            System.out.println("--- JSON ---");
            System.out.println(json);
            System.out.println("--- /JSON ---");
            */

            

Reported by PMD.

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

Line: 43

                          String json = JSON.toJSONString(customer);
        System.out.println(json);
            // should not force loading...
            Set<Payment> payments = customer.getPayments();
            /*
            System.out.println("--- JSON ---");
            System.out.println(json);
            System.out.println("--- /JSON ---");
            */

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 52

              
            //assertFalse(Hibernate.isInitialized(payments));
            // TODO: verify
            assertNotNull(json);
            
//            Map<?,?> stuff = mapper.readValue(json, Map.class);
//
//            // "payments" is marked as lazily loaded AND "Include.NON_EMPTY"; should not be serialized
//            if (stuff.containsKey("payments")) {

            

Reported by PMD.

Avoid unused imports such as 'com.fasterxml.jackson.core.JsonProcessingException'
Design

Line: 10

              import javax.persistence.Persistence;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.alibaba.json.demo.hibernate.data.*;

import junit.framework.TestCase;
import org.hibernate.Hibernate;

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/deser/list/ListStringFieldTest_array_big.java
15 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: 16

              import junit.framework.TestCase;

public class ListStringFieldTest_array_big extends TestCase {
    public void test_list() throws Exception {
        Model model = new Model();
        model.values = new ArrayList<String>();
        for (int i = 0; i < 1000; ++i) {
            char[] chars = new char[512];
            Arrays.fill(chars, (char) ('0' + (i % 10))); 

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 20

                      Model model = new Model();
        model.values = new ArrayList<String>();
        for (int i = 0; i < 1000; ++i) {
            char[] chars = new char[512];
            Arrays.fill(chars, (char) ('0' + (i % 10))); 
            model.values.add(new String(chars));
        }
        
        String text = JSON.toJSONString(model, SerializerFeature.BeanToArray);

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 22

                      for (int i = 0; i < 1000; ++i) {
            char[] chars = new char[512];
            Arrays.fill(chars, (char) ('0' + (i % 10))); 
            model.values.add(new String(chars));
        }
        
        String text = JSON.toJSONString(model, SerializerFeature.BeanToArray);
        
        Model model2 = JSON.parseObject(text, Model.class, Feature.SupportArrayToBean);

            

Reported by PMD.

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

Line: 28

                      String text = JSON.toJSONString(model, SerializerFeature.BeanToArray);
        
        Model model2 = JSON.parseObject(text, Model.class, Feature.SupportArrayToBean);
        Assert.assertEquals(model.values.size(), model2.values.size());
        for (int i = 0; i < model.values.size(); ++i) {
            Assert.assertEquals(model.values.get(i), model2.values.get(i));    
        }
    }
    

            

Reported by PMD.

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

Line: 28

                      String text = JSON.toJSONString(model, SerializerFeature.BeanToArray);
        
        Model model2 = JSON.parseObject(text, Model.class, Feature.SupportArrayToBean);
        Assert.assertEquals(model.values.size(), model2.values.size());
        for (int i = 0; i < model.values.size(); ++i) {
            Assert.assertEquals(model.values.get(i), model2.values.get(i));    
        }
    }
    

            

Reported by PMD.

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

Line: 29

                      
        Model model2 = JSON.parseObject(text, Model.class, Feature.SupportArrayToBean);
        Assert.assertEquals(model.values.size(), model2.values.size());
        for (int i = 0; i < model.values.size(); ++i) {
            Assert.assertEquals(model.values.get(i), model2.values.get(i));    
        }
    }
    
    public void test_list_empty() throws Exception {

            

Reported by PMD.

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

Line: 30

                      Model model2 = JSON.parseObject(text, Model.class, Feature.SupportArrayToBean);
        Assert.assertEquals(model.values.size(), model2.values.size());
        for (int i = 0; i < model.values.size(); ++i) {
            Assert.assertEquals(model.values.get(i), model2.values.get(i));    
        }
    }
    
    public void test_list_empty() throws Exception {
        Model model = new Model();

            

Reported by PMD.

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

Line: 30

                      Model model2 = JSON.parseObject(text, Model.class, Feature.SupportArrayToBean);
        Assert.assertEquals(model.values.size(), model2.values.size());
        for (int i = 0; i < model.values.size(); ++i) {
            Assert.assertEquals(model.values.get(i), model2.values.get(i));    
        }
    }
    
    public void test_list_empty() throws Exception {
        Model model = new Model();

            

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

                      }
    }
    
    public void test_list_empty() throws Exception {
        Model model = new Model();
        model.values = new ArrayList<String>();
        
        String text = JSON.toJSONString(model, SerializerFeature.BeanToArray);
        

            

Reported by PMD.

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

Line: 41

                      String text = JSON.toJSONString(model, SerializerFeature.BeanToArray);
        
        Model model2 = JSON.parseObject(text, Model.class, Feature.SupportArrayToBean);
        Assert.assertEquals(model.values.size(), model2.values.size());
        for (int i = 0; i < model.values.size(); ++i) {
            Assert.assertEquals(model.values.get(i), model2.values.get(i));    
        }
    }


            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/deser/list/ArrayListTypeDeserializerTest.java
15 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: 17

              
public class ArrayListTypeDeserializerTest extends TestCase {

    public void test_null_0() throws Exception {
        Assert.assertNull(JSON.parseObject("null", new TypeReference<ArrayList<Integer>>() {
        }));
    }

    public void test_null_1() 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: 22

                      }));
    }

    public void test_null_1() throws Exception {
        Assert.assertNull(JSON.parseObject("null", new TypeReference<Collection<Integer>>() {
        }));
    }

    public void test_null_2() 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: 27

                      }));
    }

    public void test_null_2() throws Exception {
        Assert.assertNull(JSON.parseObject("{\"value\":null}", VO.class).getValue());
    }

    public void test_null_3() throws Exception {
        Assert.assertNull(JSON.parseObject("{\"value\":null}", V1.class).getValue());

            

Reported by PMD.

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

Line: 28

                  }

    public void test_null_2() throws Exception {
        Assert.assertNull(JSON.parseObject("{\"value\":null}", VO.class).getValue());
    }

    public void test_null_3() throws Exception {
        Assert.assertNull(JSON.parseObject("{\"value\":null}", V1.class).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: 31

                      Assert.assertNull(JSON.parseObject("{\"value\":null}", VO.class).getValue());
    }

    public void test_null_3() throws Exception {
        Assert.assertNull(JSON.parseObject("{\"value\":null}", V1.class).getValue());
    }

    public void test_empty() throws Exception {
        Assert.assertEquals(0, JSON.parseObject("[]", new TypeReference<ArrayList<Integer>>() {

            

Reported by PMD.

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

Line: 32

                  }

    public void test_null_3() throws Exception {
        Assert.assertNull(JSON.parseObject("{\"value\":null}", V1.class).getValue());
    }

    public void test_empty() throws Exception {
        Assert.assertEquals(0, JSON.parseObject("[]", new TypeReference<ArrayList<Integer>>() {
        }).size());

            

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

                      Assert.assertNull(JSON.parseObject("{\"value\":null}", V1.class).getValue());
    }

    public void test_empty() throws Exception {
        Assert.assertEquals(0, JSON.parseObject("[]", new TypeReference<ArrayList<Integer>>() {
        }).size());
        Assert.assertEquals(0, JSON.parseObject("[]", new TypeReference<Set<Integer>>() {
        }).size());


            

Reported by PMD.

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

Line: 44

                      Assert.assertEquals(0, JSON.parseObject("[]", new TypeReference<HashSet<Integer>>() {
        }).size());

        Assert.assertEquals(0, JSON.parseObject("{\"value\":[]}", VO.class).getValue().size());
    }

    public static class VO {

        private ArrayList<Integer> value;

            

Reported by PMD.

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

Line: 44

                      Assert.assertEquals(0, JSON.parseObject("[]", new TypeReference<HashSet<Integer>>() {
        }).size());

        Assert.assertEquals(0, JSON.parseObject("{\"value\":[]}", VO.class).getValue().size());
    }

    public static class VO {

        private ArrayList<Integer> value;

            

Reported by PMD.

Avoid using implementation types like 'ArrayList'; use the interface instead
Design

Line: 49

              
    public static class VO {

        private ArrayList<Integer> value;

        public ArrayList<Integer> getValue() {
            return value;
        }


            

Reported by PMD.

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

Line: 12

              import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;

public class AbstractSerializeTest extends TestCase {
    protected void setUp() throws Exception {
        ParserConfig.global.addAccept("com.alibaba.json.bvt.bug.AbstractSerializeTest");

        ObjectDeserializer serializerB = ParserConfig.getGlobalInstance().getDeserializer(B.class);
        ParserConfig.getGlobalInstance().putDeserializer(A.class, serializerB);
    }

            

Reported by PMD.

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

Line: 13

              
public class AbstractSerializeTest extends TestCase {
    protected void setUp() throws Exception {
        ParserConfig.global.addAccept("com.alibaba.json.bvt.bug.AbstractSerializeTest");

        ObjectDeserializer serializerB = ParserConfig.getGlobalInstance().getDeserializer(B.class);
        ParserConfig.getGlobalInstance().putDeserializer(A.class, serializerB);
    }


            

Reported by PMD.

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

Line: 15

                  protected void setUp() throws Exception {
        ParserConfig.global.addAccept("com.alibaba.json.bvt.bug.AbstractSerializeTest");

        ObjectDeserializer serializerB = ParserConfig.getGlobalInstance().getDeserializer(B.class);
        ParserConfig.getGlobalInstance().putDeserializer(A.class, serializerB);
    }

    protected void tearDown() throws Exception {
        ParserConfig.getGlobalInstance().putDeserializer(A.class, null);

            

Reported by PMD.

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

Line: 16

                      ParserConfig.global.addAccept("com.alibaba.json.bvt.bug.AbstractSerializeTest");

        ObjectDeserializer serializerB = ParserConfig.getGlobalInstance().getDeserializer(B.class);
        ParserConfig.getGlobalInstance().putDeserializer(A.class, serializerB);
    }

    protected void tearDown() throws Exception {
        ParserConfig.getGlobalInstance().putDeserializer(A.class, null);
    }

            

Reported by PMD.

JUnit 4 tests that clean up tests should use the @After annotation, JUnit5 tests should use @AfterEach or @AfterAll
Design

Line: 19

                      ParserConfig.getGlobalInstance().putDeserializer(A.class, serializerB);
    }

    protected void tearDown() throws Exception {
        ParserConfig.getGlobalInstance().putDeserializer(A.class, null);
    }

    public void test_mapping_0() throws Exception {
        String text = "{\"@type\":\"com.alibaba.json.bvt.parser.deser.AbstractSerializeTest$A\"}";

            

Reported by PMD.

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

Line: 20

                  }

    protected void tearDown() throws Exception {
        ParserConfig.getGlobalInstance().putDeserializer(A.class, null);
    }

    public void test_mapping_0() throws Exception {
        String text = "{\"@type\":\"com.alibaba.json.bvt.parser.deser.AbstractSerializeTest$A\"}";


            

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

                      ParserConfig.getGlobalInstance().putDeserializer(A.class, null);
    }

    public void test_mapping_0() throws Exception {
        String text = "{\"@type\":\"com.alibaba.json.bvt.parser.deser.AbstractSerializeTest$A\"}";

        B b = (B) JSON.parse(text);
        Assert.assertNotNull(b);
    }

            

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

                      Assert.assertNotNull(b);
    }

    public void test_mapping_1() throws Exception {
        String text = "{\"@type\":\"com.alibaba.json.bvt.parser.deser.AbstractSerializeTest$A\",\"id\":123}";

        B b = (B) JSON.parse(text);
        Assert.assertNotNull(b);
        Assert.assertEquals(123, b.getId());

            

Reported by PMD.

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

Line: 35

              
        B b = (B) JSON.parse(text);
        Assert.assertNotNull(b);
        Assert.assertEquals(123, b.getId());
    }

    public void test_mapping_2() throws Exception {
        String text = "{\"@type\":\"com.alibaba.json.bvt.parser.deser.AbstractSerializeTest$A\",\"id\":234,\"name\":\"abc\"}";


            

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

                      Assert.assertEquals(123, b.getId());
    }

    public void test_mapping_2() throws Exception {
        String text = "{\"@type\":\"com.alibaba.json.bvt.parser.deser.AbstractSerializeTest$A\",\"id\":234,\"name\":\"abc\"}";

        B b = (B) JSON.parse(text);
        Assert.assertNotNull(b);
        Assert.assertEquals(234, b.getId());

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_2300/Issue2357.java
15 issues
System.out.println is used
Design

Line: 15

                      buff.flip();

        String result = JSON.toJSONString(buff);
        System.out.println(result);

        assertEquals("{\"array\":\"AAAAZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=\",\"limit\":4,\"position\":0}", result);

        ByteBuffer buf1 = JSON.parseObject(result, ByteBuffer.class);


            

Reported by PMD.

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

Line: 9

              import java.nio.ByteBuffer;

public class Issue2357 extends TestCase {
    public void test_for_issue() throws Exception {
        ByteBuffer buff = ByteBuffer.allocate(32);
        buff.putInt(100);
        buff.flip();

        String result = JSON.toJSONString(buff);

            

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 java.nio.ByteBuffer;

public class Issue2357 extends TestCase {
    public void test_for_issue() throws Exception {
        ByteBuffer buff = ByteBuffer.allocate(32);
        buff.putInt(100);
        buff.flip();

        String result = JSON.toJSONString(buff);

            

Reported by PMD.

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

Line: 11

              public class Issue2357 extends TestCase {
    public void test_for_issue() throws Exception {
        ByteBuffer buff = ByteBuffer.allocate(32);
        buff.putInt(100);
        buff.flip();

        String result = JSON.toJSONString(buff);
        System.out.println(result);


            

Reported by PMD.

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

Line: 12

                  public void test_for_issue() throws Exception {
        ByteBuffer buff = ByteBuffer.allocate(32);
        buff.putInt(100);
        buff.flip();

        String result = JSON.toJSONString(buff);
        System.out.println(result);

        assertEquals("{\"array\":\"AAAAZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=\",\"limit\":4,\"position\":0}", result);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 17

                      String result = JSON.toJSONString(buff);
        System.out.println(result);

        assertEquals("{\"array\":\"AAAAZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=\",\"limit\":4,\"position\":0}", result);

        ByteBuffer buf1 = JSON.parseObject(result, ByteBuffer.class);

        assertEquals(buff.capacity(), buf1.capacity());
        assertEquals(buff.limit(), buf1.limit());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 21

              
        ByteBuffer buf1 = JSON.parseObject(result, ByteBuffer.class);

        assertEquals(buff.capacity(), buf1.capacity());
        assertEquals(buff.limit(), buf1.limit());
        assertEquals(buff.position(), buf1.position());

    }
}

            

Reported by PMD.

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

Line: 21

              
        ByteBuffer buf1 = JSON.parseObject(result, ByteBuffer.class);

        assertEquals(buff.capacity(), buf1.capacity());
        assertEquals(buff.limit(), buf1.limit());
        assertEquals(buff.position(), buf1.position());

    }
}

            

Reported by PMD.

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

Line: 21

              
        ByteBuffer buf1 = JSON.parseObject(result, ByteBuffer.class);

        assertEquals(buff.capacity(), buf1.capacity());
        assertEquals(buff.limit(), buf1.limit());
        assertEquals(buff.position(), buf1.position());

    }
}

            

Reported by PMD.

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

Line: 22

                      ByteBuffer buf1 = JSON.parseObject(result, ByteBuffer.class);

        assertEquals(buff.capacity(), buf1.capacity());
        assertEquals(buff.limit(), buf1.limit());
        assertEquals(buff.position(), buf1.position());

    }
}

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/autoType/AutoTypeTest0.java
15 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 10/02/2017.
 */
public class AutoTypeTest0 extends TestCase {
    public void test_0() throws Exception {
        String text = "{\"@type\":\"com.alibaba.json.bvt.parser.autoType.AutoTypeTest0$Model\",\"id\":123}";
        Model model = JSON.parseObject(text, Model.class);
        assertEquals(123, model.id);

        Model model2 = (Model) JSON.parse(text);

            

Reported by PMD.

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

Line: 10

               * Created by wenshao on 10/02/2017.
 */
public class AutoTypeTest0 extends TestCase {
    public void test_0() throws Exception {
        String text = "{\"@type\":\"com.alibaba.json.bvt.parser.autoType.AutoTypeTest0$Model\",\"id\":123}";
        Model model = JSON.parseObject(text, Model.class);
        assertEquals(123, model.id);

        Model model2 = (Model) JSON.parse(text);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 13

                  public void test_0() throws Exception {
        String text = "{\"@type\":\"com.alibaba.json.bvt.parser.autoType.AutoTypeTest0$Model\",\"id\":123}";
        Model model = JSON.parseObject(text, Model.class);
        assertEquals(123, model.id);

        Model model2 = (Model) JSON.parse(text);
        assertEquals(123, model2.id);
    }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 16

                      assertEquals(123, model.id);

        Model model2 = (Model) JSON.parse(text);
        assertEquals(123, model2.id);
    }

    public void test_nested() {
        String text = "{\"@type\":\"com.alibaba.json.bvt.parser.autoType.AutoTypeTest0$ModelNested\",\"id\":123, \"nested\":{\"@type\":\"com.alibaba.json.bvt.parser.autoType.AutoTypeTest0$ModelNested\",\"id\":456, \"nested\":null}}";


            

Reported by PMD.

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

Line: 19

                      assertEquals(123, model2.id);
    }

    public void test_nested() {
        String text = "{\"@type\":\"com.alibaba.json.bvt.parser.autoType.AutoTypeTest0$ModelNested\",\"id\":123, \"nested\":{\"@type\":\"com.alibaba.json.bvt.parser.autoType.AutoTypeTest0$ModelNested\",\"id\":456, \"nested\":null}}";

        ModelNested model = JSON.parseObject(text, ModelNested.class);
        assertEquals(123, model.id);
        ModelNested nested1 = model.nested;

            

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

                      assertEquals(123, model2.id);
    }

    public void test_nested() {
        String text = "{\"@type\":\"com.alibaba.json.bvt.parser.autoType.AutoTypeTest0$ModelNested\",\"id\":123, \"nested\":{\"@type\":\"com.alibaba.json.bvt.parser.autoType.AutoTypeTest0$ModelNested\",\"id\":456, \"nested\":null}}";

        ModelNested model = JSON.parseObject(text, ModelNested.class);
        assertEquals(123, model.id);
        ModelNested nested1 = model.nested;

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 23

                      String text = "{\"@type\":\"com.alibaba.json.bvt.parser.autoType.AutoTypeTest0$ModelNested\",\"id\":123, \"nested\":{\"@type\":\"com.alibaba.json.bvt.parser.autoType.AutoTypeTest0$ModelNested\",\"id\":456, \"nested\":null}}";

        ModelNested model = JSON.parseObject(text, ModelNested.class);
        assertEquals(123, model.id);
        ModelNested nested1 = model.nested;
        assertEquals(456, nested1.id);
        assertNull(nested1.nested);

        ModelNested model2 = (ModelNested) JSON.parse(text);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 25

                      ModelNested model = JSON.parseObject(text, ModelNested.class);
        assertEquals(123, model.id);
        ModelNested nested1 = model.nested;
        assertEquals(456, nested1.id);
        assertNull(nested1.nested);

        ModelNested model2 = (ModelNested) JSON.parse(text);
        assertEquals(123, model2.id);
        ModelNested nested2 = model2.nested;

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 26

                      assertEquals(123, model.id);
        ModelNested nested1 = model.nested;
        assertEquals(456, nested1.id);
        assertNull(nested1.nested);

        ModelNested model2 = (ModelNested) JSON.parse(text);
        assertEquals(123, model2.id);
        ModelNested nested2 = model2.nested;
        assertEquals(456, nested2.id);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 29

                      assertNull(nested1.nested);

        ModelNested model2 = (ModelNested) JSON.parse(text);
        assertEquals(123, model2.id);
        ModelNested nested2 = model2.nested;
        assertEquals(456, nested2.id);
        assertNull(nested2.nested);
    }


            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/bug/Bug_for_wangran2.java
15 issues
System.out.println is used
Design

Line: 47

                      }

        public void setSecond(Child second) {
            System.out.println("setSecond");
            this.second = second;
        }

        public Child getFirst() {
            return first;

            

Reported by PMD.

System.out.println is used
Design

Line: 56

                      }

        public void setFirst(Child first) {
            System.out.println("setFirst");
            this.first = first;
        }

        public List<Child> getChildren() {
            return children;

            

Reported by PMD.

System.out.println is used
Design

Line: 65

                      }

        public void setChildren(List<Child> children) {
            System.out.println("setChildren");
            this.children = children;
        }

        public int getId() {
            return id;

            

Reported by PMD.

System.out.println is used
Design

Line: 102

                      }

        public void setRoot(Root root) {
            System.out.println("setRoot");
            this.root = root;
        }

        public int getId() {
            return id;

            

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 Bug_for_wangran2 extends TestCase {

    public void test_for_wangran() throws Exception {
        String text = "{" + //
                      "\"first\":{\"id\":1001}," + //
                      "\"second\":{\"id\":1002,\"root\":{\"$ref\":\"$\"}}," + //
                      "\"id\":23," + //
                      "\"name\":\"xxx\"," + //

            

Reported by PMD.

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

Line: 22

                                    "\"children\":[{\"root\":{\"$ref\":\"$\"}},{\"$ref\":\"$.second\"}]" + //
                      "}";
        Root root = JSON.parseObject(text, Root.class);
        Assert.assertEquals(23, root.getId());
        Assert.assertEquals("xxx", root.getName());
        Assert.assertTrue(root == root.getChildren().get(0).getRoot());
        Assert.assertTrue(root == root.getChildren().get(1).getRoot());
    }


            

Reported by PMD.

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

Line: 23

                                    "}";
        Root root = JSON.parseObject(text, Root.class);
        Assert.assertEquals(23, root.getId());
        Assert.assertEquals("xxx", root.getName());
        Assert.assertTrue(root == root.getChildren().get(0).getRoot());
        Assert.assertTrue(root == root.getChildren().get(1).getRoot());
    }

    public static class Root {

            

Reported by PMD.

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

Line: 24

                      Root root = JSON.parseObject(text, Root.class);
        Assert.assertEquals(23, root.getId());
        Assert.assertEquals("xxx", root.getName());
        Assert.assertTrue(root == root.getChildren().get(0).getRoot());
        Assert.assertTrue(root == root.getChildren().get(1).getRoot());
    }

    public static class Root {


            

Reported by PMD.

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

Line: 24

                      Root root = JSON.parseObject(text, Root.class);
        Assert.assertEquals(23, root.getId());
        Assert.assertEquals("xxx", root.getName());
        Assert.assertTrue(root == root.getChildren().get(0).getRoot());
        Assert.assertTrue(root == root.getChildren().get(1).getRoot());
    }

    public static class Root {


            

Reported by PMD.

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

Line: 24

                      Root root = JSON.parseObject(text, Root.class);
        Assert.assertEquals(23, root.getId());
        Assert.assertEquals("xxx", root.getName());
        Assert.assertTrue(root == root.getChildren().get(0).getRoot());
        Assert.assertTrue(root == root.getChildren().get(1).getRoot());
    }

    public static class Root {


            

Reported by PMD.