Do unit tests right

This commit is contained in:
Mark Vainomaa 2016-12-16 16:59:08 +02:00
parent 0d6b255187
commit 3b3e6e1bcf

View File

@ -10,8 +10,8 @@ import java.lang.reflect.Method;
public class TestReflect { public class TestReflect {
@Test @Test
public void testGetClass(){ public void testGetClass(){
Assert.assertEquals(Reflect.getClass("java.lang.String"), String.class); Assert.assertEquals(String.class, Reflect.getClass("java.lang.String"));
Assert.assertNotEquals(Reflect.getClass("java.lang.Integer"), String.class); Assert.assertNotEquals(String.class, Reflect.getClass("java.lang.Integer"));
} }
@Test @Test
@ -34,7 +34,7 @@ public class TestReflect {
Class reflectClass = Reflect.getClass("eu.mikroskeem.utils.reflect.Reflect"); Class reflectClass = Reflect.getClass("eu.mikroskeem.utils.reflect.Reflect");
Method method = Reflect.getMethod(reflectClass, "getClass", String.class); Method method = Reflect.getMethod(reflectClass, "getClass", String.class);
Class<?> resultClazz = (Class)Reflect.invokeMethod(method, null, "java.lang.String"); Class<?> resultClazz = (Class)Reflect.invokeMethod(method, null, "java.lang.String");
Assert.assertEquals(resultClazz, String.class); Assert.assertEquals(String.class, resultClazz);
} }
@Test @Test
@ -51,7 +51,7 @@ public class TestReflect {
Class reflectTestClass = Reflect.getClass("eu.mikroskeem.utils.test.reflect.ReflectionTestClass"); Class reflectTestClass = Reflect.getClass("eu.mikroskeem.utils.test.reflect.ReflectionTestClass");
Field foobarField = Reflect.getField(reflectTestClass, "FOOBAR"); Field foobarField = Reflect.getField(reflectTestClass, "FOOBAR");
String value = (String)Reflect.readField(foobarField, null); String value = (String)Reflect.readField(foobarField, null);
Assert.assertEquals(value, "nope"); Assert.assertEquals("nope", value);
} }
@Test @Test
@ -60,6 +60,6 @@ public class TestReflect {
Field bazfed = Reflect.getField(reflectTestClass, "BAZFED"); Field bazfed = Reflect.getField(reflectTestClass, "BAZFED");
Reflect.writeField(bazfed, null, "no yeah man :("); Reflect.writeField(bazfed, null, "no yeah man :(");
String value = (String)Reflect.readField(bazfed, null); String value = (String)Reflect.readField(bazfed, null);
Assert.assertEquals(value, "no yeah man :("); Assert.assertEquals("no yeah man :(", value);
} }
} }