package com.alibaba.json.bvt.issue_2400;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.PropertyNamingStrategy;
import com.alibaba.fastjson.serializer.SerializeConfig;
import junit.framework.TestCase;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@Data
public class Issue2428 extends TestCase {
    private String myName;
    private NestedBean nestedBean;

    @AllArgsConstructor
    @Data
    public static class NestedBean {
        private String myId;
    }

    public void test_for_issue() {
        Issue2428 demoBean = new Issue2428();
        demoBean.setMyName("test name");
        demoBean.setNestedBean(new NestedBean("test id"));
        assertEquals("{\"nestedBean\":{\"myId\":\"test id\"},\"myName\":\"test name\"}", JSON.toJSON(demoBean).toString());

        SerializeConfig serializeConfig = new SerializeConfig();
        serializeConfig.propertyNamingStrategy = PropertyNamingStrategy.SnakeCase;

        assertEquals("{\"my_name\":\"test name\",\"nested_bean\":{\"my_id\":\"test id\"}}", JSON.toJSON(demoBean, serializeConfig).toString());
    }
}

@@ -177,16 +177,74 @@
 Config;%0A
+import com.alibaba.fastjson.serializer.SerializerFeature;%0A
 import j
@@ -786,121 +786,186 @@
     
-assertEquals(%22%7B%5C%22nestedBean%5C%22:%7B%5C%22myId%5C%22:%5C%22test id%5C%22%7D,%5C%22myName%5C%22:%5C%22test name%5C%22%7D%22, JSON.toJSON(demoBean).toString()
+String text = JSON.toJSONString(JSON.toJSON(demoBean), SerializerFeature.SortField);%0A        assertEquals(%22%7B%5C%22myName%5C%22:%5C%22test name%5C%22,%5C%22nestedBean%5C%22:%7B%5C%22myId%5C%22:%5C%22test id%5C%22%7D%7D%22, text
 );%0A%0A
@@ -1112,16 +1112,118 @@
 keCase;%0A
+        text = JSON.toJSONString(JSON.toJSON(demoBean, serializeConfig), SerializerFeature.SortField);
 %0A       
@@ -1311,57 +1311,12 @@
 %7D%22, 
-JSON.toJSON(demoBean, serializeConfig).toString()
+text
 );%0A 

Fix flaky testcase for issue#2428