The following issues were found

src/test/java/com/alibaba/json/bvt/issue_1000/Issue1079.java
6 issues
JUnit tests should include assert() or fail()
Design

Line: 14

               * Created by wenshao on 17/03/2017.
 */
public class Issue1079 extends TestCase {
    public void test_for_issue() throws Exception {
        String text = "{\n" +
                "\t\"Response\": [{\n" +
                "\t\t\"Status\": {\n" +
                "\t\t\t\"StatusCode\": {\n" +
                "\t\t\t\t\"Value\": \"urn:oasis:names:tc:xacml:1.0:status:ok\"\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: 14

               * Created by wenshao on 17/03/2017.
 */
public class Issue1079 extends TestCase {
    public void test_for_issue() throws Exception {
        String text = "{\n" +
                "\t\"Response\": [{\n" +
                "\t\t\"Status\": {\n" +
                "\t\t\t\"StatusCode\": {\n" +
                "\t\t\t\t\"Value\": \"urn:oasis:names:tc:xacml:1.0:status:ok\"\n" +

            

Reported by PMD.

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

Line: 33

                  public static class PdpResponse {

        @JSONField(name ="Response")
        public List<Response> response;

        public static class Response {
            public List<InnerObject> innerObjects;
        }


            

Reported by PMD.

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

Line: 36

                      public List<Response> response;

        public static class Response {
            public List<InnerObject> innerObjects;
        }

        public static class InnerObject {
            @JSONField(name = "Status")
            public Status status;

            

Reported by PMD.

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

Line: 43

                          @JSONField(name = "Status")
            public Status status;
            @JSONField(name = "Decision")
            public String decision;
        }


        public static class Status {
            @JSONField(name = "StatusCode")

            

Reported by PMD.

Avoid unused imports such as 'com.fasterxml.jackson.annotation.JsonIgnore'
Design

Line: 5

              
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonIgnore;
import junit.framework.TestCase;

import java.util.List;

/**

            

Reported by PMD.

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

Line: 13

              
public class JSONCreatorTest extends TestCase {

    public void test_create() throws Exception {
        Entity entity = new Entity(123, "菜姐");
        String text = JSON.toJSONString(entity);
        
        Entity entity2 = JSON.parseObject(text, Entity.class);
        Assert.assertEquals(entity.getId(), entity2.getId());

            

Reported by PMD.

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

Line: 18

                      String text = JSON.toJSONString(entity);
        
        Entity entity2 = JSON.parseObject(text, Entity.class);
        Assert.assertEquals(entity.getId(), entity2.getId());
        Assert.assertEquals(entity.getName(), entity2.getName());
    }
    
    public void test_create_2() throws Exception {
        Entity entity = new Entity(123, "菜姐");

            

Reported by PMD.

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

Line: 19

                      
        Entity entity2 = JSON.parseObject(text, Entity.class);
        Assert.assertEquals(entity.getId(), entity2.getId());
        Assert.assertEquals(entity.getName(), entity2.getName());
    }
    
    public void test_create_2() throws Exception {
        Entity entity = new Entity(123, "菜姐");
        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: 22

                      Assert.assertEquals(entity.getName(), entity2.getName());
    }
    
    public void test_create_2() throws Exception {
        Entity entity = new Entity(123, "菜姐");
        String text = JSON.toJSONString(entity);
        
        ParserConfig config = new ParserConfig();
        config.setAsmEnable(false);

            

Reported by PMD.

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

Line: 30

                      config.setAsmEnable(false);
        
        Entity entity2 = JSON.parseObject(text, Entity.class, config, 0);
        Assert.assertEquals(entity.getId(), entity2.getId());
        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.assertEquals(entity.getId(), entity2.getId());
        Assert.assertEquals(entity.getName(), entity2.getName());
    }

    public static class Entity {

        private final int    id;

            

Reported by PMD.

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

Line: 11

               * @Date :Created in 00:14 2020/7/18
 */
public class Issue3351 extends TestCase {
    public void test_for_issue() throws Exception {
        String cString = "c110";
        boolean cValid = JSONValidator.from(cString).validate();
        assertFalse(cValid);

        String jsonString = "{\"forecast\":\"sss\"}";

            

Reported by PMD.

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

Line: 11

               * @Date :Created in 00:14 2020/7/18
 */
public class Issue3351 extends TestCase {
    public void test_for_issue() throws Exception {
        String cString = "c110";
        boolean cValid = JSONValidator.from(cString).validate();
        assertFalse(cValid);

        String jsonString = "{\"forecast\":\"sss\"}";

            

Reported by PMD.

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

Line: 13

              public class Issue3351 extends TestCase {
    public void test_for_issue() throws Exception {
        String cString = "c110";
        boolean cValid = JSONValidator.from(cString).validate();
        assertFalse(cValid);

        String jsonString = "{\"forecast\":\"sss\"}";
        boolean jsonValid = JSONValidator.from(jsonString).validate();
        assertTrue(jsonValid);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 14

                  public void test_for_issue() throws Exception {
        String cString = "c110";
        boolean cValid = JSONValidator.from(cString).validate();
        assertFalse(cValid);

        String jsonString = "{\"forecast\":\"sss\"}";
        boolean jsonValid = JSONValidator.from(jsonString).validate();
        assertTrue(jsonValid);
    }

            

Reported by PMD.

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

Line: 17

                      assertFalse(cValid);

        String jsonString = "{\"forecast\":\"sss\"}";
        boolean jsonValid = JSONValidator.from(jsonString).validate();
        assertTrue(jsonValid);
    }

}

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 18

              
        String jsonString = "{\"forecast\":\"sss\"}";
        boolean jsonValid = JSONValidator.from(jsonString).validate();
        assertTrue(jsonValid);
    }

}

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_1700/Issue1780_Module.java
6 issues
System.out.println is used
Design

Line: 46

              
				public void write(JSONSerializer serializer, Object object, Object fieldName, Type fieldType,
						int features) throws IOException {
					System.out.println("-------------myModule.createSerializer-------------------");
					org.json.JSONObject req = (org.json.JSONObject) object;
					serializer.out.write(req.toString());
				}
			};
		}

            

Reported by PMD.

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

Line: 21

              
public class Issue1780_Module extends TestCase {

	public void test_for_issue() {
		org.json.JSONObject req = new org.json.JSONObject();

		SerializeConfig config = new SerializeConfig();
		config.register(new myModule());
		req.put("id", 1111);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 30

              		req.put("name", "name11");
		String text = JSON.toJSONString(req, SerializerFeature.SortField);

		assertTrue("{\"id\":1111,\"name\":\"name11\"}".equals(text) || "{\"name\":\"name11\",\"id\":1111}".equals(text));
	}

	public class myModule implements Module {

		@SuppressWarnings("rawtypes")

            

Reported by PMD.

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

Line: 48

              						int features) throws IOException {
					System.out.println("-------------myModule.createSerializer-------------------");
					org.json.JSONObject req = (org.json.JSONObject) object;
					serializer.out.write(req.toString());
				}
			};
		}

	}

            

Reported by PMD.

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

Line: 48

              						int features) throws IOException {
					System.out.println("-------------myModule.createSerializer-------------------");
					org.json.JSONObject req = (org.json.JSONObject) object;
					serializer.out.write(req.toString());
				}
			};
		}

	}

            

