package mobi.cangol.mobile;

import org.junit.Test;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.TypeVariable;
import java.util.HashMap;
import java.util.Map;

import mobi.cangol.mobile.logging.Log;
import mobi.cangol.mobile.parser.Element;
import mobi.cangol.mobile.parser.JSONParserException;
import mobi.cangol.mobile.parser.JsonUtils;
import mobi.cangol.mobile.parser.XMLParserException;
import mobi.cangol.mobile.parser.XmlUtils;

import static junit.framework.Assert.assertEquals;


/**
 * To work on unit tests, switch the Test Artifact in the Build Variants view.
 */
public class ExampleUnitTest {
    @Test
    public void test1() throws Exception {
        String jsonStr=" {\"name\":\"Nick\",\"id\":1,\"height\":1.75,\"isChild\":true,\"t\":true,\"r\":\"111\"}";
        parser(jsonStr);
    }
    private void parser(String str) {
        try {
            ParserObject<Boolean,String> test=new ParserObject<Boolean,String>();
            Class<ParserObject<Boolean,String>> clazz= (Class<ParserObject<Boolean,String>>) test.getClass();
            ParserObject tr = clazz.getDeclaredConstructor().newInstance();
            Map<String,Class> typeMap=new HashMap<String,Class>();

            for(TypeVariable type:clazz.getTypeParameters()){
                System.out.println("type:"+type.getName()+","+type.getGenericDeclaration());
            }
//            for(Method method:clazz.getDeclaredMethods()){
//                System.out.println("method:"+method.getName()+","+method.getReturnType());
//            }

            ParserObject<Boolean,String> parserObject=JsonUtils.parserToObject(clazz,str,true);
            System.out.println(parserObject.toString());

        } catch (JSONParserException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (java.lang.InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }
}
class ParserObject<T,R> {
//    @Element("t")
//    private T t;
//    @Element("r")
//    private R r;

    @Element("id")
    private int id;
    @Element("name")
    private String name;
    @Element("_HEIGHT")
    private double height;
    @Element("_IS_CHILD")
    private boolean isChild;
    public ParserObject() {

    }

//    public T getT() {
//        return t;
//    }
//
//    public void setT(T t) {
//        this.t = t;
//    }
//
//    public R getR() {
//        return r;
//    }
//
//    public void setR(R r) {
//        this.r = r;
//    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getHeight() {
        return height;
    }

    public void setHeight(double height) {
        this.height = height;
    }

    public boolean isChild() {
        return isChild;
    }

    public void setChild(boolean child) {
        isChild = child;
    }

    @Override
    public String toString() {
        return "ParserObject{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", height=" + height +
                ", isChild=" + isChild +
//                ", t=" + t +
//                ", r=" + r +
                '}';
    }
}




@@ -740,1089 +740,36 @@
 oid 
-test1() throws Exception %7B%0A        String jsonStr=%22 %7B%5C%22name%5C%22:%5C%22Nick%5C%22,%5C%22id%5C%22:1,%5C%22height%5C%22:1.75,%5C%22isChild%5C%22:true,%5C%22t%5C%22:true,%5C%22r%5C%22:%5C%22111%5C%22%7D%22;%0A        parser(jsonStr);%0A    %7D%0A    private void parser(String str) %7B%0A        try %7B%0A            ParserObject%3CBoolean,String%3E test=new ParserObject%3CBoolean,String%3E();%0A            Class%3CParserObject%3CBoolean,String%3E%3E clazz= (Class%3CParserObject%3CBoolean,String%3E%3E) test.getClass();%0A            ParserObject tr = clazz.getDeclaredConstructor().newInstance();%0A            Map%3CString,Class%3E typeMap=new HashMap%3CString,Class%3E();%0A%0A            for(TypeVariable type:clazz.getTypeParameters())%7B%0A                System.out.println(%22type:%22+type.getName()+%22,%22+type.getGenericDeclaration());%0A            %7D%0A//            for(Method method:clazz.getDeclaredMethods())%7B%0A//                System.out.println(%22method:%22+method.getName()+%22,%22+method.getReturnType());%0A//            %7D%0A%0A            ParserObject%3CBoolean,String%3E parserObject=JsonUtils.parserToObject(clazz,str,true);%0A            System.out.println(parserObject.toString());%0A%0A        %7D catch (JSONParser
+addition_isCorrect() throws 
 Exce
@@ -765,35 +765,32 @@
 throws Exception
- e)
  %7B%0A            e
@@ -788,1772 +788,30 @@
     
- 
-   e.printStackTrace();%0A        %7D catch (NoSuchMethodException e) %7B%0A            e.printStackTrace();%0A        %7D catch (java.lang.InstantiationException e) %7B%0A            e.printStackTrace();%0A        %7D catch (IllegalAccessException e) %7B%0A            e.printStackTrace();%0A        %7D catch (InvocationTargetException e) %7B%0A            e.printStackTrace();%0A        %7D%0A    %7D%0A%7D%0Aclass ParserObject%3CT,R%3E %7B%0A//    @Element(%22t%22)%0A//    private T t;%0A//    @Element(%22r%22)%0A//    private R r;%0A%0A    @Element(%22id%22)%0A    private int id;%0A    @Element(%22name%22)%0A    private String name;%0A    @Element(%22_HEIGHT%22)%0A    private double height;%0A    @Element(%22_IS_CHILD%22)%0A    private boolean isChild;%0A    public ParserObject() %7B%0A%0A    %7D%0A%0A//    public T getT() %7B%0A//        return t;%0A//    %7D%0A//%0A//    public void setT(T t) %7B%0A//        this.t = t;%0A//    %7D%0A//%0A//    public R getR() %7B%0A//        return r;%0A//    %7D%0A//%0A//    public void setR(R r) %7B%0A//        this.r = r;%0A//    %7D%0A%0A    public int getId() %7B%0A        return id;%0A    %7D%0A%0A    public void setId(int id) %7B%0A        this.id = id;%0A    %7D%0A%0A    public String getName() %7B%0A        return name;%0A    %7D%0A%0A    public void setName(String name) %7B%0A        this.name = name;%0A    %7D%0A%0A    public double getHeight() %7B%0A        return height;%0A    %7D%0A%0A    public void setHeight(double height) %7B%0A        this.height = height;%0A    %7D%0A%0A    public boolean isChild() %7B%0A        return isChild;%0A    %7D%0A%0A    public void setChild(boolean child) %7B%0A        isChild = child;%0A    %7D%0A%0A    @Override%0A    public String toString() %7B%0A        return %22ParserObject%7B%22 +%0A                %22id=%22 + id +%0A                %22, name='%22 + name + '%5C'' +%0A                %22, height=%22 + height +%0A                %22, isChild=%22 + isChild +%0A//                %22, t=%22 + t +%0A//                %22, r=%22 + r +%0A                '%7D'
+assertEquals(4, 2 + 2)
 ;%0A  

update unitest