From 71a83a67930c51e79e7af7df9870e00df01e1a93 Mon Sep 17 00:00:00 2001 From: Christian Femers Date: Tue, 4 May 2021 12:41:48 +0200 Subject: [PATCH] Improve tests for DynamicClass checks --- src/test/java/de/tum/in/test/api/DynamicsTest.java | 2 +- src/test/java/de/tum/in/testuser/DynamicsUser.java | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/test/java/de/tum/in/test/api/DynamicsTest.java b/src/test/java/de/tum/in/test/api/DynamicsTest.java index cb9fc592..23363ebc 100644 --- a/src/test/java/de/tum/in/test/api/DynamicsTest.java +++ b/src/test/java/de/tum/in/test/api/DynamicsTest.java @@ -74,7 +74,7 @@ void test_class_searchNonPrivateFields() { @TestTest void test_class_searchPublicOrProtectedMethods() { tests.assertThatEvents().haveExactly(1, testFailedWith(class_searchPublicOrProtectedMethods, - AssertionFailedError.class, "Methode throwException() ist public, sollte sie aber nicht")); + AssertionFailedError.class, "Methode doSomething(java.lang.String) ist public, sollte sie aber nicht")); } @TestTest diff --git a/src/test/java/de/tum/in/testuser/DynamicsUser.java b/src/test/java/de/tum/in/testuser/DynamicsUser.java index 8e72953d..18d09376 100644 --- a/src/test/java/de/tum/in/testuser/DynamicsUser.java +++ b/src/test/java/de/tum/in/testuser/DynamicsUser.java @@ -71,17 +71,29 @@ void class_notFound() { @Test void class_searchNonFinalFields() { + int checked = DynamicClass.toDynamic(DynamicsUser.class).checkForNonFinalFields(); + assertThat(checked).isEqualTo(12); + SomeClass.checkForNonFinalFields(); } @Test void class_searchNonPrivateFields() { + int checked = DynamicClass.toDynamic(DynamicsUser.class).checkForNonPrivateFields(); + assertThat(checked).isEqualTo(12); + SomeClass.checkForNonPrivateFields(); } @Test void class_searchPublicOrProtectedMethods() { - SomeClass.checkForPublicOrProtectedMethods(); + int checked = DynamicClass.toDynamic(SUBJECT_PACKAGE + ".SomeAbstractClass").checkForPublicOrProtectedMethods(); + assertThat(checked).isOne(); + + SomeClass.checkForPublicOrProtectedMethods(SomeClass_getSomeAttribute, SomeClass_doSomethingElse, + SomeClass_throwException, SomeClass.method(Integer.class, "getAnotherAttribute"), + SomeClass.method(void.class, "setSomeAttribute", String.class), + SomeClass.method(Class.class, "initializeFailingClass")); } @Test