The following issues were found

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

Line: 14

              
public class EnumCustomCodecTest extends TestCase {

    public void test_for_enum() throws Exception {
        Type type = Type.A;
        String str =JSON.toJSONString(type);

        assertEquals("{\"id\":1001,\"name\":\"aaa\"}", str);


            

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

              
public class EnumCustomCodecTest extends TestCase {

    public void test_for_enum() throws Exception {
        Type type = Type.A;
        String str =JSON.toJSONString(type);

        assertEquals("{\"id\":1001,\"name\":\"aaa\"}", str);


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 18

                      Type type = Type.A;
        String str =JSON.toJSONString(type);

        assertEquals("{\"id\":1001,\"name\":\"aaa\"}", str);

        Type type2 = JSON.parseObject(str, Type.class);
        Type type3 = JSON.parseObject(str, Type.class);

        assertSame(type, type2);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 23

                      Type type2 = JSON.parseObject(str, Type.class);
        Type type3 = JSON.parseObject(str, Type.class);

        assertSame(type, type2);
        assertSame(type, type3);

    }

    @JSONType(serializeEnumAsJavaBean = true, deserializer = TypeDeser.class)

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 24

                      Type type3 = JSON.parseObject(str, Type.class);

        assertSame(type, type2);
        assertSame(type, type3);

    }

    @JSONType(serializeEnumAsJavaBean = true, deserializer = TypeDeser.class)
    public static enum Type {

            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 42

                      }

        public static Type valueOf(long id) {
            if (id == 1001) {
                return A;
            } else if (id == 1002) {
                return B;
            }
            return null;

            

Reported by PMD.

Avoid using Literals in Conditional Statements
Error

Line: 44

                      public static Type valueOf(long id) {
            if (id == 1001) {
                return A;
            } else if (id == 1002) {
                return B;
            }
            return null;
        }
    }

            

Reported by PMD.

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

Line: 55

              
        public <T> T deserialze(DefaultJSONParser parser, java.lang.reflect.Type type, Object fieldName) {
            JSONObject object = parser.parseObject();
            long id = object.getLongValue("id");
            return (T) Type.valueOf(id);
        }

        public int getFastMatchToken() {
            return 0;

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/deser/PropertyProcessableTest_0.java
8 issues
Unit tests should not contain more than 1 assert(s).
Design

Line: 13

               * Created by wenshao on 15/07/2017.
 */
public class PropertyProcessableTest_0 extends TestCase {
    public void test_processable() throws Exception {
        VO vo = JSON.parseObject("{\"vo_id\":123,\"vo_name\":\"abc\",\"value\":{}}", VO.class);
        assertEquals(123, vo.id);
        assertEquals("abc", vo.name);
        assertNotNull(vo.value);
    }

            

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 15/07/2017.
 */
public class PropertyProcessableTest_0 extends TestCase {
    public void test_processable() throws Exception {
        VO vo = JSON.parseObject("{\"vo_id\":123,\"vo_name\":\"abc\",\"value\":{}}", VO.class);
        assertEquals(123, vo.id);
        assertEquals("abc", vo.name);
        assertNotNull(vo.value);
    }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 15

              public class PropertyProcessableTest_0 extends TestCase {
    public void test_processable() throws Exception {
        VO vo = JSON.parseObject("{\"vo_id\":123,\"vo_name\":\"abc\",\"value\":{}}", VO.class);
        assertEquals(123, vo.id);
        assertEquals("abc", vo.name);
        assertNotNull(vo.value);
    }

    public static class VO implements PropertyProcessable {

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 16

                  public void test_processable() throws Exception {
        VO vo = JSON.parseObject("{\"vo_id\":123,\"vo_name\":\"abc\",\"value\":{}}", VO.class);
        assertEquals(123, vo.id);
        assertEquals("abc", vo.name);
        assertNotNull(vo.value);
    }

    public static class VO implements PropertyProcessable {
        public int id;

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 17

                      VO vo = JSON.parseObject("{\"vo_id\":123,\"vo_name\":\"abc\",\"value\":{}}", VO.class);
        assertEquals(123, vo.id);
        assertEquals("abc", vo.name);
        assertNotNull(vo.value);
    }

    public static class VO implements PropertyProcessable {
        public int id;
        public String name;

            

Reported by PMD.

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

Line: 21

                  }

    public static class VO implements PropertyProcessable {
        public int id;
        public String name;
        public Value value;

        public Type getType(String name) {
            if ("value".equals(name)) {

            

Reported by PMD.

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

Line: 22

              
    public static class VO implements PropertyProcessable {
        public int id;
        public String name;
        public Value value;

        public Type getType(String name) {
            if ("value".equals(name)) {
                return Value.class;

            

Reported by PMD.

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

Line: 23

                  public static class VO implements PropertyProcessable {
        public int id;
        public String name;
        public Value value;

        public Type getType(String name) {
            if ("value".equals(name)) {
                return Value.class;
            }

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/path/TestSpecial_3.java
8 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 TestSpecial_3 extends TestCase {

    public void test_special() throws Exception {
        String json = "[{\"@type\":\"NAME_CORRECTION\",\"value\":23}]";
        JSONArray array = (JSONArray) JSON.parse(json, Feature.DisableSpecialKeyDetect);
        Object obj = JSONPath.eval(array, "[\\@type='NAME_CORRECTION']");
        assertNotNull(obj);
    }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 19

                      String json = "[{\"@type\":\"NAME_CORRECTION\",\"value\":23}]";
        JSONArray array = (JSONArray) JSON.parse(json, Feature.DisableSpecialKeyDetect);
        Object obj = JSONPath.eval(array, "[\\@type='NAME_CORRECTION']");
        assertNotNull(obj);
    }

    public void test_special_1() throws Exception {
        String json = "[{\":lang\":\"NAME_CORRECTION\",\"value\":23}]";
        JSONArray array = (JSONArray) JSON.parse(json, Feature.DisableSpecialKeyDetect);

            

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

                      assertNotNull(obj);
    }

    public void test_special_1() throws Exception {
        String json = "[{\":lang\":\"NAME_CORRECTION\",\"value\":23}]";
        JSONArray array = (JSONArray) JSON.parse(json, Feature.DisableSpecialKeyDetect);
        Object obj = JSONPath.eval(array, "[\\:lang='NAME_CORRECTION']");
        assertNotNull(obj);
    }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 26

                      String json = "[{\":lang\":\"NAME_CORRECTION\",\"value\":23}]";
        JSONArray array = (JSONArray) JSON.parse(json, Feature.DisableSpecialKeyDetect);
        Object obj = JSONPath.eval(array, "[\\:lang='NAME_CORRECTION']");
        assertNotNull(obj);
    }

    public void test_special_2() throws Exception {
        String json = "{\"cpe-item\":{\"@name\":\"cpe:/a:google:chrome:4.0.249.19\",\"cpe-23:cpe23-item\":{\"@name\":\"cpe:2.3:a:google:chrome:4.0.249.19:*:*:*:*:*:*:*\"},\"title\":[{\"#text\":\"グーグル クローム 4.0.249.19\",\"@xml:lang\":\"ja-JP\"},{\"#text\":\"Google Chrome 4.0.249.19\",\"@xml:lang\":\"en-US\"}]}}";
        String path = "['cpe-item']['title'][\\@xml\\:lang='en-US']['#text'][0]";

            

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

                      assertNotNull(obj);
    }

    public void test_special_2() throws Exception {
        String json = "{\"cpe-item\":{\"@name\":\"cpe:/a:google:chrome:4.0.249.19\",\"cpe-23:cpe23-item\":{\"@name\":\"cpe:2.3:a:google:chrome:4.0.249.19:*:*:*:*:*:*:*\"},\"title\":[{\"#text\":\"グーグル クローム 4.0.249.19\",\"@xml:lang\":\"ja-JP\"},{\"#text\":\"Google Chrome 4.0.249.19\",\"@xml:lang\":\"en-US\"}]}}";
        String path = "['cpe-item']['title'][\\@xml\\:lang='en-US']['#text'][0]";
        JSONObject object = (JSONObject) JSON.parse(json, Feature.DisableSpecialKeyDetect);
        Object obj = JSONPath.eval(object, path);
        assertNotNull(obj);

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 34

                      String path = "['cpe-item']['title'][\\@xml\\:lang='en-US']['#text'][0]";
        JSONObject object = (JSONObject) JSON.parse(json, Feature.DisableSpecialKeyDetect);
        Object obj = JSONPath.eval(object, path);
        assertNotNull(obj);
    }
}

            

Reported by PMD.

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

Line: 10

              import com.alibaba.fastjson.parser.Feature;
import junit.framework.TestCase;

import java.util.HashMap;
import java.util.Map;

public class TestSpecial_3 extends TestCase {

    public void test_special() throws Exception {

            

Reported by PMD.

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

Line: 11

              import junit.framework.TestCase;

import java.util.HashMap;
import java.util.Map;

public class TestSpecial_3 extends TestCase {

    public void test_special() throws Exception {
        String json = "[{\"@type\":\"NAME_CORRECTION\",\"value\":23}]";

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/serializer/date/DateTest_ISO8601_OneLetterISO8601TimeZone.java
8 issues
A method/constructor should not explicitly throw java.lang.Exception
Design

Line: 13

              
public class DateTest_ISO8601_OneLetterISO8601TimeZone extends TestCase {

    public void f_test_date() throws Exception {
        String text = "{\"gmtCreate\":\"2014-08-21T09:51:36.2+08\"}";
        
        Calendar date = JSON.parseObject(text, VO.class).getGmtCreate();
        Assert.assertNotNull(date);
        

            

Reported by PMD.

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

Line: 16

                  public void f_test_date() throws Exception {
        String text = "{\"gmtCreate\":\"2014-08-21T09:51:36.2+08\"}";
        
        Calendar date = JSON.parseObject(text, VO.class).getGmtCreate();
        Assert.assertNotNull(date);
        
        Assert.assertEquals(8, date.getTimeZone().getRawOffset()/(3600*1000));
    }
    

            

Reported by PMD.

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

Line: 19

                      Calendar date = JSON.parseObject(text, VO.class).getGmtCreate();
        Assert.assertNotNull(date);
        
        Assert.assertEquals(8, date.getTimeZone().getRawOffset()/(3600*1000));
    }
    
    public void test_date_9() throws Exception {
        String text = "{\"gmtCreate\":\"2014-08-21T09:51:36.235+09\"}";
        

            

Reported by PMD.

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

Line: 19

                      Calendar date = JSON.parseObject(text, VO.class).getGmtCreate();
        Assert.assertNotNull(date);
        
        Assert.assertEquals(8, date.getTimeZone().getRawOffset()/(3600*1000));
    }
    
    public void test_date_9() throws Exception {
        String text = "{\"gmtCreate\":\"2014-08-21T09:51:36.235+09\"}";
        

            

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(8, date.getTimeZone().getRawOffset()/(3600*1000));
    }
    
    public void test_date_9() throws Exception {
        String text = "{\"gmtCreate\":\"2014-08-21T09:51:36.235+09\"}";
        
        Calendar date = JSON.parseObject(text, VO.class).getGmtCreate();
        Assert.assertNotNull(date);
        

            

Reported by PMD.

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

Line: 25

                  public void test_date_9() throws Exception {
        String text = "{\"gmtCreate\":\"2014-08-21T09:51:36.235+09\"}";
        
        Calendar date = JSON.parseObject(text, VO.class).getGmtCreate();
        Assert.assertNotNull(date);
        
        Assert.assertEquals(9, date.getTimeZone().getRawOffset()/(3600*1000));
    }


            

Reported by PMD.

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

Line: 28

                      Calendar date = JSON.parseObject(text, VO.class).getGmtCreate();
        Assert.assertNotNull(date);
        
        Assert.assertEquals(9, date.getTimeZone().getRawOffset()/(3600*1000));
    }

    public static class VO {

        private Calendar gmtCreate;

            

Reported by PMD.

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

Line: 28

                      Calendar date = JSON.parseObject(text, VO.class).getGmtCreate();
        Assert.assertNotNull(date);
        
        Assert.assertEquals(9, date.getTimeZone().getRawOffset()/(3600*1000));
    }

    public static class VO {

        private Calendar gmtCreate;

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/writeAsArray/WriteAsArray_Object_public.java
8 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 WriteAsArray_Object_public extends TestCase {

    public void test_0() throws Exception {
        A a = new A();
        a.setId(123);
        a.setName("wenshao");
        
        VO vo = new VO();

            

Reported by PMD.

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

Line: 25

                      Assert.assertEquals("[[123,\"wenshao\"]]", text);
        
        VO vo2 = JSON.parseObject(text, VO.class, Feature.SupportArrayToBean);
        Assert.assertEquals(vo.getA().getId(), vo2.getA().getId());
        Assert.assertEquals(vo.getA().getName(), vo2.getA().getName());
    }

    public static class VO {


            

Reported by PMD.

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

Line: 25

                      Assert.assertEquals("[[123,\"wenshao\"]]", text);
        
        VO vo2 = JSON.parseObject(text, VO.class, Feature.SupportArrayToBean);
        Assert.assertEquals(vo.getA().getId(), vo2.getA().getId());
        Assert.assertEquals(vo.getA().getName(), vo2.getA().getName());
    }

    public static class VO {


            

Reported by PMD.

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

Line: 25

                      Assert.assertEquals("[[123,\"wenshao\"]]", text);
        
        VO vo2 = JSON.parseObject(text, VO.class, Feature.SupportArrayToBean);
        Assert.assertEquals(vo.getA().getId(), vo2.getA().getId());
        Assert.assertEquals(vo.getA().getName(), vo2.getA().getName());
    }

    public static class VO {


            

Reported by PMD.

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

Line: 26

                      
        VO vo2 = JSON.parseObject(text, VO.class, Feature.SupportArrayToBean);
        Assert.assertEquals(vo.getA().getId(), vo2.getA().getId());
        Assert.assertEquals(vo.getA().getName(), vo2.getA().getName());
    }

    public static class VO {

        private A a;

            

Reported by PMD.

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

Line: 26

                      
        VO vo2 = JSON.parseObject(text, VO.class, Feature.SupportArrayToBean);
        Assert.assertEquals(vo.getA().getId(), vo2.getA().getId());
        Assert.assertEquals(vo.getA().getName(), vo2.getA().getName());
    }

    public static class VO {

        private A a;

            

Reported by PMD.

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

Line: 26

                      
        VO vo2 = JSON.parseObject(text, VO.class, Feature.SupportArrayToBean);
        Assert.assertEquals(vo.getA().getId(), vo2.getA().getId());
        Assert.assertEquals(vo.getA().getName(), vo2.getA().getName());
    }

    public static class VO {

        private A a;

            

Reported by PMD.

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

Line: 43

              
    }

    public static class A {

        private int    id;
        private String name;

        public int getId() {

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/support/jaxrs/FastJsonProviderTest.java
8 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: 22

              
public class FastJsonProviderTest extends TestCase {

    @SuppressWarnings("deprecation")
    public void test_1() throws Exception {

        FastJsonProvider provider1 = new FastJsonProvider("UTF-8");
        Assert.assertEquals("UTF-8", provider1.getCharset().name());


            

Reported by PMD.

The String literal 'UTF-8' appears 5 times in this file; the first occurrence is on line 25
Error

Line: 25

                  @SuppressWarnings("deprecation")
    public void test_1() throws Exception {

        FastJsonProvider provider1 = new FastJsonProvider("UTF-8");
        Assert.assertEquals("UTF-8", provider1.getCharset().name());

        FastJsonProvider provider2 = new FastJsonProvider();

        provider2.setCharset(Charset.forName("GBK"));

            

Reported by PMD.

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

Line: 26

                  public void test_1() throws Exception {

        FastJsonProvider provider1 = new FastJsonProvider("UTF-8");
        Assert.assertEquals("UTF-8", provider1.getCharset().name());

        FastJsonProvider provider2 = new FastJsonProvider();

        provider2.setCharset(Charset.forName("GBK"));
        Assert.assertEquals("GBK", provider2.getCharset().name());

            

Reported by PMD.

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

Line: 31

                      FastJsonProvider provider2 = new FastJsonProvider();

        provider2.setCharset(Charset.forName("GBK"));
        Assert.assertEquals("GBK", provider2.getCharset().name());

        Assert.assertNull(provider2.getDateFormat());
        provider2.setDateFormat("yyyyMMdd");

        provider2.setFeatures(SerializerFeature.IgnoreErrorGetter);

            

Reported by PMD.

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

Line: 37

                      provider2.setDateFormat("yyyyMMdd");

        provider2.setFeatures(SerializerFeature.IgnoreErrorGetter);
        Assert.assertEquals(1, provider2.getFeatures().length);
        Assert.assertEquals(SerializerFeature.IgnoreErrorGetter,
                provider2.getFeatures()[0]);

        provider2.setFilters(serializeFilter);
        Assert.assertEquals(1, provider2.getFilters().length);

            

Reported by PMD.

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

Line: 42

                              provider2.getFeatures()[0]);

        provider2.setFilters(serializeFilter);
        Assert.assertEquals(1, provider2.getFilters().length);
        Assert.assertEquals(serializeFilter, provider2.getFilters()[0]);

        FastJsonProvider provider = new FastJsonProvider(new Class[]{VO.class});

        Assert.assertNotNull(provider.getFastJsonConfig());

            

Reported by PMD.

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

Line: 89

                      }
    }

    private SerializeFilter serializeFilter = new ValueFilter() {
        @Override
        public Object process(Object object, String name, Object value) {
            if (value == null) {
                return "";
            }

            

Reported by PMD.

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

Line: 89

                      }
    }

    private SerializeFilter serializeFilter = new ValueFilter() {
        @Override
        public Object process(Object object, String name, Object value) {
            if (value == null) {
                return "";
            }

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/typeRef/TypeReferenceTest14.java
8 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

               * Created by wenshao on 09/02/2017.
 */
public class TypeReferenceTest14 extends TestCase {
    public void test_0() throws Exception {
        String str = "{\"result\":{\"item\":[{\"key\":\"123\"}]}}";

        ParserConfig config = new ParserConfig();
        JSONObject.parseObject(str, OpenSearchResponse.class, config);
        JSONObject.parseObject(str

            

Reported by PMD.

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

Line: 26

                              , new TypeReference<OpenSearchResponse<JSONObject>>() {}.getType()
                , config, JSON.DEFAULT_PARSER_FEATURE);

        int size = config.getDeserializers().size();
        for (int i = 0; i < 100 * 1; ++i) {
            JSONObject.parseObject(str
                    , new TypeReference<OpenSearchResponse<JSONObject>>() {}.getType()
                    , config, JSON.DEFAULT_PARSER_FEATURE);
            assertEquals(size, config.getDeserializers().size());

            

Reported by PMD.

Avoid instantiating new objects inside loops
Performance

Line: 29

                      int size = config.getDeserializers().size();
        for (int i = 0; i < 100 * 1; ++i) {
            JSONObject.parseObject(str
                    , new TypeReference<OpenSearchResponse<JSONObject>>() {}.getType()
                    , config, JSON.DEFAULT_PARSER_FEATURE);
            assertEquals(size, config.getDeserializers().size());
        }
    }


            

Reported by PMD.

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

Line: 31

                          JSONObject.parseObject(str
                    , new TypeReference<OpenSearchResponse<JSONObject>>() {}.getType()
                    , config, JSON.DEFAULT_PARSER_FEATURE);
            assertEquals(size, config.getDeserializers().size());
        }
    }

    public static class OpenSearchResponse<T> {


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 31

                          JSONObject.parseObject(str
                    , new TypeReference<OpenSearchResponse<JSONObject>>() {}.getType()
                    , config, JSON.DEFAULT_PARSER_FEATURE);
            assertEquals(size, config.getDeserializers().size());
        }
    }

    public static class OpenSearchResponse<T> {


            

Reported by PMD.

Avoid unused imports such as 'com.alibaba.fastjson.annotation.JSONField'
Design

Line: 6

              import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.parser.ParserConfig;
import java.util.List;
import junit.framework.TestCase;

import java.io.Serializable;

            

Reported by PMD.

Avoid unused imports such as 'java.io.Serializable'
Design

Line: 11

              import java.util.List;
import junit.framework.TestCase;

import java.io.Serializable;

/**
 * Created by wenshao on 09/02/2017.
 */
public class TypeReferenceTest14 extends TestCase {

            

Reported by PMD.

Found 'DU'-anomaly for variable 'size' (lines '26'-'33').
Error

Line: 26

                              , new TypeReference<OpenSearchResponse<JSONObject>>() {}.getType()
                , config, JSON.DEFAULT_PARSER_FEATURE);

        int size = config.getDeserializers().size();
        for (int i = 0; i < 100 * 1; ++i) {
            JSONObject.parseObject(str
                    , new TypeReference<OpenSearchResponse<JSONObject>>() {}.getType()
                    , config, JSON.DEFAULT_PARSER_FEATURE);
            assertEquals(size, config.getDeserializers().size());

            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/deser/deny/DenyTest8.java
8 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 DenyTest8 extends TestCase {

    public void test_autoTypeDeny() throws Exception {
        ParserConfig config = new ParserConfig();

        assertFalse(config.isAutoTypeSupport());
        config.setAutoTypeSupport(true);
        assertTrue(config.isAutoTypeSupport());

            

Reported by PMD.

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

Line: 12

              
public class DenyTest8 extends TestCase {

    public void test_autoTypeDeny() throws Exception {
        ParserConfig config = new ParserConfig();

        assertFalse(config.isAutoTypeSupport());
        config.setAutoTypeSupport(true);
        assertTrue(config.isAutoTypeSupport());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 15

                  public void test_autoTypeDeny() throws Exception {
        ParserConfig config = new ParserConfig();

        assertFalse(config.isAutoTypeSupport());
        config.setAutoTypeSupport(true);
        assertTrue(config.isAutoTypeSupport());

        Properties properties = new Properties();
        properties.put(ParserConfig.AUTOTYPE_SUPPORT_PROPERTY, "false");

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 17

              
        assertFalse(config.isAutoTypeSupport());
        config.setAutoTypeSupport(true);
        assertTrue(config.isAutoTypeSupport());

        Properties properties = new Properties();
        properties.put(ParserConfig.AUTOTYPE_SUPPORT_PROPERTY, "false");
        config.configFromPropety(properties);


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 23

                      properties.put(ParserConfig.AUTOTYPE_SUPPORT_PROPERTY, "false");
        config.configFromPropety(properties);

        assertFalse(config.isAutoTypeSupport());

        config.addAccept("com.alibaba.json.bvt.parser.deser.deny.DenyTest8");


        Object obj = JSON.parseObject("{\"@type\":\"com.alibaba.json.bvt.parser.deser.deny.DenyTest8$Model\"}", Object.class, config);

            

Reported by PMD.

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

Line: 29

              

        Object obj = JSON.parseObject("{\"@type\":\"com.alibaba.json.bvt.parser.deser.deny.DenyTest8$Model\"}", Object.class, config);
        assertEquals(Model.class, obj.getClass());
    }
    
    public static class Model {

    }

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 29

              

        Object obj = JSON.parseObject("{\"@type\":\"com.alibaba.json.bvt.parser.deser.deny.DenyTest8$Model\"}", Object.class, config);
        assertEquals(Model.class, obj.getClass());
    }
    
    public static class Model {

    }

            

Reported by PMD.

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

Line: 4

              package com.alibaba.json.bvt.parser.deser.deny;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.parser.ParserConfig;
import junit.framework.TestCase;

import java.util.Properties;


            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/parser/stream/JSONReaderScannerTest_enum.java
8 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 JSONReaderScannerTest_enum extends TestCase {

    public void test_a() throws Exception {
        DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner("{\"type\":\"A\"}"));
        VO vo = parser.parseObject(VO.class);
        Assert.assertEquals(Type.A, vo.getType());
        parser.close();
    }

            

Reported by PMD.

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

Line: 15

                  public void test_a() throws Exception {
        DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner("{\"type\":\"A\"}"));
        VO vo = parser.parseObject(VO.class);
        Assert.assertEquals(Type.A, vo.getType());
        parser.close();
    }

    public void test_b() throws Exception {
        DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner("{\"type\":\"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: 19

                      parser.close();
    }

    public void test_b() throws Exception {
        DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner("{\"type\":\"B\"}"));
        VO vo = parser.parseObject(VO.class);
        Assert.assertEquals(Type.B, vo.getType());
        parser.close();
    }

            

Reported by PMD.

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

Line: 22

                  public void test_b() throws Exception {
        DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner("{\"type\":\"B\"}"));
        VO vo = parser.parseObject(VO.class);
        Assert.assertEquals(Type.B, vo.getType());
        parser.close();
    }

    public void test_c() throws Exception {
        DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner("{\"type\":\"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: 26

                      parser.close();
    }

    public void test_c() throws Exception {
        DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner("{\"type\":\"C\"}"));
        VO vo = parser.parseObject(VO.class);
        Assert.assertEquals(Type.C, vo.getType());
        parser.close();
    }

            

Reported by PMD.

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

Line: 29

                  public void test_c() throws Exception {
        DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner("{\"type\":\"C\"}"));
        VO vo = parser.parseObject(VO.class);
        Assert.assertEquals(Type.C, vo.getType());
        parser.close();
    }
    
    public void test_x() throws Exception {
        DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner("{\"type\":\"XXXXXXXXXXXXXXXXXXXXXXXX\"}"));

            

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

                      parser.close();
    }
    
    public void test_x() throws Exception {
        DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner("{\"type\":\"XXXXXXXXXXXXXXXXXXXXXXXX\"}"));
        VO vo = parser.parseObject(VO.class);
        Assert.assertEquals(Type.XXXXXXXXXXXXXXXXXXXXXXXX, vo.getType());
        parser.close();
    }

            

Reported by PMD.

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

Line: 36

                  public void test_x() throws Exception {
        DefaultJSONParser parser = new DefaultJSONParser(new JSONReaderScanner("{\"type\":\"XXXXXXXXXXXXXXXXXXXXXXXX\"}"));
        VO vo = parser.parseObject(VO.class);
        Assert.assertEquals(Type.XXXXXXXXXXXXXXXXXXXXXXXX, vo.getType());
        parser.close();
    }

    public static class VO {


            

Reported by PMD.

src/test/java/com/alibaba/json/bvt/path/DeepScanTest.java
8 issues
Unit tests should not contain more than 1 assert(s).
Design

Line: 13

               * Created by wenshao on 30/07/2017.
 */
public class DeepScanTest extends TestCase {
    public void test_when_deep_scanning_illegal_property_access_is_ignored() {
        Object result = JSONPath.eval(
                JSON.parseObject("{\"x\": {\"foo\": {\"bar\": 4}}, \"y\": {\"foo\": 1}}")
                , "$..foo");
        assertEquals(2, ((List) result).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 30/07/2017.
 */
public class DeepScanTest extends TestCase {
    public void test_when_deep_scanning_illegal_property_access_is_ignored() {
        Object result = JSONPath.eval(
                JSON.parseObject("{\"x\": {\"foo\": {\"bar\": 4}}, \"y\": {\"foo\": 1}}")
                , "$..foo");
        assertEquals(2, ((List) result).size());


            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 17

                      Object result = JSONPath.eval(
                JSON.parseObject("{\"x\": {\"foo\": {\"bar\": 4}}, \"y\": {\"foo\": 1}}")
                , "$..foo");
        assertEquals(2, ((List) result).size());

        result = JSONPath.eval(
                JSON.parseObject("{\"x\": {\"foo\": {\"bar\": 4}}, \"y\": {\"foo\": 1}}")
                , "$..foo.bar");
        assertEquals(1, ((List) result).size());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 22

                      result = JSONPath.eval(
                JSON.parseObject("{\"x\": {\"foo\": {\"bar\": 4}}, \"y\": {\"foo\": 1}}")
                , "$..foo.bar");
        assertEquals(1, ((List) result).size());
        assertEquals(4, ((List) result).get(0));

        result = JSONPath.eval(
                JSON.parseObject("{\"x\": {\"foo\": {\"bar\": 4}}, \"y\": {\"foo\": 1}}")
                , "$..[*].foo.bar");

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 23

                              JSON.parseObject("{\"x\": {\"foo\": {\"bar\": 4}}, \"y\": {\"foo\": 1}}")
                , "$..foo.bar");
        assertEquals(1, ((List) result).size());
        assertEquals(4, ((List) result).get(0));

        result = JSONPath.eval(
                JSON.parseObject("{\"x\": {\"foo\": {\"bar\": 4}}, \"y\": {\"foo\": 1}}")
                , "$..[*].foo.bar");
        assertEquals(1, ((List) result).size());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 28

                      result = JSONPath.eval(
                JSON.parseObject("{\"x\": {\"foo\": {\"bar\": 4}}, \"y\": {\"foo\": 1}}")
                , "$..[*].foo.bar");
        assertEquals(1, ((List) result).size());
        assertEquals(4, ((List) result).get(0));

        result = JSONPath.eval(
                JSON.parseObject("{\"x\": {\"foo\": {\"baz\": 4}}, \"y\": {\"foo\": 1}}")
                , "$..[*].foo.bar");

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 29

                              JSON.parseObject("{\"x\": {\"foo\": {\"bar\": 4}}, \"y\": {\"foo\": 1}}")
                , "$..[*].foo.bar");
        assertEquals(1, ((List) result).size());
        assertEquals(4, ((List) result).get(0));

        result = JSONPath.eval(
                JSON.parseObject("{\"x\": {\"foo\": {\"baz\": 4}}, \"y\": {\"foo\": 1}}")
                , "$..[*].foo.bar");
        assertTrue(((List) result).isEmpty());

            

Reported by PMD.

JUnit assertions should include a message
Design

Line: 34

                      result = JSONPath.eval(
                JSON.parseObject("{\"x\": {\"foo\": {\"baz\": 4}}, \"y\": {\"foo\": 1}}")
                , "$..[*].foo.bar");
        assertTrue(((List) result).isEmpty());
    }

}

            

Reported by PMD.