The following issues were found

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

Line: 13

               * Created by wenshao on 11/02/2017.
 */
public class Issue1017 extends TestCase {
    public void test_for_issue() throws Exception {
        String json = "{\"pictureList\":[\"http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000\",\"http://common.cnblogs.com/images/icon_weibo_24.png\"]}";

        User user = JSON.parseObject(json, User.class);
        assertNotNull(user.pictureList);
        assertEquals(2, user.pictureList.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: 13

               * Created by wenshao on 11/02/2017.
 */
public class Issue1017 extends TestCase {
    public void test_for_issue() throws Exception {
        String json = "{\"pictureList\":[\"http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000\",\"http://common.cnblogs.com/images/icon_weibo_24.png\"]}";

        User user = JSON.parseObject(json, User.class);
        assertNotNull(user.pictureList);
        assertEquals(2, user.pictureList.size());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 17

                      String json = "{\"pictureList\":[\"http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000\",\"http://common.cnblogs.com/images/icon_weibo_24.png\"]}";

        User user = JSON.parseObject(json, User.class);
        assertNotNull(user.pictureList);
        assertEquals(2, user.pictureList.size());
        assertEquals("http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000", user.pictureList.get(0));
        assertEquals("http://common.cnblogs.com/images/icon_weibo_24.png", user.pictureList.get(1));
    }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 18

              
        User user = JSON.parseObject(json, User.class);
        assertNotNull(user.pictureList);
        assertEquals(2, user.pictureList.size());
        assertEquals("http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000", user.pictureList.get(0));
        assertEquals("http://common.cnblogs.com/images/icon_weibo_24.png", user.pictureList.get(1));
    }

    public static class User implements Serializable {

            

Reported by PMD.

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

Line: 18

              
        User user = JSON.parseObject(json, User.class);
        assertNotNull(user.pictureList);
        assertEquals(2, user.pictureList.size());
        assertEquals("http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000", user.pictureList.get(0));
        assertEquals("http://common.cnblogs.com/images/icon_weibo_24.png", user.pictureList.get(1));
    }

    public static class User implements Serializable {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 19

                      User user = JSON.parseObject(json, User.class);
        assertNotNull(user.pictureList);
        assertEquals(2, user.pictureList.size());
        assertEquals("http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000", user.pictureList.get(0));
        assertEquals("http://common.cnblogs.com/images/icon_weibo_24.png", user.pictureList.get(1));
    }

    public static class User implements Serializable {
        private List<String> pictureList;

            

Reported by PMD.

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

Line: 19

                      User user = JSON.parseObject(json, User.class);
        assertNotNull(user.pictureList);
        assertEquals(2, user.pictureList.size());
        assertEquals("http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000", user.pictureList.get(0));
        assertEquals("http://common.cnblogs.com/images/icon_weibo_24.png", user.pictureList.get(1));
    }

    public static class User implements Serializable {
        private List<String> pictureList;

            

Reported by PMD.

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

Line: 20

                      assertNotNull(user.pictureList);
        assertEquals(2, user.pictureList.size());
        assertEquals("http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000", user.pictureList.get(0));
        assertEquals("http://common.cnblogs.com/images/icon_weibo_24.png", user.pictureList.get(1));
    }

    public static class User implements Serializable {
        private List<String> pictureList;
        public List<String> getPictureList() {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 20

                      assertNotNull(user.pictureList);
        assertEquals(2, user.pictureList.size());
        assertEquals("http://static.oschina.net/uploads/user/1218/2437072_100.jpg?t=1461076033000", user.pictureList.get(0));
        assertEquals("http://common.cnblogs.com/images/icon_weibo_24.png", user.pictureList.get(1));
    }

    public static class User implements Serializable {
        private List<String> pictureList;
        public List<String> getPictureList() {

            

Reported by PMD.

Classes implementing Serializable should set a serialVersionUID
Error

Line: 23

                      assertEquals("http://common.cnblogs.com/images/icon_weibo_24.png", user.pictureList.get(1));
    }

    public static class User implements Serializable {
        private List<String> pictureList;
        public List<String> getPictureList() {
            return pictureList;
        }
        public User setPictureList(List<String> pictureList) {

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/creator/JSONCreatorTest_double_obj.java
10 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: 14

              
public class JSONCreatorTest_double_obj extends TestCase {

    public void test_create() throws Exception {
        Entity entity = new Entity(123.45D, "菜姐");
        String text = JSON.toJSONString(entity);

        Entity entity2 = JSON.parseObject(text, Entity.class);
        Assert.assertTrue(entity.getId().doubleValue() == entity2.getId().doubleValue());

            

Reported by PMD.

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

Line: 19

                      String text = JSON.toJSONString(entity);

        Entity entity2 = JSON.parseObject(text, Entity.class);
        Assert.assertTrue(entity.getId().doubleValue() == entity2.getId().doubleValue());
        Assert.assertEquals(entity.getName(), entity2.getName());
    }

    public void test_create_2() throws Exception {
        Entity entity = new Entity(123.45D, "菜姐");

            

Reported by PMD.

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

Line: 19

                      String text = JSON.toJSONString(entity);

        Entity entity2 = JSON.parseObject(text, Entity.class);
        Assert.assertTrue(entity.getId().doubleValue() == entity2.getId().doubleValue());
        Assert.assertEquals(entity.getName(), entity2.getName());
    }

    public void test_create_2() throws Exception {
        Entity entity = new Entity(123.45D, "菜姐");

            

Reported by PMD.

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

Line: 19

                      String text = JSON.toJSONString(entity);

        Entity entity2 = JSON.parseObject(text, Entity.class);
        Assert.assertTrue(entity.getId().doubleValue() == entity2.getId().doubleValue());
        Assert.assertEquals(entity.getName(), entity2.getName());
    }

    public void test_create_2() throws Exception {
        Entity entity = new Entity(123.45D, "菜姐");

            

Reported by PMD.

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

Line: 20

              
        Entity entity2 = JSON.parseObject(text, Entity.class);
        Assert.assertTrue(entity.getId().doubleValue() == entity2.getId().doubleValue());
        Assert.assertEquals(entity.getName(), entity2.getName());
    }

    public void test_create_2() throws Exception {
        Entity entity = new Entity(123.45D, "菜姐");
        String text = JSON.toJSONString(entity);

            

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(entity.getName(), entity2.getName());
    }

    public void test_create_2() throws Exception {
        Entity entity = new Entity(123.45D, "菜姐");
        String text = JSON.toJSONString(entity);

        ParserConfig config = new ParserConfig();


            

Reported by PMD.

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

Line: 30

                      ParserConfig config = new ParserConfig();

        Entity entity2 = JSON.parseObject(text, Entity.class, config, 0);
        Assert.assertTrue(entity.getId().doubleValue() == entity2.getId().doubleValue());
        Assert.assertEquals(entity.getName(), entity2.getName());
    }

    public static class Entity {


            

Reported by PMD.

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

Line: 30

                      ParserConfig config = new ParserConfig();

        Entity entity2 = JSON.parseObject(text, Entity.class, config, 0);
        Assert.assertTrue(entity.getId().doubleValue() == entity2.getId().doubleValue());
        Assert.assertEquals(entity.getName(), entity2.getName());
    }

    public static class Entity {


            

Reported by PMD.

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

Line: 30

                      ParserConfig config = new ParserConfig();

        Entity entity2 = JSON.parseObject(text, Entity.class, config, 0);
        Assert.assertTrue(entity.getId().doubleValue() == entity2.getId().doubleValue());
        Assert.assertEquals(entity.getName(), entity2.getName());
    }

    public static class Entity {


            

Reported by PMD.

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

Line: 31

              
        Entity entity2 = JSON.parseObject(text, Entity.class, config, 0);
        Assert.assertTrue(entity.getId().doubleValue() == entity2.getId().doubleValue());
        Assert.assertEquals(entity.getName(), entity2.getName());
    }

    public static class Entity {

        private final Double  id;

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/writeClassName/MapTest.java
10 issues
System.out.println is used
Design

Line: 25

                      
        String text = JSON.toJSONString(vo, SerializerFeature.WriteClassName);
        
        System.out.println(text);
        
        VO vo2 = (VO) JSON.parse(text);
        
        Assert.assertEquals(vo.getValue(), vo2.getValue());
    }

            

Reported by PMD.

System.out.println is used
Design

Line: 39

                      
        String text = JSON.toJSONString(vo, SerializerFeature.WriteClassName);
        
        System.out.println(text);
        
        VO vo2 = (VO) JSON.parse(text);
        
        Assert.assertEquals(vo.getValue(), vo2.getValue());
    }

            

Reported by PMD.

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

Line: 15

              import com.alibaba.fastjson.serializer.SerializerFeature;

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

    public void test_map() throws Exception {
        VO vo = new VO();

            

Reported by PMD.

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

Line: 16

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

    public void test_map() throws Exception {
        VO vo = new VO();
        vo.getValue().put("1", "AA");

            

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

                      ParserConfig.global.addAccept("com.alibaba.json.bvt.writeClassName.MapTest");
    }

    public void test_map() throws Exception {
        VO vo = new VO();
        vo.getValue().put("1", "AA");
        
        String text = JSON.toJSONString(vo, SerializerFeature.WriteClassName);
        

            

Reported by PMD.

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

Line: 21

              
    public void test_map() throws Exception {
        VO vo = new VO();
        vo.getValue().put("1", "AA");
        
        String text = JSON.toJSONString(vo, SerializerFeature.WriteClassName);
        
        System.out.println(text);
        

            

Reported by PMD.

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

Line: 29

                      
        VO vo2 = (VO) JSON.parse(text);
        
        Assert.assertEquals(vo.getValue(), vo2.getValue());
    }
    
    public void test_map_2() throws Exception {
        VO vo = new VO();
        vo.setValue(new TreeMap<String, Object>());

            

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

                      Assert.assertEquals(vo.getValue(), vo2.getValue());
    }
    
    public void test_map_2() throws Exception {
        VO vo = new VO();
        vo.setValue(new TreeMap<String, Object>());
        vo.getValue().put("1", "AA");
        
        String text = JSON.toJSONString(vo, SerializerFeature.WriteClassName);

            

Reported by PMD.

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

Line: 35

                  public void test_map_2() throws Exception {
        VO vo = new VO();
        vo.setValue(new TreeMap<String, Object>());
        vo.getValue().put("1", "AA");
        
        String text = JSON.toJSONString(vo, SerializerFeature.WriteClassName);
        
        System.out.println(text);
        

            

Reported by PMD.

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

Line: 43

                      
        VO vo2 = (VO) JSON.parse(text);
        
        Assert.assertEquals(vo.getValue(), vo2.getValue());
    }

    private static class VO {

        private Map<String, Object> value = new HashMap<String, Object>();

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/AETest.java
10 issues
JUnit tests should include assert() or fail()
Design

Line: 42

                          "    ]\n" +
            "}";

    public void test_for_ae() throws Exception {
        ParserConfig.getGlobalInstance().putDeserializer(Area.class, new ObjectDeserializer() {
            public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
                JSONObject jsonObject = (JSONObject) parser.parse();
                String areaType;


            

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

                          "    ]\n" +
            "}";

    public void test_for_ae() throws Exception {
        ParserConfig.getGlobalInstance().putDeserializer(Area.class, new ObjectDeserializer() {
            public <T> T deserialze(DefaultJSONParser parser, Type type, Object fieldName) {
                JSONObject jsonObject = (JSONObject) parser.parse();
                String areaType;


            

Reported by PMD.

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

Line: 48

                              JSONObject jsonObject = (JSONObject) parser.parse();
                String areaType;

                if (jsonObject.get("type") instanceof String) {
                    areaType = (String) jsonObject.get("type");
                } else {
                    return null;
                }
                if (Area.TYPE_FLOOR.equals(areaType)) {

            

Reported by PMD.

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

Line: 53

                              } else {
                    return null;
                }
                if (Area.TYPE_FLOOR.equals(areaType)) {
                     return (T) JSON.toJavaObject(jsonObject, Floor.class);
                } else if (Area.TYPE_ITEM.equals(areaType)) {
                    return (T) JSON.toJavaObject(jsonObject, Item.class);
                }


            

Reported by PMD.

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

Line: 55

                              }
                if (Area.TYPE_FLOOR.equals(areaType)) {
                     return (T) JSON.toJavaObject(jsonObject, Floor.class);
                } else if (Area.TYPE_ITEM.equals(areaType)) {
                    return (T) JSON.toJavaObject(jsonObject, Item.class);
                }

                return null;
            }

            

Reported by PMD.

Avoid unused local variables such as 'item'.
Design

Line: 70

              
        Data data = JSON.parseObject(jsonData, Data.class);

        Item item = (Item) ((Floor)(data.areaList.get(0))).children.get(0);
    }
}

            

Reported by PMD.

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

Line: 70

              
        Data data = JSON.parseObject(jsonData, Data.class);

        Item item = (Item) ((Floor)(data.areaList.get(0))).children.get(0);
    }
}

            

Reported by PMD.

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

Line: 9

              import com.alibaba.fastjson.parser.JSONToken;
import com.alibaba.fastjson.parser.ParserConfig;
import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.json.bvtVO.ae.*;
import junit.framework.TestCase;

import java.lang.reflect.Type;
import java.util.Arrays;

            

Reported by PMD.

Avoid unused imports such as 'com.alibaba.json.bvtVO.ae'
Design

Line: 10

              import com.alibaba.fastjson.parser.ParserConfig;
import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.json.bvtVO.ae.*;
import junit.framework.TestCase;

import java.lang.reflect.Type;
import java.util.Arrays;


            

Reported by PMD.

Avoid unused imports such as 'java.util.Arrays'
Design

Line: 14

              import junit.framework.TestCase;

import java.lang.reflect.Type;
import java.util.Arrays;

/**
 * Created by wenshao on 08/05/2017.
 */
public class AETest extends TestCase {

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_2300/Issue2358.java
10 issues
Unit tests should not contain more than 1 assert(s).
Design

Line: 11

              
public class Issue2358 extends TestCase {

    public void test_for_issue() throws Exception {
        String str = "[{\n" +
                "  \"test1\":\"1\",\n" +
                "  \"test2\":\"2\"\n" +
                "},\n" +
                " {\n" +

            

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

              
public class Issue2358 extends TestCase {

    public void test_for_issue() throws Exception {
        String str = "[{\n" +
                "  \"test1\":\"1\",\n" +
                "  \"test2\":\"2\"\n" +
                "},\n" +
                " {\n" +

            

Reported by PMD.

Avoid unused local variables such as 'testJsons'.
Design

Line: 23

              
        Exception error = null;
        try {
            List<TestJson2> testJsons = JSONObject.parseArray(str, TestJson2.class);
        } catch (JSONException ex) {
            error = ex;
        }
        assertNotNull(error);
        assertEquals("can't create non-static inner class instance.", error.getMessage());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 27

                      } catch (JSONException ex) {
            error = ex;
        }
        assertNotNull(error);
        assertEquals("can't create non-static inner class instance.", error.getMessage());
    }

    class TestJson {


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 28

                          error = ex;
        }
        assertNotNull(error);
        assertEquals("can't create non-static inner class instance.", error.getMessage());
    }

    class TestJson {

        private String test1;

            

Reported by PMD.

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

Line: 28

                          error = ex;
        }
        assertNotNull(error);
        assertEquals("can't create non-static inner class instance.", error.getMessage());
    }

    class TestJson {

        private String test1;

            

Reported by PMD.

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

Line: 31

                      assertEquals("can't create non-static inner class instance.", error.getMessage());
    }

    class TestJson {

        private String test1;
        private String test2;

        public String getTest1() {

            

Reported by PMD.

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

Line: 55

              
    }

    class TestJson2 {
        private String test1;
        private String test2;

        public String getTest1() {
            return test1;

            

Reported by PMD.

Found 'DD'-anomaly for variable 'error' (lines '21'-'25').
Error

Line: 21

                              "   \"test2\":\"2\"\n" +
                " }]";

        Exception error = null;
        try {
            List<TestJson2> testJsons = JSONObject.parseArray(str, TestJson2.class);
        } catch (JSONException ex) {
            error = ex;
        }

            

Reported by PMD.

Found 'DU'-anomaly for variable 'testJsons' (lines '23'-'29').
Error

Line: 23

              
        Exception error = null;
        try {
            List<TestJson2> testJsons = JSONObject.parseArray(str, TestJson2.class);
        } catch (JSONException ex) {
            error = ex;
        }
        assertNotNull(error);
        assertEquals("can't create non-static inner class instance.", error.getMessage());

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/mixins/MixinSerForFieldsTest.java
10 issues
No abstract method which means that the keyword is most likely used to prevent instantiation. Use a private or protected constructor instead.
Design

Line: 20

                      }
    }

    abstract class MixIn {
        @JSONField(serialize = false)
        public String a;
        @JSONField(name = "banana")
        public String b;
    }

            

Reported by PMD.

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

Line: 11

              
public class MixinSerForFieldsTest extends TestCase {
    static class BeanClass {
        public String a;
        public String b;

        public BeanClass(String a, String b) {
            this.a = a;
            this.b = b;

            

Reported by PMD.

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

Line: 12

              public class MixinSerForFieldsTest extends TestCase {
    static class BeanClass {
        public String a;
        public String b;

        public BeanClass(String a, String b) {
            this.a = a;
            this.b = b;
        }

            

Reported by PMD.

This abstract class does not have any abstract methods
Design

Line: 20

                      }
    }

    abstract class MixIn {
        @JSONField(serialize = false)
        public String a;
        @JSONField(name = "banana")
        public String b;
    }

            

Reported by PMD.

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

Line: 27

                      public String b;
    }

    public void test() throws Exception{
        BeanClass bean = new BeanClass("1", "2");

        JSON.addMixInAnnotations(BeanClass.class, MixIn.class);
        String jsonString = JSON.toJSONString(bean);
        JSONObject result = JSON.parseObject(jsonString);

            

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 String b;
    }

    public void test() throws Exception{
        BeanClass bean = new BeanClass("1", "2");

        JSON.addMixInAnnotations(BeanClass.class, MixIn.class);
        String jsonString = JSON.toJSONString(bean);
        JSONObject result = JSON.parseObject(jsonString);

            

Reported by PMD.

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

Line: 33

                      JSON.addMixInAnnotations(BeanClass.class, MixIn.class);
        String jsonString = JSON.toJSONString(bean);
        JSONObject result = JSON.parseObject(jsonString);
        assertEquals(1, result.size());
        assertEquals("2", result.get("banana"));
        JSON.removeMixInAnnotations(BeanClass.class);
    }
}

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 33

                      JSON.addMixInAnnotations(BeanClass.class, MixIn.class);
        String jsonString = JSON.toJSONString(bean);
        JSONObject result = JSON.parseObject(jsonString);
        assertEquals(1, result.size());
        assertEquals("2", result.get("banana"));
        JSON.removeMixInAnnotations(BeanClass.class);
    }
}

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 34

                      String jsonString = JSON.toJSONString(bean);
        JSONObject result = JSON.parseObject(jsonString);
        assertEquals(1, result.size());
        assertEquals("2", result.get("banana"));
        JSON.removeMixInAnnotations(BeanClass.class);
    }
}

            

Reported by PMD.

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

Line: 34

                      String jsonString = JSON.toJSONString(bean);
        JSONObject result = JSON.parseObject(jsonString);
        assertEquals(1, result.size());
        assertEquals("2", result.get("banana"));
        JSON.removeMixInAnnotations(BeanClass.class);
    }
}

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/creator/JSONCreatorTest_float_obj.java
10 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: 14

              
public class JSONCreatorTest_float_obj extends TestCase {

    public void test_create() throws Exception {
        Entity entity = new Entity(123.45F, "菜姐");
        String text = JSON.toJSONString(entity);

        Entity entity2 = JSON.parseObject(text, Entity.class);
        Assert.assertTrue(entity.getId().floatValue() == entity2.getId().floatValue());

            

Reported by PMD.

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

Line: 19

                      String text = JSON.toJSONString(entity);

        Entity entity2 = JSON.parseObject(text, Entity.class);
        Assert.assertTrue(entity.getId().floatValue() == entity2.getId().floatValue());
        Assert.assertEquals(entity.getName(), entity2.getName());
    }

    public void test_create_2() throws Exception {
        Entity entity = new Entity(123.45F, "菜姐");

            

Reported by PMD.

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

Line: 19

                      String text = JSON.toJSONString(entity);

        Entity entity2 = JSON.parseObject(text, Entity.class);
        Assert.assertTrue(entity.getId().floatValue() == entity2.getId().floatValue());
        Assert.assertEquals(entity.getName(), entity2.getName());
    }

    public void test_create_2() throws Exception {
        Entity entity = new Entity(123.45F, "菜姐");

            

Reported by PMD.

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

Line: 19

                      String text = JSON.toJSONString(entity);

        Entity entity2 = JSON.parseObject(text, Entity.class);
        Assert.assertTrue(entity.getId().floatValue() == entity2.getId().floatValue());
        Assert.assertEquals(entity.getName(), entity2.getName());
    }

    public void test_create_2() throws Exception {
        Entity entity = new Entity(123.45F, "菜姐");

            

Reported by PMD.

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

Line: 20

              
        Entity entity2 = JSON.parseObject(text, Entity.class);
        Assert.assertTrue(entity.getId().floatValue() == entity2.getId().floatValue());
        Assert.assertEquals(entity.getName(), entity2.getName());
    }

    public void test_create_2() throws Exception {
        Entity entity = new Entity(123.45F, "菜姐");
        String text = JSON.toJSONString(entity);

            

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(entity.getName(), entity2.getName());
    }

    public void test_create_2() throws Exception {
        Entity entity = new Entity(123.45F, "菜姐");
        String text = JSON.toJSONString(entity);

        ParserConfig config = new ParserConfig();


            

Reported by PMD.

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

Line: 30

                      ParserConfig config = new ParserConfig();

        Entity entity2 = JSON.parseObject(text, Entity.class, config, 0);
        Assert.assertTrue(entity.getId().floatValue() == entity2.getId().floatValue());
        Assert.assertEquals(entity.getName(), entity2.getName());
    }

    public static class Entity {


            

Reported by PMD.

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

Line: 30

                      ParserConfig config = new ParserConfig();

        Entity entity2 = JSON.parseObject(text, Entity.class, config, 0);
        Assert.assertTrue(entity.getId().floatValue() == entity2.getId().floatValue());
        Assert.assertEquals(entity.getName(), entity2.getName());
    }

    public static class Entity {


            

Reported by PMD.

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

Line: 30

                      ParserConfig config = new ParserConfig();

        Entity entity2 = JSON.parseObject(text, Entity.class, config, 0);
        Assert.assertTrue(entity.getId().floatValue() == entity2.getId().floatValue());
        Assert.assertEquals(entity.getName(), entity2.getName());
    }

    public static class Entity {


            

Reported by PMD.

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

Line: 31

              
        Entity entity2 = JSON.parseObject(text, Entity.class, config, 0);
        Assert.assertTrue(entity.getId().floatValue() == entity2.getId().floatValue());
        Assert.assertEquals(entity.getName(), entity2.getName());
    }

    public static class Entity {

        private final Float  id;

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/serializer/SpecialTest.java
10 issues
System.out.println is used
Design

Line: 16

                              count++;
            }
        }
        System.out.println(count);
    }
    
    final static long flags;
    static {
        long val = 0L;

            

Reported by PMD.

All methods are static. Consider using a utility class instead. Alternatively, you could add a private constructor or make the class abstract to silence this warning.
Design

Line: 5

              
import com.alibaba.fastjson.serializer.SerializerFeature;

public class SpecialTest {
    
    public static void main(String[] args) throws Exception {
        
        int count = 0;
        for (int i = 0; i < 1000; ++i) {

            

Reported by PMD.

A method/constructor should not explicitly throw java.lang.Exception
Design

Line: 7

              
public class SpecialTest {
    
    public static void main(String[] args) throws Exception {
        
        int count = 0;
        for (int i = 0; i < 1000; ++i) {
            char ch = (char) i;
            if(isSpecial(ch)) {

            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 28

                  }
    
    static boolean isSpecial(char ch) {
        if (ch <= 31) {
            return true;
        }
        
        if (ch > '\\') { // 92
            return false;

            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 32

                          return true;
        }
        
        if (ch > '\\') { // 92
            return false;
        }
        
        return ((1L << (ch - 31)) & flags) != 0;
    }

            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 44

                      // return false;
        // }
        
        if (ch == ' ') { // 32
            return false;
        }

        if (ch == '/') { // 47
            return SerializerFeature.isEnabled(features, SerializerFeature.WriteSlashAsSpecial);

            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 48

                          return false;
        }

        if (ch == '/') { // 47
            return SerializerFeature.isEnabled(features, SerializerFeature.WriteSlashAsSpecial);
        }

        if (ch > '#' // 35
            && ch != '\\' // 92

            

Reported by PMD.

Avoid unnecessary if..then..else statements when returning booleans
Design

Line: 58

                          return false;
        }

        if (ch <= 0x1F // 31
                || ch == '\\' // 92
                || ch == '"' // 34
                ) {
            return true;
        }

            

Reported by PMD.

Found 'DD'-anomaly for variable 'count' (lines '9'-'13').
Error

Line: 9

                  
    public static void main(String[] args) throws Exception {
        
        int count = 0;
        for (int i = 0; i < 1000; ++i) {
            char ch = (char) i;
            if(isSpecial(ch)) {
                count++;
            }

            

Reported by PMD.

Found 'DD'-anomaly for variable 'count' (lines '13'-'13').
Error

Line: 13

                      for (int i = 0; i < 1000; ++i) {
            char ch = (char) i;
            if(isSpecial(ch)) {
                count++;
            }
        }
        System.out.println(count);
    }
    

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_2300/Issue2343.java
10 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

              import junit.framework.TestCase;

public class Issue2343 extends TestCase {
    public void test_for_issue() throws Exception {
        A a = new A();
        a.f1 = 101;
        a.f2 = 102;
        a.f3 = 103;


            

Reported by PMD.

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

Line: 9

              import junit.framework.TestCase;

public class Issue2343 extends TestCase {
    public void test_for_issue() throws Exception {
        A a = new A();
        a.f1 = 101;
        a.f2 = 102;
        a.f3 = 103;


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 16

                      a.f3 = 103;

        String str = JSON.toJSONString(a);
        assertEquals("{\"f2\":102,\"f1\":101,\"f3\":103}", str);

        JSONObject object = JSON.parseObject(str);
        A a1 = object.toJavaObject(A.class);
        assertEquals(a.f1, a1.f1);
        assertEquals(a.f2, a1.f2);

            

Reported by PMD.

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

Line: 19

                      assertEquals("{\"f2\":102,\"f1\":101,\"f3\":103}", str);

        JSONObject object = JSON.parseObject(str);
        A a1 = object.toJavaObject(A.class);
        assertEquals(a.f1, a1.f1);
        assertEquals(a.f2, a1.f2);
        assertEquals(a.f3, a1.f3);
    }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 20

              
        JSONObject object = JSON.parseObject(str);
        A a1 = object.toJavaObject(A.class);
        assertEquals(a.f1, a1.f1);
        assertEquals(a.f2, a1.f2);
        assertEquals(a.f3, a1.f3);
    }

    public static class A {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 21

                      JSONObject object = JSON.parseObject(str);
        A a1 = object.toJavaObject(A.class);
        assertEquals(a.f1, a1.f1);
        assertEquals(a.f2, a1.f2);
        assertEquals(a.f3, a1.f3);
    }

    public static class A {
        @JSONField(ordinal = 1)

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 22

                      A a1 = object.toJavaObject(A.class);
        assertEquals(a.f1, a1.f1);
        assertEquals(a.f2, a1.f2);
        assertEquals(a.f3, a1.f3);
    }

    public static class A {
        @JSONField(ordinal = 1)
        public int f1;

            

Reported by PMD.

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

Line: 27

              
    public static class A {
        @JSONField(ordinal = 1)
        public int f1;

        @JSONField(ordinal = 0)
        public int f2;

        @JSONField(ordinal = 2)

            

Reported by PMD.

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

Line: 30

                      public int f1;

        @JSONField(ordinal = 0)
        public int f2;

        @JSONField(ordinal = 2)
        public int f3;
    }
}

            

Reported by PMD.

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

Line: 33

                      public int f2;

        @JSONField(ordinal = 2)
        public int f3;
    }
}

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/path/JSONPath_14.java
10 issues
System.out.println is used
Design

Line: 32

              
        // 初始配置中,新增的字段添加的库中
        Map<String, Object> paths = JSONPath.paths(sourceJson);
        System.out.println(JSON.toJSONString(paths));
        assertEquals(10, paths.size());

        JSONObject destJson = JSON.parseObject("{\n" +
                "\t\"boolean1\":true,\n" +
                "\t\"boolean2\":false,\n" +

            

Reported by PMD.

System.out.println is used
Design

Line: 47

                          }
            if (!JSONPath.contains(destJson, stringObjectEntry.getKey())) {
                JSONPath.set(destJson, stringObjectEntry.getKey(), stringObjectEntry.getValue());
                System.out.println("key=" + stringObjectEntry.getKey() + " ,value=" + stringObjectEntry.getValue());
            }
        }

        System.out.println(destJson.toJSONString());
    }

            

Reported by PMD.

System.out.println is used
Design

Line: 51

                          }
        }

        System.out.println(destJson.toJSONString());
    }


}

            

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

              public class JSONPath_14
        extends TestCase {

    public void test_0() {
        JSONObject sourceJson = JSON.parseObject("{\n" +
                "\t\"boolean1\":true,\n" +
                "\t\"boolean2\":false,\n" +
                "\t\"boolean3\":true,\n" +
                "\t\"boolean4\":true,\n" +

            

Reported by PMD.

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

Line: 26

                              "\t\"name1\":\"str\"\n" +
                "}");

        sourceJson.put("enum1", TimeUnit.SECONDS);
        sourceJson.put("character1", 'A');
        sourceJson.put("uuid1", UUID.randomUUID());

        // 初始配置中,新增的字段添加的库中
        Map<String, Object> paths = JSONPath.paths(sourceJson);

            

Reported by PMD.

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

Line: 27

                              "}");

        sourceJson.put("enum1", TimeUnit.SECONDS);
        sourceJson.put("character1", 'A');
        sourceJson.put("uuid1", UUID.randomUUID());

        // 初始配置中,新增的字段添加的库中
        Map<String, Object> paths = JSONPath.paths(sourceJson);
        System.out.println(JSON.toJSONString(paths));

            

Reported by PMD.

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

Line: 28

              
        sourceJson.put("enum1", TimeUnit.SECONDS);
        sourceJson.put("character1", 'A');
        sourceJson.put("uuid1", UUID.randomUUID());

        // 初始配置中,新增的字段添加的库中
        Map<String, Object> paths = JSONPath.paths(sourceJson);
        System.out.println(JSON.toJSONString(paths));
        assertEquals(10, paths.size());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 33

                      // 初始配置中,新增的字段添加的库中
        Map<String, Object> paths = JSONPath.paths(sourceJson);
        System.out.println(JSON.toJSONString(paths));
        assertEquals(10, paths.size());

        JSONObject destJson = JSON.parseObject("{\n" +
                "\t\"boolean1\":true,\n" +
                "\t\"boolean2\":false,\n" +
                "\t\"name\":\"str\"\n" +

            

Reported by PMD.

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

Line: 33

                      // 初始配置中,新增的字段添加的库中
        Map<String, Object> paths = JSONPath.paths(sourceJson);
        System.out.println(JSON.toJSONString(paths));
        assertEquals(10, paths.size());

        JSONObject destJson = JSON.parseObject("{\n" +
                "\t\"boolean1\":true,\n" +
                "\t\"boolean2\":false,\n" +
                "\t\"name\":\"str\"\n" +

            

Reported by PMD.

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

Line: 51

                          }
        }

        System.out.println(destJson.toJSONString());
    }


}

            

Reported by PMD.