The following issues were found

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

Line: 12

              import java.util.TimeZone;

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

    public void test_for_issue() 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: 17

                      JSON.defaultLocale = Locale.CHINA;
    }

    public void test_for_issue() throws Exception {
        String json = "{\"create\":\"2018-01-10 08:30:00\"}";
        User user = JSON.parseObject(json, User.class);
        assertEquals("\"2018-01-10T08:30:00+08:00\"", JSON.toJSONString(user.create, SerializerFeature.UseISO8601DateFormat));
    }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 20

                  public void test_for_issue() throws Exception {
        String json = "{\"create\":\"2018-01-10 08:30:00\"}";
        User user = JSON.parseObject(json, User.class);
        assertEquals("\"2018-01-10T08:30:00+08:00\"", JSON.toJSONString(user.create, SerializerFeature.UseISO8601DateFormat));
    }

    public static class User{
        public Date create;
    }

            

Reported by PMD.

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

Line: 24

                  }

    public static class User{
        public Date create;
    }
}

            

Reported by PMD.

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

Line: 17

              import java.lang.reflect.Type;

public class Issue1662_1 extends TestCase {
    public void test_for_issue() throws Exception {
        String json = "{\"value\":123}";
        Model model = JSON.parseObject(json, Model.class);
        assertEquals("{\"value\":\"12300元\"}",JSON.toJSONString(model));

    }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 20

                  public void test_for_issue() throws Exception {
        String json = "{\"value\":123}";
        Model model = JSON.parseObject(json, Model.class);
        assertEquals("{\"value\":\"12300元\"}",JSON.toJSONString(model));

    }

    public static class Model {
        @JSONField(serializeUsing = ModelValueSerializer.class, deserializeUsing = ModelValueDeserializer.class)

            

Reported by PMD.

Avoid unused imports such as 'com.alibaba.fastjson.JSONObject'
Design

Line: 4

              package com.alibaba.json.bvt.issue_1600;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.parser.DefaultJSONParser;
import com.alibaba.fastjson.parser.ParserConfig;
import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;
import com.alibaba.fastjson.serializer.JSONSerializer;

            

Reported by PMD.

Avoid unused imports such as 'com.alibaba.fastjson.parser.ParserConfig'
Design

Line: 7

              import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.parser.DefaultJSONParser;
import com.alibaba.fastjson.parser.ParserConfig;
import com.alibaba.fastjson.parser.deserializer.ObjectDeserializer;
import com.alibaba.fastjson.serializer.JSONSerializer;
import com.alibaba.fastjson.serializer.ObjectSerializer;
import junit.framework.TestCase;


            

Reported by PMD.

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

Line: 15

              
public class TestCglib extends TestCase {

    public void test_cglib() throws Exception {
        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(Entity.class);
        enhancer.setCallback(new Proxy());
        Entity entity = (Entity) enhancer.create();
        

            

Reported by PMD.

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

Line: 21

                      enhancer.setCallback(new Proxy());
        Entity entity = (Entity) enhancer.create();
        
        entity.setId(3);
        entity.setName("Jobs");
        
        String text = JSON.toJSONString(entity);
        Assert.assertEquals("{\"id\":3,\"name\":\"Jobs\"}", text);


            

Reported by PMD.

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

Line: 22

                      Entity entity = (Entity) enhancer.create();
        
        entity.setId(3);
        entity.setName("Jobs");
        
        String text = JSON.toJSONString(entity);
        Assert.assertEquals("{\"id\":3,\"name\":\"Jobs\"}", text);

    }

            

Reported by PMD.

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

Line: 37

              
    }

    public static class Entity {

        private int    id;
        private String name;

