Skip to content

Instantly share code, notes, and snippets.

@dariosalvi78
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dariosalvi78/ac884588f48ae200aa39 to your computer and use it in GitHub Desktop.
Save dariosalvi78/ac884588f48ae200aa39 to your computer and use it in GitHub Desktop.
A GWT test case for org.dt.reflector with nested classes
package pIoT.client.tests;
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import org.dt.reflector.client.PropertyUtils;
import org.dt.reflector.client.Reflectable;
import org.dt.reflector.client.Reflector;
import com.google.gwt.junit.client.GWTTestCase;
public class SimpleTestReflection extends GWTTestCase {
public SimpleTestReflection() {
}
@Override
public String getModuleName() {
return "pIoT.pIoTServer_test";
}
public static class MyClass implements Reflectable{
private int myInt;
private boolean myBool;
public MyClass(){
}
public int getMyInt() {
return myInt;
}
public void setMyInt(int myInt) {
this.myInt = myInt;
}
public boolean isMyBool() {
return myBool;
}
public void setMyBool(boolean myBool) {
this.myBool = myBool;
}
}
public void testReflection(){
MyClass myobject = new MyClass();
myobject.setMyBool(true);
myobject.setMyInt(10);
Reflector refl = PropertyUtils.getReflector(MyClass.class);
assertNotNull(refl);
List<String> props = Arrays.asList(refl.list(myobject));
assertTrue(props.contains("myInt"));
assertTrue(props.contains("myBool"));
assertEquals("10", refl.get(myobject, "myInt").toString());
assertEquals("true", refl.get(myobject, "myBool").toString());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment