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

feta: change project name and update test

parent 51d11e18
No related merge requests found
Pipeline #2505 canceled with stages
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>vsb-cs-java1</groupId> <groupId>vsb-cs-java1</groupId>
<artifactId>lab10v3</artifactId> <artifactId>lab11v3</artifactId>
<version>0.0.1-SNAPHOST</version> <version>0.0.1-SNAPHOST</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<properties> <properties>
...@@ -38,9 +38,6 @@ ...@@ -38,9 +38,6 @@
<artifactId>controlsfx</artifactId> <artifactId>controlsfx</artifactId>
<version>11.2.1</version> <version>11.2.1</version>
</dependency> </dependency>
<!-- <!--
https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api --> https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
<dependency> <dependency>
...@@ -72,6 +69,11 @@ ...@@ -72,6 +69,11 @@
<version>0.10.2</version> <version>0.10.2</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>3.0</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
</project> </project>
package jez04.structure.test; package jez04.structure.test;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.startsWith;
import static org.hamcrest.Matchers.stringContainsInOrder;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List; import java.util.List;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
class ClassStructureTest { class ClassStructureTest {
StructureHelper helper = new StructureHelper(); StructureHelper helper = new StructureHelper();
@Test @Test
void mainScreenControllerExistenceTest() { void dataImporterTest() throws URISyntaxException, IOException, IllegalAccessException, InvocationTargetException {
helper.classExist("MainScreenController"); helper.classExist("DataImporter", false);
Class<?> d = helper.getClass("DataImporter", false);
} }
@Test @Test
void mainScreenControllerFxmlTest() { void dataImporterDownloadTest() throws URISyntaxException, IOException, IllegalAccessException, InvocationTargetException {
helper.classExist("MainScreenController"); helper.classExist("DataImporter", false);
Class<?> c = helper.getClass("MainScreenController"); Class<?> d = helper.getClass("DataImporter", false);
helper.hasPropertyWithAnnotation(c, ".*", FXML.class); String src = helper.getSourceCode(d);
helper.hasMethod(d, ".*down.*", false, String.class);
Method download = helper.getMethod(d, ".*down.*", false, String.class);
String downloadedText = (String) download.invoke(null);
assertThat(downloadedText, allOf(
endsWith("}]}"),
startsWith("{\"status\":\"OK\""),
stringContainsInOrder("firstname"),
stringContainsInOrder("lastname"),
stringContainsInOrder("birthday")
));
} }
@Test @Test
void mainScreenControllerButtonActionMethodTest() { void dataImporterParseAllTest() throws URISyntaxException, IOException, IllegalAccessException, InvocationTargetException {
helper.classExist("MainScreenController"); helper.classExist("DataImporter", false);
Class<?> c = helper.getClass("MainScreenController"); Class<?> d = helper.getClass("DataImporter", false);
long count = helper.countMethodRegexp(c, ".*", void.class, ActionEvent.class); String src = helper.getSourceCode(d);
assertTrue(count > 1, "Only " + count+ " method handling button click found. Expected more then 1"); 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 @Test
void mainScreenControllerTableViewTest() { void personTest() throws URISyntaxException, IOException, IllegalAccessException, InvocationTargetException {
helper.classExist("MainScreenController"); helper.classExist("Person", false);
Class<?> c = helper.getClass("MainScreenController"); Class<?> p = helper.getClass("Person", false);
helper.hasProperty(c, ".*", TableView.class, false);
}
@Test
void mainScreenControllerTableColumnTest() {
helper.classExist("MainScreenController");
Class<?> c = helper.getClass("MainScreenController");
helper.hasProperty(c, ".*", TableColumn.class, false);
} }
@Test @Test
void dbConnectorTest() { void dataImporterParsePersonTest() throws URISyntaxException, IOException, IllegalAccessException, InvocationTargetException {
helper.classExistRegexp(".*[Dd][Bb][cC]on.*"); helper.classExist("DataImporter", false);
} Class<?> d = helper.getClass("DataImporter", false);
String src = helper.getSourceCode(d);
@Test helper.classExist("Person", false);
void dbConnectorGetAllTest() { Class<?> p = helper.getClass("Person", false);
helper.classExistRegexp(".*[Dd][Bb][cC]on.*"); helper.hasMethod(d, ".*parse.*", false, p, String.class);
Class<?> scoreClass = helper.getClassRegexp(".*[sS]core.*"); Method parsePerson = helper.getMethod(d, ".*parse.*", false, p, String.class);
Class<?> c = helper.getClassRegexp(".*[Dd][Bb][cC]on.*"); 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\":{");
helper.hasMethodRegexp(c, ".*[aA]ll.*", List.class); assertThat(person, notNullValue());
helper.hasMethodRegexp(c, ".*[iI]nsert.*", void.class, scoreClass);
}
@Test
void dbConnectorInsertTest() {
helper.classExistRegexp(".*[Dd][Bb][cC]on.*");
Class<?> scoreClass = helper.getClassRegexp(".*[sS]core.*");
Class<?> c = helper.getClassRegexp(".*[Dd][Bb][cC]on.*");
helper.hasMethodRegexp(c, ".*[iI]nsert.*", void.class, scoreClass);
} }
@Test @Test
void dbConnectorContainsJdbcTest() throws URISyntaxException, IOException { void personAgeTest() throws URISyntaxException, IOException, IllegalAccessException, InvocationTargetException {
helper.classExistRegexp(".*[Dd][Bb][cC]on.*"); helper.classExist("DataImporter", false);
Class<?> c = helper.getClassRegexp(".*[Dd][Bb][cC]on.*"); Class<?> d = helper.getClass("DataImporter", false);
String src = helper.getSourceCode(c);
assertTrue(src.contains("jdbc:"), "No usage of jdbc detect."); 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 age = helper.getMethod(p, ".*age.*", false, int.class);
int result = (int)age.invoke(person);
assertEquals(78, result , "Calculate wrong age.");
} }
@Test @Test
void dbConnectorContainsDriverManagerTest() throws URISyntaxException, IOException { void person50birthdayTest() throws URISyntaxException, IOException, IllegalAccessException, InvocationTargetException {
helper.classExistRegexp(".*[Dd][Bb][cC]on.*"); helper.classExist("DataImporter", false);
Class<?> c = helper.getClassRegexp(".*[Dd][Bb][cC]on.*"); Class<?> d = helper.getClass("DataImporter", false);
String src = helper.getSourceCode(c); String src = helper.getSourceCode(d);
assertTrue(src.contains("DriverManager"), "No usage of DriverManager detect.");
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 @Test
void dbConnectorContainsSqlTest() throws URISyntaxException, IOException { void personNextBirthdayTest() throws URISyntaxException, IOException, IllegalAccessException, InvocationTargetException {
helper.classExistRegexp(".*[Dd][Bb][cC]on.*"); helper.classExist("DataImporter", false);
Class<?> c = helper.getClassRegexp(".*[Dd][Bb][cC]on.*"); Class<?> d = helper.getClass("DataImporter", false);
String src = helper.getSourceCode(c).toLowerCase(); String src = helper.getSourceCode(d);
assertTrue(src.contains("create "), "No usage of SQL create.");
assertTrue(src.contains("select "), "No usage of SQL select."); helper.classExist("Person", false);
assertTrue(src.contains("insert "), "No usage of SQL table."); Class<?> p = helper.getClass("Person", false);
assertTrue(src.contains(" from "), "No usage of SQL from."); helper.hasMethod(d, ".*parse.*", false, p, String.class);
assertTrue(src.contains(" table"), "No usage of SQL table."); Method parsePerson = helper.getMethod(d, ".*parse.*", false, p, String.class);
LocalDate bod =LocalDate.now().plusDays(338).minusYears(10);
Object person = parsePerson.invoke(null, "{\"id\":1,\"firstname\":\"Tatum\",\"lastname\":\"Block\",\"email\":\"lonnie.bergstrom@stoltenberg.com\",\"phone\":\"+12397191764\",\"birthday\":\""+ bod.format(DateTimeFormatter.ISO_DATE) +"\",\"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.");
} }
} }
...@@ -45,11 +45,18 @@ class StructureHelper { ...@@ -45,11 +45,18 @@ class StructureHelper {
} }
public void classExist(String name) { public void classExist(String name) {
assertTrue(allClasses.stream().anyMatch(c -> c.endsWith(name)), "Class/Interface " + name + " not found"); classExist(name, true);
}
public void classExist(String name, boolean caseSensitive) {
assertTrue(allClasses.stream().anyMatch(c -> caseSensitive?c.endsWith(name):c.toLowerCase().endsWith(name.toLowerCase())), "Class/Interface " + name + " not found");
} }
public void classExistRegexp(String name) { public void classExistRegexp(String name) {
assertTrue(allClasses.stream().anyMatch(c -> c.matches(name)), "Class/Interface " + name + " not found"); classExistRegexp(name, true);
}
public void classExistRegexp(String name, boolean caseSensitive) {
assertTrue(allClasses.stream().anyMatch(c -> caseSensitive?c.matches(name):c.toLowerCase().matches(name.toLowerCase())), "Class/Interface " + name + " not found");
} }
public Class<?> getClassDirectly(String name) { public Class<?> getClassDirectly(String name) {
...@@ -57,15 +64,25 @@ class StructureHelper { ...@@ -57,15 +64,25 @@ class StructureHelper {
} }
public Class<?> getClassRegexp(String name) { public Class<?> getClassRegexp(String name) {
String className = allClasses.stream().filter(c -> c.matches(name)).findAny().orElse(null); return getClassRegexp(name, true);
}
public Class<?> getClassRegexp(String name, boolean caseSensitive) {
String className = allClasses.stream().filter(c ->
caseSensitive?
c.matches(name):
c.toLowerCase().matches(name.toLowerCase())
).findAny().orElse(null);
if (className == null) { if (className == null) {
Assertions.fail("Class " + name + " not found."); Assertions.fail("Class " + name + " not found.");
} }
return loadClass(name, className); return loadClass(name, className);
} }
public Class<?> getClass(String name) { public Class<?> getClass(String name) {
String className = allClasses.stream().filter(c -> c.endsWith(name)).findAny().orElse(null); return getClass(name, true);
}
public Class<?> getClass(String name, boolean caseSensitive) {
String className = allClasses.stream().filter(c -> caseSensitive?c.endsWith(name):c.toLowerCase().endsWith(name.toLowerCase())).findAny().orElse(null);
if (className == null) { if (className == null) {
Assertions.fail("Class " + name + " not found."); Assertions.fail("Class " + name + " not found.");
} }
...@@ -89,9 +106,12 @@ class StructureHelper { ...@@ -89,9 +106,12 @@ class StructureHelper {
} }
public void hasProperty(Class<?> classDef, String propertyNameRegexp, Class<?> type, boolean array) { public void hasProperty(Class<?> classDef, String propertyNameRegexp, Class<?> type, boolean array) {
hasProperty(classDef, propertyNameRegexp, type, array, true);
}
public void hasProperty(Class<?> classDef, String propertyNameRegexp, Class<?> type, boolean array, boolean caseSensitive) {
List<Field> fields = Arrays.asList(classDef.getDeclaredFields()); List<Field> fields = Arrays.asList(classDef.getDeclaredFields());
assertTrue(fields.stream().anyMatch(f -> { assertTrue(fields.stream().anyMatch(f -> {
if (f.getName().matches(propertyNameRegexp)) { if (caseSensitive?f.getName().matches(propertyNameRegexp):f.getName().toLowerCase().matches(propertyNameRegexp.toLowerCase())) {
if (array) { if (array) {
return f.getType().isArray() && f.getType().getComponentType().equals(type); return f.getType().isArray() && f.getType().getComponentType().equals(type);
} else { } else {
...@@ -104,9 +124,13 @@ class StructureHelper { ...@@ -104,9 +124,13 @@ class StructureHelper {
} }
public void hasPropertyWithAnnotation(Class<?> classDef, String propertyNameRegexp, Class<?> annotation) { public void hasPropertyWithAnnotation(Class<?> classDef, String propertyNameRegexp, Class<?> annotation) {
hasPropertyWithAnnotation(classDef, propertyNameRegexp, annotation, true);
}
public void hasPropertyWithAnnotation(Class<?> classDef, String propertyNameRegexp, Class<?> annotation, boolean caseSensitive) {
List<Field> fields = Arrays.asList(classDef.getDeclaredFields()); List<Field> fields = Arrays.asList(classDef.getDeclaredFields());
assertTrue( assertTrue(
fields.stream().filter(f -> f.getName().matches(propertyNameRegexp)) fields.stream().filter(f -> caseSensitive?f.getName().matches(propertyNameRegexp):f.getName().toLowerCase().matches(propertyNameRegexp.toLowerCase()))
.flatMap(f -> Arrays.asList(f.getAnnotations()).stream()).map(a -> a.annotationType()) .flatMap(f -> Arrays.asList(f.getAnnotations()).stream()).map(a -> a.annotationType())
.anyMatch(a -> a.equals(annotation)), .anyMatch(a -> a.equals(annotation)),
"No field " + propertyNameRegexp + " with annotation " + annotation.getName() + " in class " "No field " + propertyNameRegexp + " with annotation " + annotation.getName() + " in class "
...@@ -114,28 +138,39 @@ class StructureHelper { ...@@ -114,28 +138,39 @@ class StructureHelper {
} }
public void hasMethod(Class<?> interfaceDef, String methodName, Class<?> returnType) { public void hasMethod(Class<?> interfaceDef, String methodName, Class<?> returnType) {
hasMethod(interfaceDef, methodName, returnType, true);
}
public void hasMethod(Class<?> interfaceDef, String methodName, Class<?> returnType, boolean caseSensitive) {
List<Method> methods = Arrays.asList(interfaceDef.getDeclaredMethods()); List<Method> methods = Arrays.asList(interfaceDef.getDeclaredMethods());
assertTrue(methods.stream().anyMatch(m -> m.getName().contains(methodName)), "No method " + methodName); assertTrue(methods.stream().anyMatch(m -> m.getName().contains(methodName)), "No method " + methodName);
assertTrue( assertTrue(
methods.stream().filter(m -> m.getName().contains(methodName)) methods.stream().filter(m -> caseSensitive?m.getName().matches(methodName):m.getName().toLowerCase().matches(methodName.toLowerCase()))
.anyMatch(m -> m.getReturnType().equals(returnType)), .anyMatch(m -> m.getReturnType().equals(returnType)),
"Method " + methodName + " not return " + returnType.getName()); "Method " + methodName + " not return " + returnType.getName());
} }
public void hasMethod(Class<?> interfaceDef, String methodName, Class<?> returnType, Class<?>... params) { public void hasMethod(Class<?> interfaceDef, String methodName, Class<?> returnType, Class<?>... params) {
hasMethod(interfaceDef, methodName, true, returnType, params);
}
public void hasMethod(Class<?> interfaceDef, String methodName, boolean caseSensitive, Class<?> returnType, Class<?>... params) {
List<Method> methods = Arrays.asList(interfaceDef.getDeclaredMethods()); List<Method> methods = Arrays.asList(interfaceDef.getDeclaredMethods());
assertTrue(methods.stream().anyMatch(m -> m.getName().contains(methodName)), "No method " + methodName); assertTrue(methods.stream().anyMatch(m -> caseSensitive?m.getName().matches(methodName):m.getName().toLowerCase().matches(methodName.toLowerCase())), "No method " + methodName);
assertTrue( assertTrue(
methods.stream().filter(m -> m.getName().contains(methodName)) methods.stream().filter(m -> caseSensitive?m.getName().matches(methodName):m.getName().toLowerCase().matches(methodName.toLowerCase()))
.filter(m -> m.getReturnType().equals(returnType)) .filter(m -> m.getReturnType().equals(returnType))
.anyMatch(m -> Arrays.asList(m.getParameterTypes()).containsAll(Arrays.asList(params))), .anyMatch(m -> Arrays.asList(m.getParameterTypes()).containsAll(Arrays.asList(params))),
"Method " + methodName + " has no all parrams:" "Method " + methodName + " has no all parrams:"
+ Arrays.asList(params).stream().map(Class::getName).collect(Collectors.joining(", "))); + Arrays.asList(params).stream().map(Class::getName).collect(Collectors.joining(", ")));
} }
public Method getMethod(Class<?> interfaceDef, String methodName, Class<?> returnType, Class<?>... params) { public Method getMethod(Class<?> interfaceDef, String methodName,Class<?> returnType, Class<?>... params) {
return getMethod(interfaceDef, methodName, true, returnType, params);
}
public Method getMethod(Class<?> interfaceDef, String methodName, boolean caseSensitive, Class<?> returnType, Class<?>... params) {
List<Method> methods = Arrays.asList(interfaceDef.getDeclaredMethods()); List<Method> methods = Arrays.asList(interfaceDef.getDeclaredMethods());
List<Method> foundMethods = methods.stream().filter(m -> m.getName().contains(methodName)) List<Method> foundMethods = methods.stream().filter(m -> caseSensitive?m.getName().matches(methodName):m.getName().toLowerCase().matches(methodName.toLowerCase()))
.filter(m -> m.getReturnType().equals(returnType)) .filter(m -> m.getReturnType().equals(returnType))
.filter(m -> Arrays.asList(m.getParameterTypes()).containsAll(Arrays.asList(params))).toList(); .filter(m -> Arrays.asList(m.getParameterTypes()).containsAll(Arrays.asList(params))).toList();
if (foundMethods.isEmpty()) { if (foundMethods.isEmpty()) {
...@@ -148,8 +183,12 @@ class StructureHelper { ...@@ -148,8 +183,12 @@ class StructureHelper {
} }
public long countMethodRegexp(Class<?> interfaceDef, String methodNameRegexp) { public long countMethodRegexp(Class<?> interfaceDef, String methodNameRegexp) {
return countMethodRegexp(interfaceDef, methodNameRegexp, true);
}
public long countMethodRegexp(Class<?> interfaceDef, String methodNameRegexp, boolean caseSensitive) {
List<Method> methods = Arrays.asList(interfaceDef.getDeclaredMethods()); List<Method> methods = Arrays.asList(interfaceDef.getDeclaredMethods());
return methods.stream().filter(m -> m.getName().matches(methodNameRegexp)).count(); return methods.stream().filter(m -> caseSensitive?m.getName().matches(methodNameRegexp):m.getName().toLowerCase().matches(methodNameRegexp.toLowerCase())).count();
} }
public long countMethodReference(Class<?> interfaceDef) throws URISyntaxException, IOException { public long countMethodReference(Class<?> interfaceDef) throws URISyntaxException, IOException {
...@@ -170,7 +209,10 @@ class StructureHelper { ...@@ -170,7 +209,10 @@ class StructureHelper {
} }
public long countClassesRegexp(String classNameRegexp) { public long countClassesRegexp(String classNameRegexp) {
return getNameOfAllClasses().stream().filter(className -> className.matches(classNameRegexp)).count(); return countClassesRegexp(classNameRegexp, true);
}
public long countClassesRegexp(String classNameRegexp, boolean caseSensitive) {
return getNameOfAllClasses().stream().filter(className -> caseSensitive?className.matches(classNameRegexp):className.toLowerCase().matches(classNameRegexp.toLowerCase())).count();
} }
public void hasConstructor(Class<?> classDef, Class<?>... params) { public void hasConstructor(Class<?> classDef, Class<?>... params) {
...@@ -192,14 +234,19 @@ class StructureHelper { ...@@ -192,14 +234,19 @@ class StructureHelper {
} }
return foundConstructors.get(0); return foundConstructors.get(0);
} }
public void hasMethodRegexp(Class<?> interfaceDef, String methodNameRegexp, Class<?> returnType, public void hasMethodRegexp(Class<?> interfaceDef, String methodNameRegexp, Class<?> returnType,
Class<?>... params) { Class<?>... params) {
hasMethodRegexp(interfaceDef, methodNameRegexp, true, returnType, params);
}
public void hasMethodRegexp(Class<?> interfaceDef, String methodNameRegexp, boolean caseSensitive, Class<?> returnType,
Class<?>... params) {
List<Method> methods = Arrays.asList(interfaceDef.getDeclaredMethods()); List<Method> methods = Arrays.asList(interfaceDef.getDeclaredMethods());
assertTrue(methods.stream().anyMatch(m -> m.getName().matches(methodNameRegexp)), assertTrue(methods.stream().anyMatch(m -> caseSensitive?m.getName().matches(methodNameRegexp):m.getName().toLowerCase().matches(methodNameRegexp.toLowerCase())),
"No method " + methodNameRegexp); "No method " + methodNameRegexp);
assertTrue( assertTrue(
methods.stream().filter(m -> m.getName().matches(methodNameRegexp)) methods.stream().filter(m -> caseSensitive?m.getName().matches(methodNameRegexp):m.getName().toLowerCase().matches(methodNameRegexp.toLowerCase()))
.filter(m -> m.getReturnType().equals(returnType)) .filter(m -> m.getReturnType().equals(returnType))
.anyMatch(m -> Arrays.asList(m.getParameterTypes()).containsAll(Arrays.asList(params))), .anyMatch(m -> Arrays.asList(m.getParameterTypes()).containsAll(Arrays.asList(params))),
"Method " + methodNameRegexp + " has no all parrams:" "Method " + methodNameRegexp + " has no all parrams:"
...@@ -208,20 +255,30 @@ class StructureHelper { ...@@ -208,20 +255,30 @@ class StructureHelper {
public long countMethodRegexp(Class<?> interfaceDef, String methodNameRegexp, Class<?> returnType, public long countMethodRegexp(Class<?> interfaceDef, String methodNameRegexp, Class<?> returnType,
Class<?>... params) { Class<?>... params) {
return countMethodRegexp(interfaceDef, methodNameRegexp, true, returnType, params);
}
public long countMethodRegexp(Class<?> interfaceDef, String methodNameRegexp, boolean caseSensitive, Class<?> returnType,
Class<?>... params) {
List<Method> methods = Arrays.asList(interfaceDef.getDeclaredMethods()); List<Method> methods = Arrays.asList(interfaceDef.getDeclaredMethods());
assertTrue(methods.stream().anyMatch(m -> m.getName().matches(methodNameRegexp)), assertTrue(methods.stream().anyMatch(m -> caseSensitive?m.getName().matches(methodNameRegexp):m.getName().toLowerCase().matches(methodNameRegexp.toLowerCase())),
"No method " + methodNameRegexp); "No method " + methodNameRegexp);
return methods.stream().filter(m -> m.getName().matches(methodNameRegexp)) return methods.stream().filter(m -> caseSensitive?m.getName().matches(methodNameRegexp):m.getName().toLowerCase().matches(methodNameRegexp.toLowerCase()))
.filter(m -> m.getReturnType().equals(returnType)) .filter(m -> m.getReturnType().equals(returnType))
.filter(m -> Arrays.asList(m.getParameterTypes()).containsAll(Arrays.asList(params))).count(); .filter(m -> Arrays.asList(m.getParameterTypes()).containsAll(Arrays.asList(params))).count();
} }
public void hasMethod(Class<?> interfaceDef, boolean finalTag, boolean abstractTag, String methodName, public void hasMethod(Class<?> interfaceDef, boolean finalTag, boolean abstractTag, String methodName,
Class<?> returnType, Class<?>... params) { Class<?> returnType, Class<?>... params) {
hasMethod(interfaceDef, finalTag, abstractTag, methodName, true, returnType, params);
}
public void hasMethod(Class<?> interfaceDef, boolean finalTag, boolean abstractTag, String methodName, boolean caseSensitive,
Class<?> returnType, Class<?>... params) {
List<Method> methods = Arrays.asList(interfaceDef.getDeclaredMethods()); List<Method> methods = Arrays.asList(interfaceDef.getDeclaredMethods());
assertTrue(methods.stream().anyMatch(m -> m.getName().contains(methodName)), "No method " + methodName); assertTrue(methods.stream().anyMatch(m -> caseSensitive?m.getName().matches(methodName):m.getName().toLowerCase().matches(methodName.toLowerCase())), "No method " + methodName);
assertTrue( assertTrue(
methods.stream().filter(m -> m.getName().contains(methodName)) methods.stream().filter(m -> caseSensitive?m.getName().matches(methodName):m.getName().toLowerCase().matches(methodName.toLowerCase()))
.filter(m -> m.getReturnType().equals(returnType) .filter(m -> m.getReturnType().equals(returnType)
&& (Modifier.isAbstract(m.getModifiers()) == abstractTag) && (Modifier.isAbstract(m.getModifiers()) == abstractTag)
&& (Modifier.isFinal(m.getModifiers()) == finalTag)) && (Modifier.isFinal(m.getModifiers()) == finalTag))
...@@ -249,8 +306,12 @@ class StructureHelper { ...@@ -249,8 +306,12 @@ class StructureHelper {
} }
public void hasMethod(Class<?> interfaceDef, String methodName) { public void hasMethod(Class<?> interfaceDef, String methodName) {
hasMethod(interfaceDef, methodName, true);
}
public void hasMethod(Class<?> interfaceDef, String methodName, boolean caseSensitive) {
List<Method> methods = Arrays.asList(interfaceDef.getMethods()); List<Method> methods = Arrays.asList(interfaceDef.getMethods());
assertTrue(methods.stream().anyMatch(m -> m.getName().contains(methodName)), "No method " + methodName); assertTrue(methods.stream().anyMatch(m -> caseSensitive?m.getName().matches(methodName):m.getName().toLowerCase().matches(methodName.toLowerCase())), "No method " + methodName);
} }
public String getSourceCode(Class<?> clazz) throws URISyntaxException, IOException { public String getSourceCode(Class<?> clazz) throws URISyntaxException, IOException {
......
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