Commit c5172608 authored by Fabian Becker's avatar Fabian Becker

Add more tests to ToolBox and BeanInspector

parent 44d09bd9
Pipeline #62 passed with stage
......@@ -353,7 +353,7 @@ public class BeanInspector {
System.out.println(" Prop = Long" + obj.toString());
}
if (obj instanceof java.lang.Double) {
System.out.println(" Prop = Long" + obj.toString());
System.out.println(" Prop = Double" + obj.toString());
}
} catch (Exception e) {
//System.out.println(" ERROR +"+ e.getMessage());
......
package eva2.gui;
import org.junit.Before;
import org.junit.Test;
import java.lang.reflect.Method;
import static org.junit.Assert.*;
public class BeanInspectorTest {
private class TestClass {
public int getNumber() {
return 12;
}
public void doIt() {
// Do nothing
}
public String getParam(String param) {
return param;
}
}
private TestClass obj;
@Before
public void setUp() {
obj = new TestClass();
}
@Test
public void testCallIfAvailable() throws Exception {
assertEquals(12, BeanInspector.callIfAvailable(obj, "getNumber", null));
assertEquals(null, BeanInspector.callIfAvailable(obj, "doIt", null));
assertEquals("Hello", BeanInspector.callIfAvailable(obj, "getParam", new Object[]{"Hello"}));
assertNull(BeanInspector.callIfAvailable(obj, "doesNotExist", null));
}
@Test
public void testHasMethod() throws Exception {
// Existing method without parameter
Method m = BeanInspector.hasMethod(obj, "getNumber", null);
assertNotNull(m);
assertEquals("getNumber", m.getName());
// Not existing method
assertNull(BeanInspector.hasMethod(obj, "doesNotExist", null));
// Existing method with params
assertNotNull(BeanInspector.hasMethod(obj, "getParam", new Object[]{""}));
assertNotNull(BeanInspector.hasMethod(obj, "getParam", new Class[]{String.class}));
assertNull(BeanInspector.hasMethod(obj, "getParam", new Object[]{12.0}));
assertNull(BeanInspector.hasMethod(obj, "getParam", new Class[]{Double.class}));
}
@Test
public void testToClassArray() throws Exception {
assertArrayEquals(
new Class[]{String.class, Double.class, Integer.class},
BeanInspector.toClassArray(new Object[]{"", 12.0, 12})
);
}
}
\ No newline at end of file
package eva2.tools;
import org.junit.Test;
import static org.junit.Assert.*;
public class ToolBoxTest {
private enum TestEnum { first, last }
@Test
public void testAppendEnumAndArray() throws Exception {
assertArrayEquals(
new String[]{"first", "last", "some", "array"},
ToolBox.appendEnumAndArray(TestEnum.first, new String[]{"some", "array"})
);
}
@Test
public void testAppendArrays() throws Exception {
String[] array1 = {"You", "Shall"};
String[] array2 = {"Not", "Pass"};
String[] array3 = {"Gandalf", "Said"};
assertArrayEquals(
new String[]{"You", "Shall", "Not", "Pass", "Gandalf", "Said"},
ToolBox.appendArrays(array1, array2, array3)
);
}
@Test
public void testParseDoubles() throws Exception {
}
@Test
public void testToDouble() throws Exception {
assertNull(ToolBox.toDouble("DefinitelyNotADouble"));
}
@Test
public void testFilterBy() throws Exception {
}
@Test
public void testGetCols() throws Exception {
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment