Skip to content
Snippets Groups Projects
Commit e86ba804 authored by jez04's avatar jez04
Browse files

feat: update unit test

parent 0464ea00
Branches
No related merge requests found
...@@ -30,6 +30,12 @@ class ClassStructureTest { ...@@ -30,6 +30,12 @@ class ClassStructureTest {
void dataImporterTest() throws URISyntaxException, IOException, IllegalAccessException, InvocationTargetException { void dataImporterTest() throws URISyntaxException, IOException, IllegalAccessException, InvocationTargetException {
helper.classExist("DataImporter", false); helper.classExist("DataImporter", false);
Class<?> d = helper.getClass("DataImporter", false); Class<?> d = helper.getClass("DataImporter", false);
}
@Test
void dataImporterDownloadTest() throws URISyntaxException, IOException, IllegalAccessException, InvocationTargetException {
helper.classExist("DataImporter", false);
Class<?> d = helper.getClass("DataImporter", false);
String src = helper.getSourceCode(d); String src = helper.getSourceCode(d);
helper.hasMethod(d, ".*down.*", false, String.class); helper.hasMethod(d, ".*down.*", false, String.class);
Method download = helper.getMethod(d, ".*down.*", false, String.class); Method download = helper.getMethod(d, ".*down.*", false, String.class);
...@@ -42,10 +48,43 @@ class ClassStructureTest { ...@@ -42,10 +48,43 @@ class ClassStructureTest {
stringContainsInOrder("birthday") stringContainsInOrder("birthday")
)); ));
}
@Test
void dataImporterParseAllTest() throws URISyntaxException, IOException, IllegalAccessException, InvocationTargetException {
helper.classExist("DataImporter", false);
Class<?> d = helper.getClass("DataImporter", false);
String src = helper.getSourceCode(d);
helper.hasMethod(d, ".*parse.*", false, List.class, String.class); helper.hasMethod(d, ".*parse.*", false, List.class, String.class);
Method parse = helper.getMethod(d, ".*parse.*", false, List.class, String.class); Method parse = helper.getMethod(d, ".*parse.*", false, List.class, String.class);
List<String> texts = (List<String>) parse.invoke(null, "{\"id\":1,\"firstname\":\"Tatum\",\"lastname\":\"Block\",\"email\":\"lonnie.bergstrom@stoltenberg.com\",\"phone\":\"+12397191764\",\"birthday\":\"1946-11-06\",\"gender\":\"male\",\"address\":{"); List<String> texts = (List<String>) parse.invoke(null, "{\"id\":1,\"firstname\":\"Tatum\",\"lastname\":\"Block\",\"email\":\"lonnie.bergstrom@stoltenberg.com\",\"phone\":\"+12397191764\",\"birthday\":\"1946-11-06\",\"gender\":\"male\",\"address\":{");
assertThat(texts, not(empty())); assertThat(texts, not(empty()));
}
@Test
void personTest() throws URISyntaxException, IOException, IllegalAccessException, InvocationTargetException {
helper.classExist("Person", false);
Class<?> p = helper.getClass("Person", false);
}
@Test
void dataImporterParsePersonTest() throws URISyntaxException, IOException, IllegalAccessException, InvocationTargetException {
helper.classExist("DataImporter", false);
Class<?> d = helper.getClass("DataImporter", false);
String src = helper.getSourceCode(d);
helper.classExist("Person", false);
Class<?> p = helper.getClass("Person", false);
helper.hasMethod(d, ".*parse.*", false, p, String.class);
Method parsePerson = helper.getMethod(d, ".*parse.*", false, p, String.class);
Object person = parsePerson.invoke(null, "{\"id\":1,\"firstname\":\"Tatum\",\"lastname\":\"Block\",\"email\":\"lonnie.bergstrom@stoltenberg.com\",\"phone\":\"+12397191764\",\"birthday\":\"1946-11-06\",\"gender\":\"male\",\"address\":{");
assertThat(person, notNullValue());
}
@Test
void personAgeTest() throws URISyntaxException, IOException, IllegalAccessException, InvocationTargetException {
helper.classExist("DataImporter", false);
Class<?> d = helper.getClass("DataImporter", false);
helper.classExist("Person", false); helper.classExist("Person", false);
Class<?> p = helper.getClass("Person", false); Class<?> p = helper.getClass("Person", false);
...@@ -57,15 +96,43 @@ class ClassStructureTest { ...@@ -57,15 +96,43 @@ class ClassStructureTest {
Method age = helper.getMethod(p, ".*age.*", false, int.class); Method age = helper.getMethod(p, ".*age.*", false, int.class);
int result = (int)age.invoke(person); int result = (int)age.invoke(person);
assertEquals(78, result , "Calculate wrong age."); assertEquals(78, result , "Calculate wrong age.");
}
@Test
void person50birthdayTest() throws URISyntaxException, IOException, IllegalAccessException, InvocationTargetException {
helper.classExist("DataImporter", false);
Class<?> d = helper.getClass("DataImporter", false);
String src = helper.getSourceCode(d);
helper.classExist("Person", false);
Class<?> p = helper.getClass("Person", false);
helper.hasMethod(d, ".*parse.*", false, p, String.class);
Method parsePerson = helper.getMethod(d, ".*parse.*", false, p, String.class);
Object person = parsePerson.invoke(null, "{\"id\":1,\"firstname\":\"Tatum\",\"lastname\":\"Block\",\"email\":\"lonnie.bergstrom@stoltenberg.com\",\"phone\":\"+12397191764\",\"birthday\":\"1946-11-06\",\"gender\":\"male\",\"address\":{");
assertThat(person, notNullValue());
Method birth50 = helper.getMethod(p, ".*50.*", false, LocalDate.class); Method birth50 = helper.getMethod(p, ".*50.*", false, LocalDate.class);
LocalDate ldBirth50 = (LocalDate)birth50.invoke(person); LocalDate ldBirth50 = (LocalDate)birth50.invoke(person);
assertEquals(LocalDate.of(1996, 11, 06), ldBirth50 , "Calculate wrong 50th birthday."); assertEquals(LocalDate.of(1996, 11, 06), ldBirth50 , "Calculate wrong 50th birthday.");
}
@Test
void peronNextBirthdayTest() throws URISyntaxException, IOException, IllegalAccessException, InvocationTargetException {
helper.classExist("DataImporter", false);
Class<?> d = helper.getClass("DataImporter", false);
String src = helper.getSourceCode(d);
helper.classExist("Person", false);
Class<?> p = helper.getClass("Person", false);
helper.hasMethod(d, ".*parse.*", false, p, String.class);
Method parsePerson = helper.getMethod(d, ".*parse.*", false, p, String.class);
Object person = parsePerson.invoke(null, "{\"id\":1,\"firstname\":\"Tatum\",\"lastname\":\"Block\",\"email\":\"lonnie.bergstrom@stoltenberg.com\",\"phone\":\"+12397191764\",\"birthday\":\"1946-11-06\",\"gender\":\"male\",\"address\":{");
assertThat(person, notNullValue());
Method daysM = helper.getMethod(p, ".*days.*", false, long.class); Method daysM = helper.getMethod(p, ".*days.*", false, long.class);
long days= (long)daysM.invoke(person); long days= (long)daysM.invoke(person);
assertEquals(338, days , "Calculate wrong days to next birthday."); assertEquals(338, days , "Calculate wrong days to next birthday.");
} }
} }
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