Skip to content

Commit

Permalink
1.2.33-SNAPSHOT
Browse files Browse the repository at this point in the history
  • Loading branch information
wenshao committed May 9, 2017
1 parent 01d2583 commit d3687b7
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 129 deletions.
97 changes: 97 additions & 0 deletions src/test/java/com/alibaba/json/bvt/annotation/AnnotationTest.java
@@ -0,0 +1,97 @@
package com.alibaba.json.bvt.annotations;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import junit.framework.TestCase;
import sun.reflect.annotation.AnnotationType;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.Map;

/**
* Created by Helly on 2017/04/10.
*/
public class AnnotationTest extends TestCase {

public void test_annoation() throws Exception {
Bob bob = new Bob("Bob", 30, true);
JSONObject obj = (JSONObject) JSON.toJSON(bob);
assertEquals(3, obj.size());
assertEquals(Boolean.TRUE, obj.get("sex"));
assertEquals("Bob", obj.get("name"));
assertEquals(new Integer(30), obj.get("age"));

PersonInfo info = Bob.class.getAnnotation(PersonInfo.class);
obj = (JSONObject) JSON.toJSON(info);

assertEquals(3, obj.size());
assertEquals(Boolean.TRUE, obj.get("sex"));
assertEquals("Bob", obj.get("name"));
assertEquals(new Integer(30), obj.get("age"));
}

@PersonInfo(name = "Bob", age = 30, sex = true)
public static class Bob implements Person {
private String name;
private int age;
private boolean sex;

public String getName() {
return name;
}

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

public int getAge() {
return age;
}

public void setAge(int age) {
this.age = age;
}

public boolean isSex() {
return sex;
}

public void setSex(boolean sex) {
this.sex = sex;
}

public Bob() {
}

public Bob(String name, int age, boolean sex) {
this();
this.name = name;
this.age = age;
this.sex = sex;
}

public void hello() {
System.out.println("world");
}
}

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public static @interface PersonInfo {
String name();
int age();
boolean sex();
}


public static interface Person {
void hello();
}

}
55 changes: 0 additions & 55 deletions src/test/java/demo/annotations/AnnotationTest.java

This file was deleted.

49 changes: 0 additions & 49 deletions src/test/java/demo/annotations/Bob.java

This file was deleted.

8 changes: 0 additions & 8 deletions src/test/java/demo/annotations/Person.java

This file was deleted.

17 changes: 0 additions & 17 deletions src/test/java/demo/annotations/PersonInfo.java

This file was deleted.

0 comments on commit d3687b7

Please sign in to comment.