Reported by PMD.

Avoid unused imports such as 'org.junit.Assert'
Design

Line: 7

              import java.lang.reflect.Type;

import com.alibaba.fastjson.serializer.SerializerFeature;
import org.junit.Assert;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.parser.ParserConfig;
import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;
import com.alibaba.fastjson.serializer.JSONSerializer;

            

Reported by PMD.

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

Line: 11

              import java.util.List;

public class Bug_for_lingzhi extends TestCase {
    public void test_0() throws Exception {
        String str = "[\n" +
                "{\n" +
                "\"isDefault\":false,\n" +
                "\"msgId\": \"expireTransitionChange\",\n" +
                "\"msgText\": \"xxx\",\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

              import java.util.List;

public class Bug_for_lingzhi extends TestCase {
    public void test_0() throws Exception {
        String str = "[\n" +
                "{\n" +
                "\"isDefault\":false,\n" +
                "\"msgId\": \"expireTransitionChange\",\n" +
                "\"msgText\": \"xxx\",\n" +

            

Reported by PMD.

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

Line: 23

                              "\"rule\": {\n" +
                "\"aliUid\":[39314],\n" +
                "\"regionNo\":[]\n" +
                "}\n" +
                "},\n" +
                "{\n" +
                "\"isDefault\":true,\n" +
                "\"msgId\": \"expireTransitionUnChange\",\n" +
                "\"msgText\": \"xxx\",\n" +

            

Reported by PMD.

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

Line: 57

                      JSON.parseObject(str, new TypeReference<List<EcsTransitionDisplayedMsgConfig>>(){});
    }

    public static class EcsTransitionDisplayedMsgConfig {

        /**
         * 是否默认文案
         */
        private Boolean isDefault;

            

Reported by PMD.

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

Line: 149

                      }
    }

    public static class EcsTransitionConfigRule {


        /** 0 过保迁移, 1 非过保迁移 **/
        private List<Integer> transType;


            

Reported by PMD.

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

Line: 5

              
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.serializer.SerializerFeature;
import junit.framework.TestCase;

import java.util.List;

public class Bug_for_lingzhi extends TestCase {

            

Reported by PMD.

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

Line: 13

              
public class JSONReader_error extends TestCase {

    public void test_0() throws Exception {
        JSONReader reader = new JSONReader(new StringReader("[]"));

        Exception error = null;
        try {
            reader.hasNext();

            

Reported by PMD.

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

Line: 19

                      Exception error = null;
        try {
            reader.hasNext();
        } catch (Exception e) {
            error = e;
        }
        Assert.assertNotNull(error);
        
    }

            

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

                      
    }

    public void test_1() throws Exception {
        JSONReader reader = new JSONReader(new StringReader("{\"id\":123}"));

        reader.startObject();
        reader.readObject();


            

Reported by PMD.

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

Line: 35

                      Exception error = null;
        try {
            reader.hasNext();
        } catch (Exception e) {
            error = e;
        }
        Assert.assertNotNull(error);
    }
}

            

Reported by PMD.

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

Line: 16

                  public void test_0() throws Exception {
        JSONReader reader = new JSONReader(new StringReader("[]"));

        Exception error = null;
        try {
            reader.hasNext();
        } catch (Exception e) {
            error = e;
        }

            

Reported by PMD.

Found 'DD'-anomaly for variable 'error' (lines '32'-'36').
Error

Line: 32

                      reader.startObject();
        reader.readObject();

        Exception error = null;
        try {
            reader.hasNext();
        } catch (Exception e) {
            error = e;
        }

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/issue_3300/Issue3373.java
6 issues
System.out.println is used
Design

Line: 19

                      items.add(new Item("item1",category));
        items.add(new Item("item2",category));

        System.out.println(JSON.toJSONString(items,refAfterFilterTest));
    }

    public static class RefBeforeFilterTest extends BeforeFilter {

        private Category category = new Category("afterFilterCategory");

            

Reported by PMD.

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

Line: 11

              import java.util.List;

public class Issue3373 extends TestCase {
    public void test_for_issue() throws Exception {
        RefBeforeFilterTest refAfterFilterTest = new RefBeforeFilterTest();

        List<Item> items = new ArrayList<Item>(2);
        Category category = new Category("category");
        items.add(new Item("item1",category));

            

Reported by PMD.

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

Line: 11

              import java.util.List;

public class Issue3373 extends TestCase {
    public void test_for_issue() throws Exception {
        RefBeforeFilterTest refAfterFilterTest = new RefBeforeFilterTest();

        List<Item> items = new ArrayList<Item>(2);
        Category category = new Category("category");
        items.add(new Item("item1",category));

            

Reported by PMD.

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

Line: 24

              
    public static class RefBeforeFilterTest extends BeforeFilter {

        private Category category = new Category("afterFilterCategory");

        @Override
        public void writeBefore(Object object) {

            if (object instanceof Item) {

            

Reported by PMD.

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

Line: 24

              
    public static class RefBeforeFilterTest extends BeforeFilter {

        private Category category = new Category("afterFilterCategory");

        @Override
        public void writeBefore(Object object) {

            if (object instanceof Item) {

            

Reported by PMD.

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

Line: 58

                      }
    }

    public static class Item {

        private String name;

        private Category category;


            

Reported by PMD.

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

Line: 13

              
public class JSONCreatorTest_double 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() == entity2.getId());

            

Reported by PMD.

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

Line: 18

                      String text = JSON.toJSONString(entity);
        
        Entity entity2 = JSON.parseObject(text, Entity.class);
        Assert.assertTrue(entity.getId() == entity2.getId());
        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

                      
        Entity entity2 = JSON.parseObject(text, Entity.class);
        Assert.assertTrue(entity.getId() == entity2.getId());
        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: 22

                      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 (object not created locally)
Design

Line: 29

                      ParserConfig config = new ParserConfig();
        
        Entity entity2 = JSON.parseObject(text, Entity.class, config, 0);
        Assert.assertTrue(entity.getId() == entity2.getId());
        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

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

    public static class Entity {

        private final double    id;

            

Reported by PMD.

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

Line: 12

               */
public class Issue1134 extends TestCase {

    public void test_for_issue() throws Exception {
        Model model = new Model();
        model.blockpos = new BlockPos();
        model.blockpos.x = 526;
        model.blockpos.y = 65;
        model.blockpos.z = 554;

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 21

                      model.passCode = "010";

        String text = JSON.toJSONString(model);
        assertEquals("{\"Dimension\":0,\"PassCode\":\"010\",\"BlockPos\":{\"x\":526,\"y\":65,\"z\":554}}", text);
    }

    public static class Model {
        @JSONField(ordinal = 1, name="Dimension")
        private int dimension;

            

Reported by PMD.

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

Line: 24

                      assertEquals("{\"Dimension\":0,\"PassCode\":\"010\",\"BlockPos\":{\"x\":526,\"y\":65,\"z\":554}}", text);
    }

    public static class Model {
        @JSONField(ordinal = 1, name="Dimension")
        private int dimension;
        @JSONField(ordinal = 2, name="PassCode")
        private String passCode;
        @JSONField(ordinal = 3, name="BlockPos")

            

Reported by PMD.

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

Line: 58

                  }

    public static class BlockPos {
        public int x;
        public int y;
        public int z;
    }
}

            

Reported by PMD.

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

Line: 59

              
    public static class BlockPos {
        public int x;
        public int y;
        public int z;
    }
}

            

Reported by PMD.

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

Line: 60

                  public static class BlockPos {
        public int x;
        public int y;
        public int z;
    }
}

            

Reported by PMD.

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

Line: 18

               * @Date :Created in 16:32 2020/8/16
 */
public class Issue3397 extends TestCase {
    @Override
    public void setUp() throws Exception {
        JSON.defaultTimeZone = TimeZone.getDefault();
        JSON.defaultLocale = Locale.CHINA;
    }


            

Reported by PMD.

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

Line: 24

                      JSON.defaultLocale = Locale.CHINA;
    }

    public void test_for_issue() throws Exception {
        String text = "{\"date\":\"2020-08-16 16:35:18.188\"}";
        VO vo = JSON.parseObject(text, VO.class);

        JSONObject json = (JSONObject) JSONObject.toJSON(vo);


            

Reported by PMD.

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

Line: 24

                      JSON.defaultLocale = Locale.CHINA;
    }

    public void test_for_issue() throws Exception {
        String text = "{\"date\":\"2020-08-16 16:35:18.188\"}";
        VO vo = JSON.parseObject(text, VO.class);

        JSONObject json = (JSONObject) JSONObject.toJSON(vo);


            

Reported by PMD.

Avoid unused local variables such as 'date'.
Design

Line: 30

              
        JSONObject json = (JSONObject) JSONObject.toJSON(vo);

        Date date = json.getDate("date");
//        assertEquals("Sun Aug 16 16:35:18 CST 2020", date.toString());
    }

    public static class VO {
        @JSONField(format = "yyyy-MM-dd HH:mm:ss.SSS")

            

Reported by PMD.

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

Line: 30

              
        JSONObject json = (JSONObject) JSONObject.toJSON(vo);

        Date date = json.getDate("date");
//        assertEquals("Sun Aug 16 16:35:18 CST 2020", date.toString());
    }

    public static class VO {
        @JSONField(format = "yyyy-MM-dd HH:mm:ss.SSS")

            

Reported by PMD.

Found 'DU'-anomaly for variable 'date' (lines '30'-'32').
Error

Line: 30

              
        JSONObject json = (JSONObject) JSONObject.toJSON(vo);

        Date date = json.getDate("date");
//        assertEquals("Sun Aug 16 16:35:18 CST 2020", date.toString());
    }

    public static class VO {
        @JSONField(format = "yyyy-MM-dd HH:mm:ss.SSS")

            

Reported by PMD.