package com.alibaba.json.bvt.issue_2200;

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

public class Issue2249 extends TestCase {
    public void test_for_issue() throws Exception {
        assertSame(Type.Big, JSON.parseObject("\"big\"", Type.class));
        assertSame(Type.Big, JSON.parseObject("\"Big\"", Type.class));
        assertSame(Type.Big, JSON.parseObject("\"BIG\"", Type.class));
        assertSame(Type.Small, JSON.parseObject("\"Small\"", Type.class));
        assertSame(Type.Small, JSON.parseObject("\"small\"", Type.class));
        assertSame(Type.Small, JSON.parseObject("\"SMALL\"", Type.class));
        assertSame(Type.Medium, JSON.parseObject("\"medium\"", Type.class));
        assertSame(Type.Medium, JSON.parseObject("\"MEDIUM\"", Type.class));
        assertSame(Type.Medium, JSON.parseObject("\"Medium\"", Type.class));
        assertSame(Type.Medium, JSON.parseObject("\"MediuM\"", Type.class));
    }

    public void test_for_issue_1() throws Exception {
        assertSame(Type.Big, JSON.parseObject("{\"type\":\"bIG\"}", Model.class).type);
        assertSame(Type.Big, JSON.parseObject("{\"type\":\"big\"}", Model.class).type);
        assertSame(Type.Big, JSON.parseObject("{\"type\":\"Big\"}", Model.class).type);
        assertSame(Type.Big, JSON.parseObject("{\"type\":\"BIG\"}", Model.class).type);

        assertSame(Type.Small, JSON.parseObject("{\"type\":\"Small\"}", Model.class).type);
        assertSame(Type.Small, JSON.parseObject("{\"type\":\"SmAll\"}", Model.class).type);
        assertSame(Type.Small, JSON.parseObject("{\"type\":\"small\"}", Model.class).type);
        assertSame(Type.Small, JSON.parseObject("{\"type\":\"SMALL\"}", Model.class).type);

        assertSame(Type.Medium, JSON.parseObject("{\"type\":\"Medium\"}", Model.class).type);
        assertSame(Type.Medium, JSON.parseObject("{\"type\":\"MediuM\"}", Model.class).type);
        assertSame(Type.Medium, JSON.parseObject("{\"type\":\"medium\"}", Model.class).type);
        assertSame(Type.Medium, JSON.parseObject("{\"type\":\"MEDIUM\"}", Model.class).type);
    }


    public void test_for_issue_error() throws Exception {
        Exception error = null;
        try {
            JSON.parseObject("\"xxx\"", Type.class, Feature.ErrorOnEnumNotMatch);
        } catch (JSONException e) {
            error = e;
        }
        assertNotNull(error);
    }

    public void test_for_issue_error_1() throws Exception {
        Exception error = null;
        try {
            JSON.parseObject("{\"type\":\"xxx\"}", Model.class, Feature.ErrorOnEnumNotMatch);
        } catch (JSONException e) {
            error = e;
        }
        assertNotNull(error);
    }

    public enum  Type {
        Big,Small,Medium
    }

    public static class Model {
        public Type type;
    }
}

@@ -1026,24 +1026,82 @@
 pe.class));%0A
+        assertNull(JSON.parseObject(%22%5C%22%5C%22%22, Type.class));%0A
     %7D%0A%0A    p
@@ -2243,24 +2243,99 @@
 ass).type);%0A
+        assertNull(JSON.parseObject(%22%7B%5C%22type%5C%22:%5C%22%5C%22%7D%22, Model.class).type);%0A
     %7D%0A%0A%0A    

add testcase