diff --git a/src/test/java/jez04/structure/test/ClassStructureTest.java b/src/test/java/jez04/structure/test/ClassStructureTest.java index ae6627b178d4e7941b82a0668b30ee9100d8d5cb..aa54460024988e22b5b623712e25695e24f0dec4 100644 --- a/src/test/java/jez04/structure/test/ClassStructureTest.java +++ b/src/test/java/jez04/structure/test/ClassStructureTest.java @@ -30,6 +30,12 @@ class ClassStructureTest { void dataImporterTest() throws URISyntaxException, IOException, IllegalAccessException, InvocationTargetException { helper.classExist("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); helper.hasMethod(d, ".*down.*", false, String.class); Method download = helper.getMethod(d, ".*down.*", false, String.class); @@ -42,10 +48,43 @@ class ClassStructureTest { 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); 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\":{"); 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); Class<?> p = helper.getClass("Person", false); @@ -57,15 +96,43 @@ class ClassStructureTest { Method age = helper.getMethod(p, ".*age.*", false, int.class); int result = (int)age.invoke(person); 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); LocalDate ldBirth50 = (LocalDate)birth50.invoke(person); 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); long days= (long)daysM.invoke(person); assertEquals(338, days , "Calculate wrong days to next birthday."); } - }