Last active
August 29, 2015 14:06
-
-
Save dariosalvi78/ac884588f48ae200aa39 to your computer and use it in GitHub Desktop.
A GWT test case for org.dt.reflector with nested classes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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