        public Entity(){

            

Reported by PMD.

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

Line: 9

              import java.util.HashMap;

public class Issue1657 extends TestCase {
    public void test_for_issue() throws Exception {
        HashMap map = JSON.parseObject("\"\"", HashMap.class);
        assertEquals(0, map.size());
    }
}

            

Reported by PMD.

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

Line: 10

              
public class Issue1657 extends TestCase {
    public void test_for_issue() throws Exception {
        HashMap map = JSON.parseObject("\"\"", HashMap.class);
        assertEquals(0, map.size());
    }
}

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 11

              public class Issue1657 extends TestCase {
    public void test_for_issue() throws Exception {
        HashMap map = JSON.parseObject("\"\"", HashMap.class);
        assertEquals(0, map.size());
    }
}

            

Reported by PMD.

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

Line: 11

              public class Issue1657 extends TestCase {
    public void test_for_issue() throws Exception {
        HashMap map = JSON.parseObject("\"\"", HashMap.class);
        assertEquals(0, map.size());
    }
}

            

Reported by PMD.

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

Line: 13

              
public class OptionalTest2 extends TestCase {

    public void test_optional() throws Exception {
        Entity entity = new Entity();
        entity.setValue(Optional.of(123));

        String text = JSON.toJSONString(entity);


            

Reported by PMD.

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

Line: 23

              
        Entity entity2 = JSON.parseObject(text, Entity.class);
        
        Assert.assertEquals(entity.getValue().get(), entity2.getValue().get());
    }

    public static class Entity {

        private Optional<Integer> value;

            

Reported by PMD.

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

Line: 23

              
        Entity entity2 = JSON.parseObject(text, Entity.class);
        
        Assert.assertEquals(entity.getValue().get(), entity2.getValue().get());
    }

    public static class Entity {

        private Optional<Integer> value;

            

Reported by PMD.

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

Line: 23

              
        Entity entity2 = JSON.parseObject(text, Entity.class);
        
        Assert.assertEquals(entity.getValue().get(), entity2.getValue().get());
    }

    public static class Entity {

        private Optional<Integer> value;

            

Reported by PMD.

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

Line: 8

              import org.joda.time.format.*;

public class JodaTest_5_DateTimeFormatter extends TestCase {
    public void test_for_joda_0() throws Exception {

        String json = "{\"formatter\":\"yyyyMMdd\"}";
        Model m = JSON.parseObject(json, Model.class);

        assertEquals(DateTimeFormat.forPattern("yyyyMMdd"), m.formatter);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 13

                      String json = "{\"formatter\":\"yyyyMMdd\"}";
        Model m = JSON.parseObject(json, Model.class);

        assertEquals(DateTimeFormat.forPattern("yyyyMMdd"), m.formatter);
    }

    public static class Model {
        public DateTimeFormatter formatter;
    }

            

Reported by PMD.

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

Line: 17

                  }

    public static class Model {
        public DateTimeFormatter formatter;
    }
}

            

Reported by PMD.

Avoid unused imports such as 'org.joda.time.format'
Design

Line: 5

              
import com.alibaba.fastjson.JSON;
import junit.framework.TestCase;
import org.joda.time.format.*;

public class JodaTest_5_DateTimeFormatter extends TestCase {
    public void test_for_joda_0() throws Exception {

        String json = "{\"formatter\":\"yyyyMMdd\"}";

            

Reported by PMD.

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

Line: 10

              import java.util.List;

public class Issue1576 extends TestCase {
    public void test_for_issue() throws Exception {
        String json = "{\"code\":200,\"in_msg\":\"a\",\"out_msg\":\"a\",\"data\":[{\"title\":\"a\",\"url\":\"url\",\"content\":\"content\"}],\"client_id\":0,\"client_param\":0,\"userid\":0}";
        NewsDetail newsDetail = JSON.parseObject(json, NewsDetail.class);
        assertNotNull(newsDetail);
    }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 13

                  public void test_for_issue() throws Exception {
        String json = "{\"code\":200,\"in_msg\":\"a\",\"out_msg\":\"a\",\"data\":[{\"title\":\"a\",\"url\":\"url\",\"content\":\"content\"}],\"client_id\":0,\"client_param\":0,\"userid\":0}";
        NewsDetail newsDetail = JSON.parseObject(json, NewsDetail.class);
        assertNotNull(newsDetail);
    }

    public static class NewsDetail {

        public int code;

            

Reported by PMD.

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

Line: 16

                      assertNotNull(newsDetail);
    }

    public static class NewsDetail {

        public int code;
        public String in_msg;
        public String out_msg;
        public String client_id;

            

Reported by PMD.

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

Line: 83

                      }
    }

    public static class DataBean {
        /**
         * title : 中午
         * url : url
         * content : content
         */

            

Reported by PMD.

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

Line: 12

              import java.util.TimeZone;

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

    public void test_for_issue() 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: 17

                      JSON.defaultLocale = Locale.CHINA;
    }

    public void test_for_issue() throws Exception {
        Model model = JSON.parseObject("{\"startTime\":\"2017-11-04\",\"endTime\":\"2017-11-14\"}", Model.class);
        String text = JSON.toJSONString(model);
        assertEquals("{\"endTime\":\"2017-11-14\",\"startTime\":\"2017-11-04\"}", text);
    }


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 20

                  public void test_for_issue() throws Exception {
        Model model = JSON.parseObject("{\"startTime\":\"2017-11-04\",\"endTime\":\"2017-11-14\"}", Model.class);
        String text = JSON.toJSONString(model);
        assertEquals("{\"endTime\":\"2017-11-14\",\"startTime\":\"2017-11-04\"}", text);
    }

    public static class Model {
        @JSONField(format = "yyyy-MM-dd")
        private Date startTime;

            

Reported by PMD.

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

Line: 23

                      assertEquals("{\"endTime\":\"2017-11-14\",\"startTime\":\"2017-11-04\"}", text);
    }

    public static class Model {
        @JSONField(format = "yyyy-MM-dd")
        private Date startTime;

        @JSONField(format = "yyyy-MM-dd")
        private Date endTime;

            

Reported by PMD.

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

Line: 12

              import java.util.List;

public class Issue1496 extends TestCase {
    public void test_for_issue() throws Exception {
        String json = JSON.toJSONString(SetupStatus.FINAL_TRAIL);
        assertEquals("{\"canRefuse\":true,\"code\":3,\"declaringClass\":\"com.alibaba.json.bvt.issue_1400.Issue1496$SetupStatus\",\"first\":false,\"last\":false,\"name\":\"FINAL_TRAIL\",\"nameCn\":\"公益委员会/理事会/理事长审核\"}", json);
    }

    public interface ISetupStatusInfo {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 14

              public class Issue1496 extends TestCase {
    public void test_for_issue() throws Exception {
        String json = JSON.toJSONString(SetupStatus.FINAL_TRAIL);
        assertEquals("{\"canRefuse\":true,\"code\":3,\"declaringClass\":\"com.alibaba.json.bvt.issue_1400.Issue1496$SetupStatus\",\"first\":false,\"last\":false,\"name\":\"FINAL_TRAIL\",\"nameCn\":\"公益委员会/理事会/理事长审核\"}", json);
    }

    public interface ISetupStatusInfo {
        List<SetupStatus> nextList();


            

Reported by PMD.

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

Line: 172

                              return null;
            }
            for (SetupStatus status : values()) {
                if (status.name.equals(name)) {
                    return status;
                }
            }
            return null;
        }

            

Reported by PMD.

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

Line: 5

              
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONType;
import com.alibaba.fastjson.serializer.SerializeConfig;
import junit.framework.TestCase;

import java.util.Arrays;
import java.util.List;


            

Reported by PMD.

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

Line: 12

              import java.lang.reflect.Constructor;

public class Issue1547 extends TestCase {
    public void test_user() throws Exception {
        ExtClassLoader classLoader = new ExtClassLoader();
        Class clazz = classLoader.loadClass("Head");

        Object head = JSON.parseObject("{\"msg\":\"mmm\",\"code\":\"ccc\"}", clazz);
        assertEquals("{\"code\":\"ccc\",\"msg\":\"mmm\"}", JSON.toJSONString(head));

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 17

                      Class clazz = classLoader.loadClass("Head");

        Object head = JSON.parseObject("{\"msg\":\"mmm\",\"code\":\"ccc\"}", clazz);
        assertEquals("{\"code\":\"ccc\",\"msg\":\"mmm\"}", JSON.toJSONString(head));
    }

    public static class ExtClassLoader extends ClassLoader {

        public ExtClassLoader() throws IOException {

            

Reported by PMD.

Ensure that resources like this InputStream object are closed after use
Error

Line: 27

              
            {
                byte[] bytes;
                InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("kotlin/issue1547/Head.clazz");
                bytes = IOUtils.toByteArray(is);
                is.close();

                super.defineClass("Head", bytes, 0, bytes.length);
            }

            

Reported by PMD.

Avoid unused imports such as 'java.lang.reflect.Constructor'
Design

Line: 9

              
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Constructor;

public class Issue1547 extends TestCase {
    public void test_user() throws Exception {
        ExtClassLoader classLoader = new ExtClassLoader();
        Class clazz = classLoader.loadClass("Head");

            

Reported by PMD.