-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simple and canonical name support for Structure Test Oracle files (#67)
Co-authored-by: Niclas Schümann <[email protected]> Co-authored-by: Christian Femers <[email protected]>
- Loading branch information
1 parent
08fa61b
commit 3db2afd
Showing
4 changed files
with
60 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
|
||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.Modifier; | ||
import java.lang.reflect.Type; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import java.util.ArrayList; | ||
|
@@ -21,7 +22,7 @@ | |
* or an interface or an enum and also if the class extends another superclass | ||
* and if it implements the interfaces and annotations, based on its definition | ||
* in the structure oracle (test.json). | ||
* | ||
* | ||
* @author Stephan Krusche ([email protected]) | ||
* @version 5.0 (11.11.2020) | ||
*/ | ||
|
@@ -31,7 +32,7 @@ public abstract class ClassTestProvider extends StructuralTestProvider { | |
* This method collects the classes in the structure oracle file for which at | ||
* least one class property is specified. These classes are then transformed | ||
* into JUnit 5 dynamic tests. | ||
* | ||
* | ||
* @return A dynamic test container containing the test for each class which is | ||
* then executed by JUnit. | ||
* @throws URISyntaxException an exception if the URI of the class name cannot | ||
|
@@ -80,7 +81,7 @@ protected static boolean hasAdditionalProperties(JSONObject jsonObject) { | |
* This method gets passed the expected class structure generated by the method | ||
* {@link #generateTestsForAllClasses()}, checks if the class is found at all in | ||
* the assignment and then proceeds to check its properties. | ||
* | ||
* | ||
* @param expectedClassStructure The class structure that we expect to find and | ||
* test against. | ||
*/ | ||
|
@@ -124,10 +125,11 @@ private static void checkSuperclass(String expectedClassName, Class<?> observedC | |
if (expectedClassPropertiesJSON.has(JSON_PROPERTY_SUPERCLASS) | ||
&& !expectedClassPropertiesJSON.getString(JSON_PROPERTY_SUPERCLASS).equals("Enum")) { | ||
String expectedSuperClassName = expectedClassPropertiesJSON.getString(JSON_PROPERTY_SUPERCLASS); | ||
String actualSuperClassName = observedClass.getSuperclass().getSimpleName(); | ||
String failMessage = THE_CLASS + "'" + expectedClassName + "' is not a subclass of the class '" | ||
+ expectedSuperClassName + "' as expected. Implement the class inheritance properly."; | ||
if (!expectedSuperClassName.equals(actualSuperClassName)) { | ||
|
||
if (!checkExpectedType(observedClass.getSuperclass(), observedClass.getGenericSuperclass(), | ||
expectedSuperClassName)) { | ||
String failMessage = THE_CLASS + "'" + expectedClassName + "' is not a subclass of the class '" | ||
+ expectedSuperClassName + "' as expected. Implement the class inheritance properly."; | ||
fail(failMessage); | ||
} | ||
} | ||
|
@@ -138,16 +140,14 @@ private static void checkInterfaces(String expectedClassName, Class<?> observedC | |
if (expectedClassPropertiesJSON.has(JSON_PROPERTY_INTERFACES)) { | ||
JSONArray expectedInterfaces = expectedClassPropertiesJSON.getJSONArray(JSON_PROPERTY_INTERFACES); | ||
Class<?>[] observedInterfaces = observedClass.getInterfaces(); | ||
Type[] observedGenericInterfaceTypes = observedClass.getGenericInterfaces(); | ||
for (int i = 0; i < expectedInterfaces.length(); i++) { | ||
String expectedInterface = expectedInterfaces.getString(i); | ||
boolean implementsInterface = false; | ||
for (Class<?> observedInterface : observedInterfaces) { | ||
/* | ||
* TODO: this does not work with the current implementation of the test oracle | ||
* generator (which does not print the simple but the full qualified name | ||
* including the package) | ||
*/ | ||
if (expectedInterface.equals(observedInterface.getSimpleName())) { | ||
for (int j = 0; j < observedInterfaces.length; j++) { | ||
Class<?> observedInterface = observedInterfaces[j]; | ||
Type observedGenericInterfaceType = observedGenericInterfaceTypes[j]; | ||
if (checkExpectedType(observedInterface, observedGenericInterfaceType, expectedInterface)) { | ||
implementsInterface = true; | ||
break; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters