wrote more comments

This commit is contained in:
JonathanFleischmann 2024-07-03 22:34:46 +02:00
parent 09319df7f4
commit 8b18447e3f
33 changed files with 1681 additions and 100 deletions

View File

@ -24,8 +24,7 @@
durch den Compiler mithilfe des Tools prüfen
- Hinzufügen von Testfiles, die bei der Umwandlung fehlschlagen sollen
- Implementierung von Tests, die prüfen, ob der Compiler bei den fehlerhaften Testfiles tatsächlich fehlschlägt
[//]: # (TODO: - Dokumentation der Tests)
- Dokumentation der Tests
## Besonderheiten unserer Implementierung
@ -39,6 +38,7 @@
## Aufbau der Tests
### Tests für den Scanner, Parser und Typechecker:
- Die Testfiles (.java), die alle Features abdecken, sind im Ordner `src/test/testFiles/ASTandTypedASTFeatures` zu finden.
Ihr Name gibt circa an, welches Feature / welche Features sie abdecken
@ -51,19 +51,21 @@
- Weitere Testfiles, die nicht unbedingt auf ein bestimmtes Feature abzielen, sind im Ordner `src/test/testFiles/MoreTestFiles`
zu finden, die manuell übersetzen ASTs und TypedASTs dazu sind im Ordner `src/test/java/MoreTestResources` zu finden.
Die korrekte Umwandlung dieser Testfiles in AST und TypedAST wird ebenfalls durch die Klassen `src/test/java/ScannerParserTests.java`
und `src/test/java/TypingTests.java` geprüft, jedoch sind die Unit-Tests hier nicht vollständig
und `src/test/java/TypingTests.java` geprüft, jedoch sind die Unit-Tests hier nicht vollständig.
### Tests für den gesamten Compiler:
- Da die Kompilierung der Testfiles für den Scanner, Parser und Typechecker teilweise nicht gut mit Reflections testbar ist,
gibt es extra Testfiles für das Testen des Compilers im Ordner `src/test/testFiles/E2EFeatures`
- Jedes der Testfiles hat eine eigene Testklasse, welche sich im Ordner `src/test/java/E2ETests/Features` befindet. Diese
Testklassen haben jeweils einen Namen, der sich aus `ByteCode_` und dem Namen des Testfiles zusammensetzt. Sie prüfen
Testklassen haben jeweils einen Namen, der sich aus `E2E_` und dem Namen des Testfiles zusammensetzt. Sie prüfen
mithilfe der Hilfsklasse `src/test/java/E2ETests/BytecodeTestUtil.java`, ob der Compiler die Testfiles korrekt in
class-Files umwandelt. Die Hilfsklasse erstellt ein Objekt der Klasse und implementiert Methoden, welche mit Reflections
Werte aus dem Objekt auslesen und zurückgeben. Diese Werte werden dann mit den erwarteten Werten in der jeweiligen
Testklasse verglichen.
class-Files umwandelt. Die Hilfsklasse erstellt ein Class<?>-Objekt der Klasse und implementiert Methoden, welche mit
Reflections Werte aus dem Objekt auslesen und zurückgeben. Diese Werte werden dann mit den erwarteten Werten in der
jeweiligen Testklasse verglichen.
- Die Klasse `src/test/java/AllE2ETests.java` führt mithilfe der Klasse `src/test/java/HelpClasses/TestFileTester.java`
alle Testklassen für die E2E-Tests der einzelnen Features aus und gibt deren Ergebnis aus. Somit muss für das E2E-Testen
der gesamten Features nur diese Klasse ausgeführt werden.
### Negative Tests:
- Um zu überprüfen, dass der Compiler auch bei fehlerhaften Testfiles fehlschlägt, gibt es Testfiles im Ordner
`src/test/testFiles/Negative`, welche nicht korrekt kompiliert werden können. Die Testfiles sin in mehrere Kategorien

View File

@ -4,6 +4,7 @@ import java.util.HashMap;
import java.util.Map;
public class ByteClassLoader extends ClassLoader {
// TODO: Use or remove this class
// Map to store the class name and its corresponding byte array
private final Map<String, byte[]> classesBytes = new HashMap<>();

View File

@ -13,13 +13,30 @@ import java.util.logging.Logger;
public class BytecodeTestUtil {
/**
* Class object representing the class that was compiled and can be analysed using reflection
*/
private final Class<?> clazz;
/**
* Object of the class that was compiled to help testing values of fields
*/
private final Object instance;
/**
* Logger to log exceptions
*/
private static final Logger LOGGER = Logger.getLogger(BytecodeTestUtil.class.getName());
public BytecodeTestUtil(List<String> sourceFilePaths, String className) throws Exception {
byte[] resultBytecode = Compiler.generateByteCodeArrayFromFiles(sourceFilePaths).get(0);
/**
* Constructor to compile the source files, load the Class<?>-Object and create an instance of the class
* @param sourceFilePath Path to the source file to be compiled
* @param className Name of the class to be loaded into the Class<?>-Object and create an instance of
* @throws Exception If any exception occurs
*/
public BytecodeTestUtil(String sourceFilePath, String className) throws Exception {
// Generate bytecode from source file
byte[] resultBytecode = Compiler.generateByteCodeArrayFromFiles(List.of(sourceFilePath)).get(0);
// Custom class loader to load the class
ClassLoader classLoader = new ClassLoader() {
@Override
protected Class<?> findClass(String name) {
@ -27,6 +44,7 @@ public class BytecodeTestUtil {
}
};
// Load the class and create an instance of it or throw an exception if it fails
try {
clazz = classLoader.loadClass(className);
this.instance = clazz.getDeclaredConstructor().newInstance();
@ -36,12 +54,18 @@ public class BytecodeTestUtil {
}
}
/**
* Get the number of constructors of the class
* @return Number of constructors
*/
public int getConstructorCount() {
return clazz.getDeclaredConstructors().length;
}
/**
* Get the names of the constructors of the class
* @return List of constructor names
*/
public List<String> getConstructorNames() {
List<String> constructorNames = new ArrayList<>();
for (Constructor<?> constructor : clazz.getDeclaredConstructors()) {
@ -50,14 +74,29 @@ public class BytecodeTestUtil {
return constructorNames;
}
/**
* Get the number of parameters of a constructor
* @param index Index of the constructor
* @return Number of parameters
*/
public int getConstructorParameterCount(int index) {
return clazz.getDeclaredConstructors()[index].getParameterCount();
}
/**
* Get the types of the parameters of a constructor
* @param parameterTypes Array of parameter types the constructor should have
* @return Number of parameters
*/
public int getConstructorParameterCount(Class<?>[] parameterTypes) throws Exception {
return clazz.getDeclaredConstructor(parameterTypes).getParameterCount();
}
/**
* Get the types of the parameters of a constructor
* @param index Index of the constructor
* @return List of parameter types as strings
*/
public List<String> getConstructorParameterTypes(int index) {
List<String> parameterTypes = new ArrayList<>();
for (Class<?> parameterType : clazz.getDeclaredConstructors()[index].getParameterTypes()) {
@ -66,16 +105,29 @@ public class BytecodeTestUtil {
return parameterTypes;
}
/**
* Invoke a constructor of the class
* @param parameterTypes Array of parameter types the constructor should have
* @param args Arguments to be passed to the constructor
* @return Object created by the constructor
*/
public Object invokeConstructor(Class<?>[] parameterTypes, Object... args) throws Exception {
return clazz.getDeclaredConstructor(parameterTypes).newInstance(args);
}
/**
* Get the number of methods of the class
* @return Number of methods
*/
public int getMethodCount() {
return clazz.getDeclaredMethods().length;
}
/**
* Get the names of the methods of the class
* @return List of method names
*/
public List<String> getMethodNames() {
List<String> methodNames = new ArrayList<>();
for (Method method : clazz.getDeclaredMethods()) {
@ -84,6 +136,12 @@ public class BytecodeTestUtil {
return methodNames;
}
/**
* Get the return type of method
* @param methodName Name of the method
* @param params Array of parameter types the method should have
* @return Return type of the method
*/
public String getMethodReturnType(String methodName, Class<?>... params) throws Exception {
try {
return clazz.getMethod(methodName, params).getReturnType().getSimpleName();
@ -93,6 +151,12 @@ public class BytecodeTestUtil {
}
}
/**
* Get the number of parameters of a method
* @param methodName Name of the method
* @param params Array of parameter types the method should have
* @return Number of parameters
*/
public int getMethodParameterCount(String methodName, Class<?>... params) throws Exception {
try {
return clazz.getMethod(methodName, params).getParameterCount();
@ -102,6 +166,12 @@ public class BytecodeTestUtil {
}
}
/**
* Get the types of the parameters of a method
* @param methodName Name of the method
* @param params Array of parameter types the method should have
* @return List of parameter types as strings
*/
public List<String> getMethodParameterTypes(String methodName, Class<?>... params) {
try {
List<String> parameterTypes = new ArrayList<>();
@ -115,6 +185,13 @@ public class BytecodeTestUtil {
}
}
/**
* Invoke a method of the class with the given name and parameters, execute it on the instance and return the result
* @param methodName Name of the method
* @param parameterTypes Array of parameter types the method should have
* @param args Arguments to be passed to the method
* @return Object returned by the method
*/
public Object invokeMethod(String methodName, Class<?>[] parameterTypes, Object... args) throws Exception {
try {
Method method = clazz.getMethod(methodName, parameterTypes);
@ -126,11 +203,18 @@ public class BytecodeTestUtil {
}
/**
* Get the number of fields of the class
* @return Number of fields
*/
public int getFieldCount() {
return clazz.getDeclaredFields().length;
}
/**
* Get the names of the fields of the class
* @return List of field names
*/
public List<String> getFieldNames() {
List<String> fieldNames = new ArrayList<>();
for (Field field : clazz.getDeclaredFields()) {
@ -139,6 +223,10 @@ public class BytecodeTestUtil {
return fieldNames;
}
/**
* Get the types of the fields of the class
* @return List of field types
*/
public List<String> getFieldTypes() {
List<String> fieldTypes = new ArrayList<>();
for (Field field : clazz.getDeclaredFields()) {
@ -147,6 +235,11 @@ public class BytecodeTestUtil {
return fieldTypes;
}
/**
* Get the value of a field of the class in the instance
* @param fieldName Name of the field
* @return Value of the field
*/
public Object getFieldValue(String fieldName) throws Exception {
try {
return clazz.getField(fieldName).get(instance);
@ -156,10 +249,24 @@ public class BytecodeTestUtil {
}
}
/**
* Set the value of a field of the class in the instance
* @param fieldName Name of the field
* @param value Value to be set
*/
public void setFieldValue(String fieldName, Object value) throws Exception {
clazz.getField(fieldName).set(instance, value);
}
/**
* Get the value of a field of an object by reflection
* @param obj Object to get the field value from
* @param fieldName Name of the field
* @return Value of the field
*/
public Object getFieldValueOfObject(Object obj, String fieldName) {
try {
Field field = obj.getClass().getField(fieldName);

View File

@ -5,6 +5,7 @@ import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.Opcodes;
public class ClassNameExtractor {
// TODO: Use or remove this class
public static String getClassName(byte[] classBytes) {
ClassReader classReader = new ClassReader(classBytes);

View File

@ -5,29 +5,43 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import E2ETests.BytecodeTestUtil;
import java.util.List;
/**
* Test class for testing if the compilation of the class 'Break' at src/test/testFiles/E2EFeatures/Break.java was successful,
* if the class contains the expected fields, methods and constructors and works as expected
*/
public class E2E_Break {
/**
* The BytecodeTestUtil instance for the test class, which provides methods for testing the compiled class
*/
private BytecodeTestUtil util;
/**
* Initializes the BytecodeTestUtil instance for the test class
*/
@BeforeEach
public void setUp() {
try {
util = new BytecodeTestUtil(List.of("src/test/testFiles/E2EFeatures/Break.java"), "Break");
util = new BytecodeTestUtil("src/test/testFiles/E2EFeatures/Break.java", "Break");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Tests the number of constructors in the class, expecting 1 constructor, which is the default constructor
*/
@Test
public void testConstructorCount() {
Assertions.assertEquals(1, util.getConstructorCount());
// default constructor
}
/**
* Tests name, parameter count and type of the returned object of the default constructor,
* expecting the default constructor to be named "Break", not to have any parameters and to return an object of type Break
*/
@Test
public void testDefaultConstructor() {
Assertions.assertEquals("Break", util.getConstructorNames().get(0));
@ -39,18 +53,25 @@ public class E2E_Break {
}
}
/**
* Tests the number of methods in the class, expecting 1 method
*/
@Test
public void testMethodCount() {
Assertions.assertEquals(1, util.getMethodCount());
}
/**
* Tests the names of the methods in the class, expecting the method "breakMethod"
*/
@Test
public void testMethodNames() {
Assertions.assertTrue(util.getMethodNames().contains("breakMethod"));
}
/**
* Tests the return type of the method "breakMethod", expecting "void"
*/
@Test
public void testMethodReturnType() {
try {
@ -60,6 +81,9 @@ public class E2E_Break {
}
}
/**
* Tests the number of parameters of the method "breakMethod", expecting 1 parameter, which is of type boolean
*/
@Test
public void testMethodParameters() {
try {
@ -70,23 +94,36 @@ public class E2E_Break {
}
}
/**
* Tests the number of fields in the class, expecting 2 fields
*/
@Test
public void testFieldCount() {
Assertions.assertEquals(2, util.getFieldCount());
}
/**
* Tests the names of the fields in the class, expecting the fields "whileRepetition" and "forRepetition"
*/
@Test
public void testFieldNames() {
Assertions.assertTrue(util.getFieldNames().contains("whileRepetition"));
Assertions.assertTrue(util.getFieldNames().contains("forRepetition"));
}
/**
* Tests the types of the fields in the class, expecting both fields to be of type int
*/
@Test
public void testFieldTypes() {
Assertions.assertEquals("int", util.getFieldTypes().get(0));
Assertions.assertEquals("int", util.getFieldTypes().get(1));
}
/**
* Tests the values of the fields in the class, expecting both fields to be initialized with 0
*/
@Test
public void testFieldValues() {
try {
@ -98,7 +135,10 @@ public class E2E_Break {
}
/**
* Tests the invocation of the default constructor, expecting the returned object to be of type Break and the fields
* to be initialized with 0 (constructor does not contain any initialization code)
*/
@Test
public void testInvokeDefaultConstructor() {
try {
@ -111,6 +151,11 @@ public class E2E_Break {
}
}
/**
* Tests the invocation of the method "breakMethod" with the parameter false, expecting the fields "whileRepetition"
* and "forRepetition" to be 0 before the method invocation and 10 after the method invocation
* (the method contains a while loop and a for loop with 10 iterations each and does not break the loop)
*/
@Test
public void testInvokeBreakMethodWithFalse() {
try {
@ -124,6 +169,11 @@ public class E2E_Break {
}
}
/**
* Tests the invocation of the method "breakMethod" with the parameter true, expecting the fields "whileRepetition"
* and "forRepetition" to be 0 before the method invocation and 5 after the method invocation
* (the method should break each loop after 5 iterations)
*/
@Test
public void testInvokeBreakMethodWithTrue() {
try {

View File

@ -5,28 +5,43 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import E2ETests.BytecodeTestUtil;
import java.util.List;
/**
* Test class for testing if the compilation of the class 'Class' at src/test/testFiles/E2EFeatures/Class.java was successful,
* if the class contains the expected fields, methods and constructors and works as expected
*/
public class E2E_Class {
/**
* The BytecodeTestUtil instance for the test class, which provides methods for testing the compiled class
*/
private BytecodeTestUtil util;
/**
* Initializes the BytecodeTestUtil instance for the test class
*/
@BeforeEach
public void setUp() {
try {
util = new BytecodeTestUtil(List.of("src/test/testFiles/E2EFeatures/Class.java"), "Class");
util = new BytecodeTestUtil("src/test/testFiles/E2EFeatures/Class.java", "Class");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Tests the number of constructors in the class, expecting 1 constructor, which is the default constructor
*/
@Test
public void testConstructorCount() {
Assertions.assertEquals(1, util.getConstructorCount());
// default constructor
}
/**
* Tests name, parameter count and type of the returned object of the default constructor,
* expecting the default constructor to be named "Class", not to have any parameters and to return an object of type Class
*/
@Test
public void testDefaultConstructor() {
Assertions.assertEquals("Class", util.getConstructorNames().get(0));
@ -39,21 +54,28 @@ public class E2E_Class {
}
/**
* Tests the number of methods in the class, expecting 0 methods
*/
@Test
public void testMethodCount() {
Assertions.assertEquals(0, util.getMethodCount());
}
/**
* Tests the number of fields in the class, expecting 0 fields
*/
@Test
public void testFieldCount() {
Assertions.assertEquals(0, util.getFieldCount());
}
/**
* Tests the invocation of the default constructor, expecting the returned object to be of type Class
* (constructor does not contain any initialization code)
*/
@Test
public void testInvokeDefaultConstructor() {
try {

View File

@ -5,26 +5,41 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.List;
/**
* Test class for testing if the compilation of the class 'ClassObjects' at src/test/testFiles/E2EFeatures/ClassObjects.java was successful,
* if the class contains the expected fields, methods and constructors and works as expected
*/
public class E2E_ClassObjects {
/**
* The BytecodeTestUtil instance for the test class, which provides methods for testing the compiled class
*/
private BytecodeTestUtil util;
/**
* Initializes the BytecodeTestUtil instance for the test class
*/
@BeforeEach
public void setUp() {
try {
util = new BytecodeTestUtil(List.of("src/test/testFiles/E2EFeatures/ClassObjects.java"), "ClassObjects");
util = new BytecodeTestUtil("src/test/testFiles/E2EFeatures/ClassObjects.java", "ClassObjects");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Tests the number of constructors in the class, expecting 2 constructors
*/
@Test
public void testConstructorCount() {
Assertions.assertEquals(2, util.getConstructorCount());
}
/**
* Tests the name, parameter count and types of the returned object of the first constructor,
* expecting the first constructor to be named "ClassObjects", not to have any parameters and to return an object of type ClassObjects
*/
@Test
public void testConstructor1() {
Assertions.assertTrue(util.getConstructorNames().contains("ClassObjects"));
@ -35,6 +50,10 @@ public class E2E_ClassObjects {
}
}
/**
* Tests the name, parameter count and types of the returned object of the second constructor,
* expecting the second constructor to be named "ClassObjects", to have 1 parameter of type int and to return an object of type ClassObjects
*/
@Test
public void testConstructor2() {
Assertions.assertTrue(util.getConstructorNames().contains("ClassObjects"));
@ -46,16 +65,25 @@ public class E2E_ClassObjects {
}
/**
* Tests the number of methods in the class, expecting 1 method
*/
@Test
public void testMethodCount() {
Assertions.assertEquals(1, util.getMethodCount());
}
/**
* Tests the names of the methods in the class, expecting the method "objectsMethod"
*/
@Test
public void testMethodNames() {
Assertions.assertTrue(util.getMethodNames().contains("objectsMethod"));
}
/**
* Tests the return type of the method "objectsMethod", expecting "void"
*/
@Test
public void testMethodReturnType() {
try {
@ -65,6 +93,9 @@ public class E2E_ClassObjects {
}
}
/**
* Tests the number of parameters of the method "objectsMethod", expecting 0 parameters
*/
@Test
public void testMethodParameters() {
try {
@ -75,11 +106,17 @@ public class E2E_ClassObjects {
}
/**
* Tests the number of fields in the class, expecting 3 fields
*/
@Test
public void testFieldCount() {
Assertions.assertEquals(3, util.getFieldCount());
}
/**
* Tests the names of the fields in the class, expecting the fields "object", "objectWithValue" and "integerValue"
*/
@Test
public void testFieldNames() {
Assertions.assertEquals("object", util.getFieldNames().get(0));
@ -87,6 +124,10 @@ public class E2E_ClassObjects {
Assertions.assertEquals("integerValue", util.getFieldNames().get(2));
}
/**
* Tests the types of the fields in the class, expecting the fields "object" and "objectWithValue" to be of type
* ClassObjects and "integerValue" to be of type int
*/
@Test
public void testFieldTypes() {
Assertions.assertEquals("ClassObjects", util.getFieldTypes().get(0));
@ -94,6 +135,9 @@ public class E2E_ClassObjects {
Assertions.assertEquals("int", util.getFieldTypes().get(2));
}
/**
* Tests the values of the fields in the class, expecting the fields "object" and "objectWithValue" to be null and "integerValue" to be 0
*/
@Test
public void testFieldValues() {
try {
@ -106,6 +150,11 @@ public class E2E_ClassObjects {
}
/**
* Tests the invocation of the first constructor, expecting the returned object to be of type ClassObjects and the field
* "object" and "objectWithValue" to be initialized with null and the field "integerValue" to be 0
* (constructor does not contain any initialization code)
*/
@Test
public void testInvokeConstructor1() {
try {
@ -120,6 +169,10 @@ public class E2E_ClassObjects {
}
}
/**
* Tests the invocation of the second constructor, expecting the returned object to be of type ClassObjects and the field
* "object" and "objectWithValue" to be initialized with null and the field "integerValue" to be 2
*/
@Test
public void testInvokeConstructor2() {
try {
@ -134,6 +187,10 @@ public class E2E_ClassObjects {
}
}
/**
* Tests the invocation of the method "objectsMethod", expecting the field "object" and "objectWithValue" to be
* initialized with a new object of type ClassObjects and the field "integerValue" to be 2
*/
@Test
public void testInvokeMethod() {
try {

View File

@ -5,28 +5,43 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import E2ETests.BytecodeTestUtil;
import java.util.List;
/**
* Test class for testing if the compilation of the class 'Comment' at src/test/testFiles/E2EFeatures/Comment.java was successful,
* if the class contains the expected fields, methods and constructors and works as expected
*/
public class E2E_Comment {
/**
* The BytecodeTestUtil instance for the test class, which provides methods for testing the compiled class
*/
private BytecodeTestUtil util;
/**
* Initializes the BytecodeTestUtil instance for the test class
*/
@BeforeEach
public void setUp() {
try {
util = new BytecodeTestUtil(List.of("src/test/testFiles/E2EFeatures/Comment.java"), "Comment");
util = new BytecodeTestUtil("src/test/testFiles/E2EFeatures/Comment.java", "Comment");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Tests the number of constructors in the class, expecting 1 constructor, which is the default constructor
*/
@Test
public void testConstructorCount() {
Assertions.assertEquals(1, util.getConstructorCount());
// default constructor
}
/**
* Tests name, parameter count and type of the returned object of the default constructor,
* expecting the default constructor to be named "Comment", not to have any parameters and to return an object of type Comment
*/
@Test
public void testDefaultConstructor() {
Assertions.assertEquals("Comment", util.getConstructorNames().get(0));
@ -40,6 +55,9 @@ public class E2E_Comment {
/**
* Tests the number of methods in the class, expecting 0 methods
*/
@Test
public void testMethodCount() {
Assertions.assertEquals(0, util.getMethodCount());
@ -47,6 +65,9 @@ public class E2E_Comment {
/**
* Tests the number of fields in the class, expecting 0 fields
*/
@Test
public void testFieldCount() {
Assertions.assertEquals(0, util.getFieldCount());
@ -54,6 +75,10 @@ public class E2E_Comment {
/**
* Tests the invocation of the default constructor, expecting the returned object to be of type Comment
* (constructor does not contain initialization code)
*/
@Test
public void testInvokeDefaultConstructor() {
try {

View File

@ -5,16 +5,24 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.List;
/**
* Test class for testing if the compilation of the class 'CompAssign' at src/test/testFiles/E2EFeatures/CompAssign.java was successful,
* if the class contains the expected fields, methods and constructors and works as expected
*/
public class E2E_CompAssign {
/**
* The BytecodeTestUtil instance for the test class, which provides methods for testing the compiled class
*/
private BytecodeTestUtil util;
/**
* Initializes the BytecodeTestUtil instance for the test class
*/
@BeforeEach
public void setUp() {
try {
util = new BytecodeTestUtil(List.of("src/test/testFiles/E2EFeatures/CompAssign.java"), "CompAssign");
util = new BytecodeTestUtil("src/test/testFiles/E2EFeatures/CompAssign.java", "CompAssign");
} catch (Exception e) {
throw new RuntimeException(e);
}
@ -22,12 +30,19 @@ public class E2E_CompAssign {
/**
* Tests the number of constructors in the class, expecting 1 constructor, which is the default constructor
*/
@Test
public void testConstructorCount() {
Assertions.assertEquals(1, util.getConstructorCount());
// default constructor
}
/**
* Tests name, parameter count and type of the returned object of the default constructor,
* expecting the default constructor to be named "CompAssign", not to have any parameters and to return an object of type CompAssign
*/
@Test
public void testDefaultConstructor() {
Assertions.assertEquals("CompAssign", util.getConstructorNames().get(0));
@ -41,11 +56,17 @@ public class E2E_CompAssign {
/**
* Tests the number of methods in the class, expecting 5 methods
*/
@Test
public void testMethodCount() {
Assertions.assertEquals(5, util.getMethodCount());
}
/**
* Tests the names of the methods in the class, expecting the methods "increase", "decrease", "multiply", "divide" and "modulus"
*/
@Test
public void testMethodNames() {
Assertions.assertTrue(util.getMethodNames().contains("increase"));
@ -55,6 +76,9 @@ public class E2E_CompAssign {
Assertions.assertTrue(util.getMethodNames().contains("modulus"));
}
/**
* Tests the return type of the methods, expecting "int" for all methods
*/
@Test
public void testMethodReturnType() {
try {
@ -68,6 +92,9 @@ public class E2E_CompAssign {
}
}
/**
* Tests the number of parameters of the methods, expecting 1 parameter of type int for all methods
*/
@Test
public void testMethodParameters() {
try {
@ -87,6 +114,10 @@ public class E2E_CompAssign {
}
/**
* Tests the number of fields in the class, expecting 0 fields
*/
@Test
public void testFieldCount() {
Assertions.assertEquals(0, util.getFieldCount());
@ -94,6 +125,10 @@ public class E2E_CompAssign {
/**
* Tests the invocation of the default constructor, expecting the returned object to be of type Comment
* (constructor does not contain initialization code)
*/
@Test
public void testInvokeDefaultConstructor() {
try {
@ -104,6 +139,9 @@ public class E2E_CompAssign {
}
}
/**
* Tests the invocation of the method "increase", expecting the returned value to be 1 and 6 when passing 0 and 5 as parameter
*/
@Test
public void testInvokeIncrease() {
try {
@ -114,6 +152,9 @@ public class E2E_CompAssign {
}
}
/**
* Tests the invocation of the method "decrease", expecting the returned value to be 0 and 4 when passing 1 and 5 as parameter
*/
@Test
public void testInvokeDecrease() {
try {
@ -124,6 +165,9 @@ public class E2E_CompAssign {
}
}
/**
* Tests the invocation of the method "multiply", expecting the returned value to be 0 and 10 when passing 0 and 5 as parameter
*/
@Test
public void testInvokeMultiply() {
try {
@ -134,6 +178,9 @@ public class E2E_CompAssign {
}
}
/**
* Tests the invocation of the method "divide", expecting the returned value to be 0 and 2 when passing 0 and 5 as parameter
*/
@Test
public void testInvokeDivide() {
try {
@ -144,6 +191,9 @@ public class E2E_CompAssign {
}
}
/**
* Tests the invocation of the method "modulus", expecting the returned value to be 0 and 1 when passing 0 and 5 as parameter
*/
@Test
public void testInvokeModulus() {
try {

View File

@ -5,16 +5,24 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.List;
/**
* Test class for testing if the compilation of the class 'ComplexCalls' at src/test/testFiles/E2EFeatures/ComplexCalls.java was successful,
* if the class contains the expected fields, methods and constructors and works as expected
*/
public class E2E_ComplexCalls {
/**
* The BytecodeTestUtil instance for the test class, which provides methods for testing the compiled class
*/
private BytecodeTestUtil util;
/**
* Initializes the BytecodeTestUtil instance for the test class
*/
@BeforeEach
public void setUp() {
try {
util = new BytecodeTestUtil(List.of("src/test/testFiles/E2EFeatures/ComplexCalls.java"), "ComplexCalls");
util = new BytecodeTestUtil("src/test/testFiles/E2EFeatures/ComplexCalls.java", "ComplexCalls");
} catch (Exception e) {
throw new RuntimeException(e);
}
@ -22,12 +30,19 @@ public class E2E_ComplexCalls {
/**
* Tests the number of constructors in the class, expecting 1 constructor, which is the default constructor
*/
@Test
public void testConstructorCount() {
Assertions.assertEquals(1, util.getConstructorCount());
// default constructor
}
/**
* Tests name, parameter count and type of the returned object of the default constructor,
* expecting the default constructor to be named "ComplexCalls", not to have any parameters and to return an object of type ComplexCalls
*/
@Test
public void testDefaultConstructor() {
Assertions.assertEquals("ComplexCalls", util.getConstructorNames().get(0));
@ -41,11 +56,17 @@ public class E2E_ComplexCalls {
/**
* Tests the number of methods in the class, expecting 3 methods
*/
@Test
public void testMethodCount() {
Assertions.assertEquals(3, util.getMethodCount());
}
/**
* Tests the names of the methods in the class, expecting the methods "makeComplexCalls", "getClassObject" and "getA"
*/
@Test
public void testMethodNames() {
Assertions.assertTrue(util.getMethodNames().contains("makeComplexCalls"));
@ -53,6 +74,10 @@ public class E2E_ComplexCalls {
Assertions.assertTrue(util.getMethodNames().contains("getA"));
}
/**
* Tests the return type of the methods in the class, expecting "int" for the method "makeComplexCalls",
* "ComplexCalls" for the method "getClassObject" and "int" for the method "getA"
*/
@Test
public void testMethodReturnType() {
try {
@ -64,6 +89,10 @@ public class E2E_ComplexCalls {
}
}
/**
* Tests the number of parameters of the methods in the class, expecting 0 parameters for the method "makeComplexCalls" and "getClassObject"
* and 1 parameter of type int for the method "getA"
*/
@Test
public void testMethodParameters() {
try {
@ -78,23 +107,35 @@ public class E2E_ComplexCalls {
/**
* Tests the number of fields in the class, expecting 2 fields
*/
@Test
public void testFieldCount() {
Assertions.assertEquals(2, util.getFieldCount());
}
/**
* Tests the names of the fields in the class, expecting the fields "a" and "classObject"
*/
@Test
public void testFieldNames() {
Assertions.assertTrue(util.getFieldNames().contains("a"));
Assertions.assertTrue(util.getFieldNames().contains("classObject"));
}
/**
* Tests the types of the fields in the class, expecting "ComplexCalls" for the field "classObject" and "int" for the field "a"
*/
@Test
public void testFieldTypes() {
Assertions.assertEquals("int", util.getFieldTypes().get(1));
Assertions.assertEquals("ComplexCalls", util.getFieldTypes().get(0));
}
/**
* Tests the values of the fields in the class, expecting 0 for the field "a" and null for the field "classObject"
*/
@Test
public void testFieldValues() {
try {
@ -107,6 +148,9 @@ public class E2E_ComplexCalls {
/**
* Tests the invocation of the default constructor, expecting the returned object to be of type ComplexCalls
*/
@Test
public void testInvokeDefaultConstructor() {
try {
@ -117,6 +161,12 @@ public class E2E_ComplexCalls {
}
}
/**
* Tests the invocation of the method "makeComplexCalls", expecting the returned value to be 3 and the field "classObject"
* to be Null before and of type ComplexCalls after the method invocation and the field "a" to be 0 before and 1 after the method invocation
* (both field should have been changed by the method), expect the field "classObject" to have a field "a" with value 2
* and the field "classObject" to have a field "classObject" of type ComplexCalls with a field "a" with value 3
*/
@Test
public void testInvokeMethodMakeComplexCalls() {
try {
@ -141,6 +191,11 @@ public class E2E_ComplexCalls {
}
}
/**
* Tests the invocation of the method "getClassObject", expecting the returned value to be the field "classObject"
* and the field "classObject" to be null before and stay null after the method invocation
* and the field "a" to be 0 before and stay 0 after the method invocation
*/
@Test
public void testInvokeMethodGetClassObject() {
try {
@ -157,6 +212,11 @@ public class E2E_ComplexCalls {
}
}
/**
* Tests the invocation of the method "getA", expecting the returned value to be 5 and the field "classObject"
* to be null before and stay null after the method invocation and the field "a" to be 0 before and 5 after the method invocation
* (the field a should have been changed by the method)
*/
@Test
public void testInvokeMethodGetA() {
try {

View File

@ -5,67 +5,124 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.List;
/**
* Test class for testing if the compilation of the class 'Constructor' at src/test/testFiles/E2EFeatures/Constructor.java was successful,
* if the class contains the expected fields, methods and constructors and works as expected
*/
public class E2E_Constructor {
/**
* The BytecodeTestUtil instance for the test class, which provides methods for testing the compiled class
*/
private BytecodeTestUtil util;
/**
* Initializes the BytecodeTestUtil instance for the test class
*/
@BeforeEach
public void setUp() {
try {
util = new BytecodeTestUtil(List.of("src/test/testFiles/E2EFeatures/Constructor.java"), "Constructor");
util = new BytecodeTestUtil("src/test/testFiles/E2EFeatures/Constructor.java", "Constructor");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Tests the number of constructors in the class, expecting 3 constructors
*/
@Test
public void testConstructorCount() {
Assertions.assertEquals(3, util.getConstructorCount());
}
/**
* Tests name, parameter count and type of the returned object of the first constructor,
* expecting the first constructor to be named "Constructor", not to have any parameters and to return an object of type Constructor
*/
@Test
public void testConstructor1() {
Assertions.assertEquals("Constructor", util.getConstructorNames().get(0));
Assertions.assertEquals(0, util.getConstructorParameterCount(0));
try {
Assertions.assertEquals("Constructor", util.invokeConstructor(new Class<?>[]{}, null).getClass().getName());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Tests name, parameter count and type of the returned object of the second constructor,
* expecting the second constructor to be named "Constructor", to have 1 parameter of type int and to return an object of type Constructor
*/
@Test
public void testConstructor2() {
Assertions.assertEquals("Constructor", util.getConstructorNames().get(1));
Assertions.assertEquals(1, util.getConstructorParameterCount(1));
Assertions.assertEquals("int", util.getConstructorParameterTypes(1).get(0));
try {
Assertions.assertEquals("Constructor", util.invokeConstructor(new Class<?>[]{int.class}, new Object[]{5}).getClass().getName());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Tests name, parameter count and type of the returned object of the third constructor,
* expecting the third constructor to be named "Constructor", to have 2 parameters of type int and to return an object of type Constructor
*/
@Test
public void testConstructor3() {
Assertions.assertEquals("Constructor", util.getConstructorNames().get(2));
Assertions.assertEquals(2, util.getConstructorParameterCount(2));
Assertions.assertEquals("int", util.getConstructorParameterTypes(2).get(0));
Assertions.assertEquals("int", util.getConstructorParameterTypes(2).get(1));
try {
Assertions.assertEquals("Constructor", util.invokeConstructor(new Class<?>[]{int.class, int.class}, new Object[]{5, 10}).getClass().getName());
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Tests the number of methods in the class, expecting 0 methods
*/
@Test
public void testMethodCount() {
Assertions.assertEquals(0, util.getMethodCount());
}
/**
* Tests the number of fields in the class, expecting 1 field
*/
@Test
public void testFieldCount() {
Assertions.assertEquals(1, util.getFieldCount());
}
/**
* Tests the names of the fields in the class, expecting the field "i"
*/
@Test
public void testFieldNames() {
Assertions.assertEquals("i", util.getFieldNames().get(0));
}
/**
* Tests the types of the fields in the class, expecting the field "i" to be of type int
*/
@Test
public void testFieldTypes() {
Assertions.assertEquals("int", util.getFieldTypes().get(0));
}
/**
* Tests the values of the fields in the class, expecting 1 for the field "i"
*/
@Test
public void testFieldValues() {
try {
@ -75,6 +132,10 @@ public class E2E_Constructor {
}
}
/**
* Tests the invocation of the first constructor, expecting the returned object to be of type Constructor and the field
* "i" to be initialized with 1
*/
@Test
public void testInvokeConstructor1() {
try {
@ -86,6 +147,10 @@ public class E2E_Constructor {
}
}
/**
* Tests the invocation of the second constructor, expecting the returned object to be of type Constructor and the field
* "i" to be initialized with 5 when passing 5 as parameter to the constructor
*/
@Test
public void testInvokeConstructor2() {
try {
@ -97,6 +162,10 @@ public class E2E_Constructor {
}
}
/**
* Tests the invocation of the third constructor, expecting the returned object to be of type Constructor and the field
* "i" to be initialized with 15 when passing 5 and 10 as parameters to the constructor
*/
@Test
public void testInvokeConstructor3() {
try {

View File

@ -5,27 +5,42 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.List;
/**
* Test class for testing if the compilation of the class 'Continue' at src/test/testFiles/E2EFeatures/Continue.java was successful,
* if the class contains the expected fields, methods and constructors and works as expected
*/
public class E2E_Continue {
/**
* The BytecodeTestUtil instance for the test class, which provides methods for testing the compiled class
*/
private BytecodeTestUtil util;
/**
* Initializes the BytecodeTestUtil instance for the test class
*/
@BeforeEach
public void setUp() {
try {
util = new BytecodeTestUtil(List.of("src/test/testFiles/E2EFeatures/Continue.java"), "Continue");
util = new BytecodeTestUtil("src/test/testFiles/E2EFeatures/Continue.java", "Continue");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Tests the number of constructors in the class, expecting 1 constructor, which is the default constructor
*/
@Test
public void testConstructorCount() {
Assertions.assertEquals(1, util.getConstructorCount());
// default constructor
}
/**
* Tests name, parameter count and type of the returned object of the default constructor,
* expecting the default constructor to be named "Continue", not to have any parameters and to return an object of type Continue
*/
@Test
public void testDefaultConstructor() {
Assertions.assertEquals("Continue", util.getConstructorNames().get(0));
@ -37,16 +52,27 @@ public class E2E_Continue {
}
}
/**
* Tests the number of methods in the class, expecting 1 method
*/
@Test
public void testMethodCount() {
Assertions.assertEquals(1, util.getMethodCount());
}
/**
* Tests the name of the method, expecting the method to be named "continueLoop"
*/
@Test
public void testMethodNames() {
Assertions.assertEquals("continueLoop", util.getMethodNames().get(0));
}
/**
* Tests the return type of the method, expecting the method to return void
*/
@Test
public void testMethodReturnType() {
try {
@ -56,6 +82,9 @@ public class E2E_Continue {
}
}
/**
* Tests the number of parameters of the method, expecting 1 parameter, which is of type boolean
*/
@Test
public void testMethodParameters() {
try {
@ -66,16 +95,25 @@ public class E2E_Continue {
}
}
/**
* Tests the number of fields in the class, expecting 1 field
*/
@Test
public void testFieldCount() {
Assertions.assertEquals(1, util.getFieldCount());
}
/**
* Tests the names of the fields in the class, expecting the field "repetitions"
*/
@Test
public void testFieldNames() {
Assertions.assertEquals("repetitions", util.getFieldNames().get(0));
}
/**
* Tests the type of the fields in the class, expecting the field to be of type int
*/
@Test
public void testFieldTypes() {
try {
@ -85,6 +123,9 @@ public class E2E_Continue {
}
}
/**
* Tests the value of the field "repetitions", expecting the field to be initialized with the value 0
*/
@Test
public void testFieldValues() {
try {
@ -94,6 +135,12 @@ public class E2E_Continue {
}
}
/**
* Tests the invocation of the default constructor, expecting the returned object to be of type Continue and
* the field "repetitions" to be initialized with 0
*/
@Test
public void testInvokeDefaultConstructor() {
try {
@ -105,6 +152,12 @@ public class E2E_Continue {
}
}
/**
* Tests the invocation of the method "continueLoop" with the parameter false, expecting the field "repetitions"
* to be 0 before the method invocation and 5 after the method invocation (method contains a for loop with 5 iterations,
* in which the field "repetitions" is incremented by 1 in each iteration, and a continue statement that skips the
* fourth iteration, which is not executed due to the parameter being false)
*/
@Test
public void testInvokeMethodWithFalse() {
try {
@ -117,6 +170,12 @@ public class E2E_Continue {
}
}
/**
* Tests the invocation of the method "continueLoop" with the parameter true, expecting the field "repetitions"
* to be 0 before the method invocation and 4 after the method invocation (method contains a for loop with 5 iterations,
* in which the field "repetitions" is incremented by 1 in each iteration, and a continue statement that skips the
* fourth iteration, which is executed due to the parameter being true)
*/
@Test
public void testInvokeMethodWithTrue() {
try {

View File

@ -9,23 +9,36 @@ import java.util.List;
public class E2E_DataTypes {
/**
* The BytecodeTestUtil instance for the test class, which provides methods for testing the compiled class
*/
private BytecodeTestUtil util;
/**
* Initializes the BytecodeTestUtil instance for the test class
*/
@BeforeEach
public void setUp() {
try {
util = new BytecodeTestUtil(List.of("src/test/testFiles/E2EFeatures/DataTypes.java"), "DataTypes");
util = new BytecodeTestUtil("src/test/testFiles/E2EFeatures/DataTypes.java", "DataTypes");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Tests the number of constructors in the class, expecting 1 constructor, which is the default constructor
*/
@Test
public void testConstructorCount() {
Assertions.assertEquals(1, util.getConstructorCount());
// default constructor
}
/**
* Tests name, parameter count and type of the returned object of the default constructor,
* expecting the default constructor to be named "DataTypes", not to have any parameters and to return an object of type DataTypes
*/
@Test
public void testDefaultConstructor() {
Assertions.assertEquals("DataTypes", util.getConstructorNames().get(0));
@ -37,11 +50,19 @@ public class E2E_DataTypes {
}
}
/**
* Tests the number of methods in the class, expecting 3 methods
*/
@Test
public void testMethodCount() {
Assertions.assertEquals(3, util.getMethodCount());
}
/**
* Tests the names of the methods in the class, expecting the methods to be named "integer", "bool" and "character"
*/
@Test
public void testMethodNames() {
Assertions.assertTrue(util.getMethodNames().contains("integer"));
@ -49,6 +70,9 @@ public class E2E_DataTypes {
Assertions.assertTrue(util.getMethodNames().contains("character"));
}
/**
* Tests the return types of the methods in the class, expecting the methods to return an int, a boolean and a char
*/
@Test
public void testMethodReturnType() {
try {
@ -60,6 +84,11 @@ public class E2E_DataTypes {
}
}
/**
* Tests the number and types of the parameters of the methods in the class, expecting the method
* "integer" to have 1 parameter of type int, the method "bool" to have 1 parameter of type boolean and the method
* "character" to have 1 parameter of type char
*/
@Test
public void testMethodParameters() {
try {
@ -80,11 +109,19 @@ public class E2E_DataTypes {
}
}
/**
* Tests the number of fields in the class, expecting 3 fields
*/
@Test
public void testFieldCount() {
Assertions.assertEquals(3, util.getFieldCount());
}
/**
* Tests the names of the fields in the class, expecting the fields "x", "y" and "z"
*/
@Test
public void testFieldNames() {
Assertions.assertTrue(util.getFieldNames().contains("x"));
@ -92,6 +129,10 @@ public class E2E_DataTypes {
Assertions.assertTrue(util.getFieldNames().contains("z"));
}
/**
* Tests the types of the fields in the class, expecting the fields "x" to be of type int, "y" to be of type
* boolean and "z" to be of type char
*/
@Test
public void testFieldTypes() {
Assertions.assertEquals("int", util.getFieldTypes().get(0));
@ -99,6 +140,9 @@ public class E2E_DataTypes {
Assertions.assertEquals("char", util.getFieldTypes().get(2));
}
/**
* Tests the values of the fields in the class, expecting the fields "x" to be 0, "y" to be false and "z" to be '\u0000'
*/
@Test
public void testFieldValues() {
try {
@ -110,6 +154,10 @@ public class E2E_DataTypes {
}
}
/**
* Tests the invocation of the default constructor, expecting the returned object to be of type DataTypes and
* the fields "x" to be 0, "y" to be false and "z" to be '\u0000'
*/
@Test
public void testInvokeDefaultConstructor() {
try {
@ -123,6 +171,11 @@ public class E2E_DataTypes {
}
}
/**
* Tests the invocation of the method "integer" with the parameter 3, expecting the returned value to be 1 and the fields
* "x" to be 0 before and 1 after the method invocation, "y" to be false before and after the method invocation
* and "z" to be '\u0000' before and after the method invocation (method changes the value of "x" to 1 and returns the value of "x")
*/
@Test
public void testInvokeMethodIntegerWith3() {
try {
@ -139,6 +192,11 @@ public class E2E_DataTypes {
}
}
/**
* Tests the invocation of the method "bool" with the parameter true, expecting the returned value to be true and the fields
* "x" to be 0 before and after the method invocation, "y" to be false before and true after the method invocation
* and "z" to be '\u0000' before and after the method invocation (method changes the value of "y" to true and returns the value of "y")
*/
@Test
public void testInvokeMethodBoolWithTrue() {
try {
@ -155,6 +213,11 @@ public class E2E_DataTypes {
}
}
/**
* Tests the invocation of the method "character" with the parameter 'B', expecting the returned value to be 'a' and the fields
* "x" to be 0 before and after the method invocation, "y" to be false before and after the method invocation
* and "z" to be '\u0000' before and 'a' after the method invocation (method changes the value of "z" to 'a' and returns the value of "z")
*/
@Test
public void testInvokeMethodCharacterWithB() {
try {

View File

@ -5,27 +5,44 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import E2ETests.BytecodeTestUtil;
import java.util.List;
/**
* Test class for testing if the compilation of the class 'Field' at src/test/testFiles/E2EFeatures/Field.java was successful,
* if the class contains the expected fields, methods and constructors and works as expected
*/
public class E2E_Field {
/**
* The BytecodeTestUtil instance for the test class, which provides methods for testing the compiled class
*/
private BytecodeTestUtil util;
/**
* Initializes the BytecodeTestUtil instance for the test class
*/
@BeforeEach
public void setUp() {
try {
util = new BytecodeTestUtil(List.of("src/test/testFiles/E2EFeatures/Field.java"), "Field");
util = new BytecodeTestUtil("src/test/testFiles/E2EFeatures/Field.java", "Field");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Tests the number of constructors in the class, expecting 1 constructor, which is the default constructor
*/
@Test
public void testConstructorCount() {
Assertions.assertEquals(1, util.getConstructorCount());
// default constructor
}
/**
* Tests name, parameter count and type of the returned object of the default constructor,
* expecting the default constructor to be named "Field", not to have any parameters and to return an object of type Field
*/
@Test
public void testDefaultConstructor() {
Assertions.assertEquals("Field", util.getConstructorNames().get(0));
@ -37,11 +54,19 @@ public class E2E_Field {
}
}
/**
* Tests the number of methods in the class, expecting 3 methods
*/
@Test
public void testMethodCount() {
Assertions.assertEquals(3, util.getMethodCount());
}
/**
* Tests the names of the methods in the class, expecting the methods 'fieldAccess', 'setX' and 'setC'
*/
@Test
public void testMethodNames() {
Assertions.assertTrue(util.getMethodNames().contains("fieldAccess"));
@ -49,6 +74,9 @@ public class E2E_Field {
Assertions.assertTrue(util.getMethodNames().contains("setC"));
}
/**
* Tests the return type of the methods in the class, expecting 'void' for all methods
*/
@Test
public void testMethodReturnType() {
try {
@ -60,6 +88,10 @@ public class E2E_Field {
}
}
/**
* Tests the number of parameters of the methods in the class, expecting 0 parameters for 'fieldAccess' and 1 parameter
* of type 'int' for 'setX' and 'setC'
*/
@Test
public void testMethodParameters() {
try {
@ -73,17 +105,28 @@ public class E2E_Field {
}
}
/**
* Tests the number of fields in the class, expecting 2 fields
*/
@Test
public void testFieldCount() {
Assertions.assertEquals(2, util.getFieldCount());
}
/**
* Tests the names of the fields in the class, expecting the fields 'x' and 'c'
*/
@Test
public void testFieldNames() {
Assertions.assertTrue(util.getFieldNames().contains("x"));
Assertions.assertTrue(util.getFieldNames().contains("c"));
}
/**
* Tests the types of the fields in the class, expecting 'int' for 'x' and 'char' for 'c'
*/
@Test
public void testFieldTypes() {
try {
@ -94,6 +137,9 @@ public class E2E_Field {
}
}
/**
* Tests the values of the fields in the class, expecting 0 for 'x' and '\u0000' for 'c'
*/
@Test
public void testFieldValues() {
try {
@ -104,6 +150,12 @@ public class E2E_Field {
}
}
/**
* Tests the invocation of the default constructor, expecting the returned object to be of type Field and the fields
* 'x' and 'c' to be initialized with 0 and '\u0000'
*/
@Test
public void testInvokeDefaultConstructor() {
try {
@ -116,6 +168,10 @@ public class E2E_Field {
}
}
/**
* Tests the invocation of the method 'fieldAccess', expecting the field 'x' to be 0, and the field 'c'
* to be changed from '\u0000' to 'a'
*/
@Test
public void testInvokeFieldAccess() {
try {
@ -129,6 +185,10 @@ public class E2E_Field {
}
}
/**
* Tests the invocation of the method 'setX' with the parameter 5, expecting the field 'x' to be 0 before and 5
* after the method invocation and the field 'c' to be '\u0000' before and after the method invocation
*/
@Test
public void testInvokeSetXWith5() {
try {
@ -142,6 +202,10 @@ public class E2E_Field {
}
}
/**
* Tests the invocation of the method 'setC' with the parameter 'h', expecting the field 'x' to be 0 before and after
* the method invocation and the field 'c' to be '\u0000' before and 'h' after the method invocation
*/
@Test
public void testInvokeSetCWithH() {
try {

View File

@ -5,27 +5,44 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import E2ETests.BytecodeTestUtil;
import java.util.List;
/**
* Test class for testing if the compilation of the class 'For' at src/test/testFiles/E2EFeatures/For.java was successful,
* if the class contains the expected fields, methods and constructors and works as expected
*/
public class E2E_For {
/**
* The BytecodeTestUtil instance for the test class, which provides methods for testing the compiled class
*/
private BytecodeTestUtil util;
/**
* Initializes the BytecodeTestUtil instance for the test class
*/
@BeforeEach
public void setUp() {
try {
util = new BytecodeTestUtil(List.of("src/test/testFiles/E2EFeatures/For.java"), "For");
util = new BytecodeTestUtil("src/test/testFiles/E2EFeatures/For.java", "For");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Tests the number of constructors in the class, expecting 1 constructor, which is the default constructor
*/
@Test
public void testConstructorCount() {
Assertions.assertEquals(1, util.getConstructorCount());
// default constructor
}
/**
* Tests name, parameter count and type of the returned object of the default constructor,
* expecting the default constructor to be named "For", not to have any parameters and to return an object of type For
*/
@Test
public void testDefaultConstructor() {
Assertions.assertEquals("For", util.getConstructorNames().get(0));
@ -37,16 +54,27 @@ public class E2E_For {
}
}
/**
* Tests the number of methods in the class, expecting 1 method
*/
@Test
public void testMethodCount() {
Assertions.assertEquals(1, util.getMethodCount());
}
/**
* Tests the name of the method, expecting the method to be named "testFor"
*/
@Test
public void testMethodNames() {
Assertions.assertTrue(util.getMethodNames().contains("testFor"));
}
/**
* Tests the return type of the method, expecting the method to return void
*/
@Test
public void testMethodReturnType() {
try {
@ -56,6 +84,9 @@ public class E2E_For {
}
}
/**
* Tests the number of parameters of the method, expecting 0 parameters
*/
@Test
public void testMethodParameters() {
try {
@ -65,11 +96,19 @@ public class E2E_For {
}
}
/**
* Tests the number of fields in the class, expecting 3 fields
*/
@Test
public void testFieldCount() {
Assertions.assertEquals(3, util.getFieldCount());
}
/**
* Tests the names of the fields in the class, expecting the fields to be named "repetitionsFirstFor", "repetitionsSecondFor" and "repetitionsThirdFor"
*/
@Test
public void testFieldNames() {
Assertions.assertTrue(util.getFieldNames().contains("repetitionsFirstFor"));
@ -77,6 +116,9 @@ public class E2E_For {
Assertions.assertTrue(util.getFieldNames().contains("repetitionsThirdFor"));
}
/**
* Tests the types of the fields in the class, expecting the fields to be of type int
*/
@Test
public void testFieldTypes() {
Assertions.assertEquals("int", util.getFieldTypes().get(0));
@ -84,6 +126,9 @@ public class E2E_For {
Assertions.assertEquals("int", util.getFieldTypes().get(2));
}
/**
* Tests the values of the fields in the class, expecting the fields to be initialized with 0
*/
@Test
public void testFieldValues() {
try {
@ -95,6 +140,10 @@ public class E2E_For {
}
}
/**
* Tests the invocation of the default constructor, expecting the returned object to be of type For and the fields
* "repetitionsFirstFor", "repetitionsSecondFor" and "repetitionsThirdFor" to be initialized with 0
*/
@Test
public void testInvokeDefaultConstructor() {
try {
@ -108,6 +157,14 @@ public class E2E_For {
}
}
/**
* Tests the invocation of the method "testFor", expecting the fields "repetitionsFirstFor",
* "repetitionsSecondFor" and "repetitionsThirdFor" to be 0 before the method invocation and 45, 45 and 10 after
* the method invocation (the method contains 3 nested for loops, the first one has 10 iterations and increases the
* field "repetitionsFirstFor" by the iteration number -1 each iteration, the second one has 10 iterations and
* increases the field "repetitionsSecondFor" by the iteration number -1 each iteration, the third one has
* 5 iterations and increases the field "repetitionsThirdFor" by the iteration number -1 each iteration)
*/
@Test
public void testInvokeMethod() {
try {

View File

@ -5,27 +5,42 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import E2ETests.BytecodeTestUtil;
import java.util.List;
/**
* Test class for testing if the compilation of the class 'If' at src/test/testFiles/E2EFeatures/If.java was successful,
* if the class contains the expected fields, methods and constructors and works as expected
*/
public class E2E_If {
/**
* The BytecodeTestUtil instance for the test class, which provides methods for testing the compiled class
*/
private BytecodeTestUtil util;
/**
* Initializes the BytecodeTestUtil instance for the test class
*/
@BeforeEach
public void setUp() {
try {
util = new BytecodeTestUtil(List.of("src/test/testFiles/E2EFeatures/If.java"), "If");
util = new BytecodeTestUtil("src/test/testFiles/E2EFeatures/If.java", "If");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Tests the number of constructors in the class, expecting 1 constructor, which is the default constructor
*/
@Test
public void testConstructorCount() {
Assertions.assertEquals(1, util.getConstructorCount());
// default constructor
}
/**
* Tests name, parameter count and type of the returned object of the default constructor,
* expecting the default constructor to be named "If", not to have any parameters and to return an object of type If
*/
@Test
public void testDefaultConstructor() {
Assertions.assertEquals("If", util.getConstructorNames().get(0));
@ -37,16 +52,27 @@ public class E2E_If {
}
}
/**
* Tests the number of methods in the class, expecting 1 method
*/
@Test
public void testMethodCount() {
Assertions.assertEquals(1, util.getMethodCount());
}
/**
* Tests the name of the method, expecting the method to be named "ifMethod"
*/
@Test
public void testMethodNames() {
Assertions.assertTrue(util.getMethodNames().contains("ifMethod"));
}
/**
* Tests the return type of the method, expecting the method to return an int
*/
@Test
public void testMethodReturnType() {
try {
@ -57,6 +83,9 @@ public class E2E_If {
}
}
/**
* Tests the number and types of the parameters of the method, expecting the method to have 2 parameters of type boolean
*/
@Test
public void testMethodParameters() {
try {
@ -71,11 +100,21 @@ public class E2E_If {
}
}
/**
* Tests the number of fields in the class, expecting 0 fields
*/
@Test
public void testFieldCount() {
Assertions.assertEquals(0, util.getFieldCount());
}
/**
* Tests the invocation of the default constructor, expecting the returned object to be of type If
*/
@Test
public void testInvokeDefaultConstructor() {
try {
@ -86,6 +125,10 @@ public class E2E_If {
}
}
/**
* Tests the invocation of the method "ifMethod" with parameters true and true, expecting the return value to be 6
* (for reason why 6, see src/test/testFiles/E2EFeatures/If.java)
*/
@Test
public void testInvokeIfMethodWithTrueTrue() {
try {
@ -97,6 +140,10 @@ public class E2E_If {
}
}
/**
* Tests the invocation of the method "ifMethod" with parameters true and false, expecting the return value to be 1
* (for reason why 1, see src/test/testFiles/E2EFeatures/If.java)
*/
@Test
public void testInvokeIfMethodWithTrueFalse() {
try {
@ -108,6 +155,10 @@ public class E2E_If {
}
}
/**
* Tests the invocation of the method "ifMethod" with parameters false and true, expecting the return value to be 2
* (for reason why 2, see src/test/testFiles/E2EFeatures/If.java)
*/
@Test
public void testInvokeIfMethodWithFalseTrue() {
try {
@ -119,6 +170,10 @@ public class E2E_If {
}
}
/**
* Tests the invocation of the method "ifMethod" with parameters false and false, expecting the return value to be 3
* (for reason why 3, see src/test/testFiles/E2EFeatures/If.java)
*/
@Test
public void testInvokeIfMethodWithFalseFalse() {
try {

View File

@ -5,27 +5,42 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.List;
/**
* Test class for testing if the compilation of the class 'InDeCrement' at src/test/testFiles/E2EFeatures/InDeCrement.java was successful,
* if the class contains the expected fields, methods and constructors and works as expected
*/
public class E2E_InDeCrement {
/**
* The BytecodeTestUtil instance for the test class, which provides methods for testing the compiled class
*/
private BytecodeTestUtil util;
/**
* Initializes the BytecodeTestUtil instance for the test class
*/
@BeforeEach
public void setUp() {
try {
util = new BytecodeTestUtil(List.of("src/test/testFiles/E2EFeatures/InDeCrement.java"), "InDeCrement");
util = new BytecodeTestUtil("src/test/testFiles/E2EFeatures/InDeCrement.java", "InDeCrement");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Tests the number of constructors in the class, expecting 1 constructor, which is the default constructor
*/
@Test
public void testConstructorCount() {
Assertions.assertEquals(1, util.getConstructorCount());
// default constructor
}
/**
* Tests name, parameter count and type of the returned object of the default constructor,
* expecting the default constructor to be named "InDeCrement", not to have any parameters and to return an object of type InDeCrement
*/
@Test
public void testDefaultConstructor() {
Assertions.assertEquals("InDeCrement", util.getConstructorNames().get(0));
@ -37,11 +52,19 @@ public class E2E_InDeCrement {
}
}
/**
* Tests the number of methods in the class, expecting 4 methods
*/
@Test
public void testMethodCount() {
Assertions.assertEquals(4, util.getMethodCount());
}
/**
* Tests the names of the methods in the class, expecting the methods to be named "PP", "MM", "PE" and "ME"
*/
@Test
public void testMethodNames() {
Assertions.assertTrue(util.getMethodNames().contains("PP"));
@ -50,6 +73,9 @@ public class E2E_InDeCrement {
Assertions.assertTrue(util.getMethodNames().contains("ME"));
}
/**
* Tests the return type of the methods in the class, expecting all methods to return "int"
*/
@Test
public void testMethodReturnType() {
try {
@ -62,23 +88,43 @@ public class E2E_InDeCrement {
}
}
/**
* Tests the number of parameters of the methods in the class, expecting the methods "PP" and "MM" to have 1 parameter of type int
* and the methods "PE" and "ME" to have 2 parameters of type int
*/
@Test
public void testMethodParameters() {
try {
Assertions.assertEquals(1, util.getMethodParameterCount("PP", new Class<?>[]{int.class}));
Assertions.assertEquals("int", util.getMethodParameterTypes("PP", new Class<?>[]{int.class}).get(0));
Assertions.assertEquals(1, util.getMethodParameterCount("MM", new Class<?>[]{int.class}));
Assertions.assertEquals("int", util.getMethodParameterTypes("MM", new Class<?>[]{int.class}).get(0));
Assertions.assertEquals(2, util.getMethodParameterCount("PE", new Class<?>[]{int.class, int.class}));
Assertions.assertEquals("int", util.getMethodParameterTypes("PE", new Class<?>[]{int.class, int.class}).get(0));
Assertions.assertEquals("int", util.getMethodParameterTypes("PE", new Class<?>[]{int.class, int.class}).get(1));
Assertions.assertEquals(2, util.getMethodParameterCount("ME", new Class<?>[]{int.class, int.class}));
Assertions.assertEquals("int", util.getMethodParameterTypes("ME", new Class<?>[]{int.class, int.class}).get(0));
Assertions.assertEquals("int", util.getMethodParameterTypes("ME", new Class<?>[]{int.class, int.class}).get(1));
} catch (Exception e) {
Assertions.fail();
}
}
/**
* Tests the number of fields in the class, expecting 0 fields
*/
@Test
public void testFieldCount() {
Assertions.assertEquals(0, util.getFieldCount());
}
/**
* Tests the invocation of the default constructor, expecting the returned object to be of type InDeCrement
*/
@Test
public void testInvokeDefaultConstructor() {
try {
@ -89,6 +135,9 @@ public class E2E_InDeCrement {
}
}
/**
* Tests the method "PP" in the class, expecting the method to increment the parameter by 1
*/
@Test
public void testPP() {
try {
@ -98,6 +147,9 @@ public class E2E_InDeCrement {
}
}
/**
* Tests the method "MM" in the class, expecting the method to decrement the parameter by 1
*/
@Test
public void testMM() {
try {
@ -107,6 +159,9 @@ public class E2E_InDeCrement {
}
}
/**
* Tests the method "PE" in the class, expecting the method to increment the first parameter by the second parameter
*/
@Test
public void testPE() {
try {
@ -116,6 +171,9 @@ public class E2E_InDeCrement {
}
}
/**
* Tests the method "ME" in the class, expecting the method to decrement the first parameter by the second parameter
*/
@Test
public void testME() {
try {

View File

@ -5,27 +5,44 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.List;
/**
* Test class for testing if the compilation of the class 'LogicExpr' at src/test/testFiles/E2EFeatures/LogicExpr.java was successful,
* if the class contains the expected fields, methods and constructors and works as expected
*/
public class E2E_LogicExpr {
/**
* The BytecodeTestUtil instance for the test class, which provides methods for testing the compiled class
*/
private BytecodeTestUtil util;
/**
* Initializes the BytecodeTestUtil instance for the test class
*/
@BeforeEach
public void setUp() {
try {
util = new BytecodeTestUtil(List.of("src/test/testFiles/E2EFeatures/LogicExpr.java"), "LogicExpr");
util = new BytecodeTestUtil("src/test/testFiles/E2EFeatures/LogicExpr.java", "LogicExpr");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Tests the number of constructors in the class, expecting 1 constructor, which is the default constructor
*/
@Test
public void testConstructorCount() {
Assertions.assertEquals(1, util.getConstructorCount());
// default constructor
}
/**
* Tests name, parameter count and type of the returned object of the default constructor,
* expecting the default constructor to be named "LogicExpr", not to have any parameters and to return an object of type LogicExpr
*/
@Test
public void testDefaultConstructor() {
Assertions.assertEquals("LogicExpr", util.getConstructorNames().get(0));
@ -37,11 +54,20 @@ public class E2E_LogicExpr {
}
}
/**
* Tests the number of methods in the class, expecting 8 methods
*/
@Test
public void testMethodCount() {
Assertions.assertEquals(8, util.getMethodCount());
}
/**
* Tests the names of the methods in the class, expecting the methods to be named "testSmaller", "testLarger",
* "testEqual", "testNotEqual", "testSmallerEqual", "testLargerEqual", "testAND" and "testOR"
*/
@Test
public void testMethodNames() {
Assertions.assertTrue(util.getMethodNames().contains("testSmaller"));
@ -54,6 +80,9 @@ public class E2E_LogicExpr {
Assertions.assertTrue(util.getMethodNames().contains("testOR"));
}
/**
* Tests the return type of the methods in the class, expecting "boolean" for all methods
*/
@Test
public void testMethodReturnType() {
try {
@ -70,6 +99,11 @@ public class E2E_LogicExpr {
}
}
/**
* Tests the number and types of the parameters of the methods in the class, expecting the methods
* "testSmaller", "testLarger", "testEqual", "testNotEqual", "testSmallerEqual" and "testLargerEqual" to have 2
* parameters of type int, the methods "testAND" and "testOR" to have 2 parameters of type boolean
*/
@Test
public void testMethodParameters() {
try {
@ -102,11 +136,21 @@ public class E2E_LogicExpr {
}
}
/**
* Tests the number of fields in the class, expecting 0 fields
*/
@Test
public void testFieldCount() {
Assertions.assertEquals(0, util.getFieldCount());
}
/**
* Tests the invocation of the default constructor, expecting the returned object to be of type LogicExpr
*/
@Test
public void testInvokeDefaultConstructor() {
try {
@ -117,6 +161,9 @@ public class E2E_LogicExpr {
}
}
/**
* Tests the invocation of the method "testSmaller" with the parameters 4 and 5, expecting the return value to be true
*/
@Test
public void testInvokeSmallerWith4And5() {
try {
@ -128,6 +175,9 @@ public class E2E_LogicExpr {
}
}
/**
* Tests the invocation of the method "testSmaller" with the parameters 5 and 4, expecting the return value to be false
*/
@Test
public void testInvokeSmallerWith5And4() {
try {
@ -139,6 +189,9 @@ public class E2E_LogicExpr {
}
}
/**
* Tests the invocation of the method "testSmaller" with the parameters 4 and 4, expecting the return value to be false
*/
@Test
public void testInvokeSmallerWith4And4() {
try {
@ -150,6 +203,9 @@ public class E2E_LogicExpr {
}
}
/**
* Tests the invocation of the method "testLarger" with the parameters 4 and 5, expecting the return value to be false
*/
@Test
public void testInvokeLargerWith4And5() {
try {
@ -161,6 +217,9 @@ public class E2E_LogicExpr {
}
}
/**
* Tests the invocation of the method "testLarger" with the parameters 5 and 4, expecting the return value to be true
*/
@Test
public void testInvokeLargerWith5And4() {
try {
@ -172,6 +231,9 @@ public class E2E_LogicExpr {
}
}
/**
* Tests the invocation of the method "testLarger" with the parameters 4 and 4, expecting the return value to be false
*/
@Test
public void testInvokeLargerWith4And4() {
try {
@ -183,6 +245,9 @@ public class E2E_LogicExpr {
}
}
/**
* Tests the invocation of the method "testEqual" with the parameters 4 and 5, expecting the return value to be false
*/
@Test
public void testInvokeEqualWith4And5() {
try {
@ -194,6 +259,9 @@ public class E2E_LogicExpr {
}
}
/**
* Tests the invocation of the method "testEqual" with the parameters 5 and 4, expecting the return value to be false
*/
@Test
public void testInvokeEqualWith5And4() {
try {
@ -205,6 +273,9 @@ public class E2E_LogicExpr {
}
}
/**
* Tests the invocation of the method "testEqual" with the parameters 4 and 4, expecting the return value to be true
*/
@Test
public void testInvokeEqualWith4And4() {
try {
@ -216,6 +287,9 @@ public class E2E_LogicExpr {
}
}
/**
* Tests the invocation of the method "testNotEqual" with the parameters 4 and 5, expecting the return value to be true
*/
@Test
public void testInvokeNotEqualWith4And5() {
try {
@ -227,6 +301,9 @@ public class E2E_LogicExpr {
}
}
/**
* Tests the invocation of the method "testNotEqual" with the parameters 5 and 4, expecting the return value to be true
*/
@Test
public void testInvokeNotEqualWith5And4() {
try {
@ -238,6 +315,9 @@ public class E2E_LogicExpr {
}
}
/**
* Tests the invocation of the method "testNotEqual" with the parameters 4 and 4, expecting the return value to be false
*/
@Test
public void testInvokeNotEqualWith4And4() {
try {
@ -249,6 +329,9 @@ public class E2E_LogicExpr {
}
}
/**
* Tests the invocation of the method "testSmallerEqual" with the parameters 4 and 5, expecting the return value to be true
*/
@Test
public void testInvokeSmallerEqualWith4And5() {
try {
@ -260,6 +343,9 @@ public class E2E_LogicExpr {
}
}
/**
* Tests the invocation of the method "testSmallerEqual" with the parameters 5 and 4, expecting the return value to be false
*/
@Test
public void testInvokeSmallerEqualWith5And4() {
try {
@ -271,6 +357,9 @@ public class E2E_LogicExpr {
}
}
/**
* Tests the invocation of the method "testSmallerEqual" with the parameters 4 and 4, expecting the return value to be true
*/
@Test
public void testInvokeSmallerEqualWith4And4() {
try {
@ -282,6 +371,9 @@ public class E2E_LogicExpr {
}
}
/**
* Tests the invocation of the method "testLargerEqual" with the parameters 4 and 5, expecting the return value to be false
*/
@Test
public void testInvokeLargerEqualWith4And5() {
try {
@ -293,6 +385,9 @@ public class E2E_LogicExpr {
}
}
/**
* Tests the invocation of the method "testLargerEqual" with the parameters 5 and 4, expecting the return value to be true
*/
@Test
public void testInvokeLargerEqualWith5And4() {
try {
@ -304,6 +399,9 @@ public class E2E_LogicExpr {
}
}
/**
* Tests the invocation of the method "testLargerEqual" with the parameters 4 and 4, expecting the return value to be true
*/
@Test
public void testInvokeLargerEqualWith4And4() {
try {
@ -315,6 +413,9 @@ public class E2E_LogicExpr {
}
}
/**
* Tests the invocation of the method "testAND" with the parameters true and true, expecting the return value to be true
*/
@Test
public void testInvokeANDWithTrueAndTrue() {
try {
@ -326,6 +427,9 @@ public class E2E_LogicExpr {
}
}
/**
* Tests the invocation of the method "testAND" with the parameters true and false, expecting the return value to be false
*/
@Test
public void testInvokeANDWithTrueAndFalse() {
try {
@ -337,6 +441,9 @@ public class E2E_LogicExpr {
}
}
/**
* Tests the invocation of the method "testAND" with the parameters false and true, expecting the return value to be false
*/
@Test
public void testInvokeANDWithFalseAndTrue() {
try {
@ -348,6 +455,9 @@ public class E2E_LogicExpr {
}
}
/**
* Tests the invocation of the method "testAND" with the parameters false and false, expecting the return value to be false
*/
@Test
public void testInvokeANDWithFalseAndFalse() {
try {
@ -359,6 +469,9 @@ public class E2E_LogicExpr {
}
}
/**
* Tests the invocation of the method "testOR" with the parameters true and true, expecting the return value to be true
*/
@Test
public void testInvokeORWithTrueAndTrue() {
try {
@ -370,6 +483,9 @@ public class E2E_LogicExpr {
}
}
/**
* Tests the invocation of the method "testOR" with the parameters true and false, expecting the return value to be true
*/
@Test
public void testInvokeORWithTrueAndFalse() {
try {
@ -381,6 +497,9 @@ public class E2E_LogicExpr {
}
}
/**
* Tests the invocation of the method "testOR" with the parameters false and true, expecting the return value to be true
*/
@Test
public void testInvokeORWithFalseAndTrue() {
try {
@ -392,6 +511,9 @@ public class E2E_LogicExpr {
}
}
/**
* Tests the invocation of the method "testOR" with the parameters false and false, expecting the return value to be false
*/
@Test
public void testInvokeORWithFalseAndFalse() {
try {

View File

@ -7,26 +7,43 @@ import org.junit.jupiter.api.Test;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.List;
/**
* Test class for testing if the compilation of the class 'Main' at src/test/testFiles/E2EFeatures/Main.java was successful,
* if the class contains the expected fields, methods and constructors and works as expected
*/
public class E2E_Main {
/**
* The BytecodeTestUtil instance for the test class, which provides methods for testing the compiled class
*/
private BytecodeTestUtil util;
/**
* Initializes the BytecodeTestUtil instance for the test class
*/
@BeforeEach
public void setUp() {
try {
util = new BytecodeTestUtil(List.of("src/test/testFiles/E2EFeatures/Main.java"), "Main");
util = new BytecodeTestUtil("src/test/testFiles/E2EFeatures/Main.java", "Main");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Tests the number of constructors in the class, expecting 1 constructor, which is the default constructor
*/
@Test
public void testConstructorCount() {
Assertions.assertEquals(1, util.getConstructorCount());
// default constructor
}
/**
* Tests name, parameter count and type of the returned object of the default constructor,
* expecting the default constructor to be named "Main", not to have any parameters and to return an object of type Main
*/
@Test
public void testDefaultConstructor() {
Assertions.assertEquals("Main", util.getConstructorNames().get(0));
@ -38,16 +55,25 @@ public class E2E_Main {
}
}
/**
* Tests the number of methods in the class, expecting 1 method
*/
@Test
public void testMethodCount() {
Assertions.assertEquals(1, util.getMethodCount());
}
/**
* Tests the name of the method, expecting the method to be named "main"
*/
@Test
public void testMethodNames() {
Assertions.assertEquals("main", util.getMethodNames().get(0));
}
/**
* Tests the return type of the method, expecting the method to return void
*/
@Test
public void testMethodReturnType() {
try {
@ -57,6 +83,9 @@ public class E2E_Main {
}
}
/**
* Tests the number of parameters of the method, expecting the method to have 1 parameter of type String[]
*/
@Test
public void testMethodParameters() {
try {
@ -69,21 +98,35 @@ public class E2E_Main {
}
}
/**
* Tests the number of fields in the class, expecting 1 field
*/
@Test
public void testFieldCount() {
Assertions.assertEquals(1, util.getFieldCount());
}
/**
* Tests the names of the fields in the class, expecting the field "i"
*/
@Test
public void testFieldNames() {
Assertions.assertEquals("i", util.getFieldNames().get(0));
}
/**
* Tests the types of the fields in the class, expecting the field "i" to be of type int
*/
@Test
public void testFieldTypes() {
Assertions.assertEquals("int", util.getFieldTypes().get(0));
}
/**
* Tests the values of the fields in the class, expecting the field "i" to be initialized with 0
*/
@Test
public void testFieldValues() {
try {
@ -93,6 +136,12 @@ public class E2E_Main {
}
}
/**
* Tests the invocation of the default constructor, expecting the returned object to be of type Main and the field
* "i" to be initialized with 0
*/
@Test
public void testInvokeDefaultConstructor() {
try {
@ -104,6 +153,9 @@ public class E2E_Main {
}
}
/**
* Tests the invocation of the main method, expecting the method to print the number 3 to the console
*/
@Test
public void testInvokeMainMethod() {
try {

View File

@ -5,27 +5,44 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.List;
/**
* Test class for testing if the compilation of the class 'Method' at src/test/testFiles/E2EFeatures/Method.java was successful,
* if the class contains the expected fields, methods and constructors and works as expected
*/
public class E2E_Method {
/**
* The BytecodeTestUtil instance for the test class, which provides methods for testing the compiled class
*/
private BytecodeTestUtil util;
/**
* Initializes the BytecodeTestUtil instance for the test class
*/
@BeforeEach
public void setUp() {
try {
util = new BytecodeTestUtil(List.of("src/test/testFiles/E2EFeatures/Method.java"), "Method");
util = new BytecodeTestUtil("src/test/testFiles/E2EFeatures/Method.java", "Method");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Tests the number of constructors in the class, expecting 1 constructor, which is the default constructor
*/
@Test
public void testConstructorCount() {
Assertions.assertEquals(1, util.getConstructorCount());
// default constructor
}
/**
* Tests name, parameter count and type of the returned object of the default constructor,
* expecting the default constructor to be named "Method", not to have any parameters and to return an object of type Method
*/
@Test
public void testConstructor() {
Assertions.assertEquals("Method", util.getConstructorNames().get(0));
@ -37,17 +54,28 @@ public class E2E_Method {
}
}
/**
* Tests the number of methods in the class, expecting 2 methods
*/
@Test
public void testMethodCount() {
Assertions.assertEquals(2, util.getMethodCount());
}
/**
* Tests the names of the methods in the class, expecting the methods to be named "method" and "method2"
*/
@Test
public void testMethodNames() {
Assertions.assertTrue(util.getMethodNames().contains("method"));
Assertions.assertTrue(util.getMethodNames().contains("method2"));
}
/**
* Tests the return type of the methods, expecting both methods to return void
*/
@Test
public void testMethodReturnType() {
try {
@ -58,6 +86,10 @@ public class E2E_Method {
}
}
/**
* Tests the number and types of the parameters of the methods, expecting the method "method" to have 0 parameters
* and the method "method2" to have 2 parameters of type int
*/
@Test
public void testMethodParameters() {
try {
@ -70,16 +102,27 @@ public class E2E_Method {
}
}
/**
* Tests the number of fields in the class, expecting 1 field
*/
@Test
public void testFieldCount() {
Assertions.assertEquals(1, util.getFieldCount());
}
/**
* Tests the names of the fields in the class, expecting the field "x"
*/
@Test
public void testFieldNames() {
Assertions.assertEquals("x", util.getFieldNames().get(0));
}
/**
* Tests the types of the fields in the class, expecting the field "x" to be of type int
*/
@Test
public void testFieldTypes() {
try {
@ -89,6 +132,9 @@ public class E2E_Method {
}
}
/**
* Tests the value of the field "x", expecting the field to be initialized with the value 0
*/
@Test
public void testFieldValues() {
try {
@ -98,6 +144,10 @@ public class E2E_Method {
}
}
/**
* Tests the invocation of the constructor, expecting the returned object to be of type Method and
* the field "x" to be initialized with 0
*/
@Test
public void testInvokeConstructor() {
try {
@ -109,7 +159,10 @@ public class E2E_Method {
}
}
/**
* Tests the invocation of the method "method", expecting the field "x" to be 0 before the method invocation and
* 10 after the method invocation
*/
@Test
public void testInvokeMethod() {
try {
@ -121,6 +174,10 @@ public class E2E_Method {
}
}
/**
* Tests the invocation of the method "method2" with the parameters 5 and 5, expecting the field "x" to be 0
* before the method invocation and 5 after the method invocation
*/
@Test
public void testInvokeMethod2() {
try {

View File

@ -5,27 +5,44 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.List;
/**
* Test class for testing if the compilation of the class 'MethodCall' at src/test/testFiles/E2EFeatures/MethodCall.java was successful,
* if the class contains the expected fields, methods and constructors and works as expected
*/
public class E2E_MethodCall {
/**
* The BytecodeTestUtil instance for the test class, which provides methods for testing the compiled class
*/
private BytecodeTestUtil util;
/**
* Initializes the BytecodeTestUtil instance for the test class
*/
@BeforeEach
public void setUp() {
try {
util = new BytecodeTestUtil(List.of("src/test/testFiles/E2EFeatures/MethodCall.java"), "MethodCall");
util = new BytecodeTestUtil("src/test/testFiles/E2EFeatures/MethodCall.java", "MethodCall");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Tests the number of constructors in the class, expecting 1 constructor, which is the default constructor
*/
@Test
public void testConstructorCount() {
Assertions.assertEquals(1, util.getConstructorCount());
// default constructor
}
/**
* Tests name, parameter count and type of the returned object of the default constructor,
* expecting the default constructor to be named "MethodCall", not to have any parameters and to return an object of type MethodCall
*/
@Test
public void testDefaultConstructor() {
Assertions.assertEquals("MethodCall", util.getConstructorNames().get(0));
@ -37,11 +54,20 @@ public class E2E_MethodCall {
}
}
/**
* Tests the number of methods in the class, expecting 6 methods
*/
@Test
public void testMethodCount() {
Assertions.assertEquals(6, util.getMethodCount());
}
/**
* Tests the names of the methods in the class, expecting the methods to be named "methodCall", "methodCall1",
* "methodCall2", "method", "method1" and "method2"
*/
@Test
public void testMethodNames() {
Assertions.assertTrue(util.getMethodNames().contains("methodCall"));
@ -52,6 +78,9 @@ public class E2E_MethodCall {
Assertions.assertTrue(util.getMethodNames().contains("method2"));
}
/**
* Tests the return type of the methods in the class, expecting "int" for all methods
*/
@Test
public void testMethodReturnType() {
try {
@ -66,6 +95,11 @@ public class E2E_MethodCall {
}
}
/**
* Tests the number and types of the parameters of the methods in the class, expecting the method
* "method" to have 0 parameters, the method "method1" to have 1 parameter of type int and the method
* "method2" to have 2 parameters of type int, the methods "methodCall", "methodCall1" and "methodCall2" to have 0 parameters
*/
@Test
public void testMethodParameters() {
try {
@ -83,11 +117,21 @@ public class E2E_MethodCall {
}
}
/**
* Tests the number of fields in the class, expecting 0 fields
*/
@Test
public void testFieldCount() {
Assertions.assertEquals(0, util.getFieldCount());
}
/**
* Tests the invocation of the default constructor, expecting the returned object to be of type MethodCall
*/
@Test
public void testInvokeDefaultConstructor() {
try {
@ -98,6 +142,9 @@ public class E2E_MethodCall {
}
}
/**
* Tests the invocation of the method "method", expecting the returned value to be 0
*/
@Test
public void testInvokeMethod() {
try {
@ -108,6 +155,9 @@ public class E2E_MethodCall {
}
}
/**
* Tests the invocation of the method "method1", expecting the returned value to be 3 when passing 3 as parameter
*/
@Test
public void testInvokeMethod1() {
try {
@ -118,6 +168,9 @@ public class E2E_MethodCall {
}
}
/**
* Tests the invocation of the method "method2", expecting the returned value to be 7 when passing 3 and 4 as parameters
*/
@Test
public void testInvokeMethod2() {
try {
@ -128,6 +181,9 @@ public class E2E_MethodCall {
}
}
/**
* Tests the invocation of the method "methodCall", expecting the returned value to be 0
*/
@Test
public void testInvokeMethodCall() {
try {
@ -138,6 +194,9 @@ public class E2E_MethodCall {
}
}
/**
* Tests the invocation of the method "methodCall1", expecting the returned value to be 1
*/
@Test
public void testInvokeMethodCall1() {
try {
@ -148,6 +207,9 @@ public class E2E_MethodCall {
}
}
/**
* Tests the invocation of the method "methodCall2", expecting the returned value to be 3
*/
@Test
public void testInvokeMethodCall2() {
try {

View File

@ -8,25 +8,42 @@ import org.junit.jupiter.api.Test;
import java.util.List;
/**
* Test class for testing if the compilation of the classes 'MultipleClasses1' and 'MultipleClasses2' at
* src/test/testFiles/E2EFeatures/MultipleClasses1.java and src/test/testFiles/E2EFeatures/MultipleClasses2.java was successful,
* and the dependencies work, if the class 'MultipleClasses1' contains the expected fields, methods and constructors and works as expected
*/
public class E2E_MultipleClasses {
/**
* The BytecodeTestUtil instance for the test class, which provides methods for testing the compiled class
*/
private BytecodeTestUtil util;
/**
* Initializes the BytecodeTestUtil instance for the test class
*/
@BeforeEach
public void setUp() {
try {
util = new BytecodeTestUtil(List.of("src/test/testFiles/E2EFeatures/MultipleClasses1.java",
"src/test/testFiles/E2EFeatures/MultipleClasses2.java"), "MultipleClasses1");
util = new BytecodeTestUtil("src/test/testFiles/E2EFeatures/MultipleClasses1.java", "MultipleClasses1");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Tests the number of constructors in the class, expecting 1 constructor,
*/
@Test
public void testConstructorCount() {
Assertions.assertEquals(1, util.getConstructorCount());
}
/**
* Tests name, parameter count and type of the returned object of the constructor,
* expecting the constructor to be named "MultipleClasses1", not to have any parameters and to return an object of type MultipleClasses1
*/
@Test
public void testConstructor() {
Assertions.assertEquals("MultipleClasses1", util.getConstructorNames().get(0));
@ -38,16 +55,27 @@ public class E2E_MultipleClasses {
}
}
/**
* Tests the number of methods in the class, expecting 1 method
*/
@Test
public void testMethodCount() {
Assertions.assertEquals(1, util.getMethodCount());
}
/**
* Tests the name of the method, expecting the method to be named "getIFromAnotherClass"
*/
@Test
public void testMethodNames() {
Assertions.assertEquals("getIFromAnotherClass", util.getMethodNames().get(0));
}
/**
* Tests the return type of the method, expecting the method to return an int
*/
@Test
public void testMethodReturnType() {
try {
@ -58,6 +86,9 @@ public class E2E_MultipleClasses {
}
}
/**
* Tests the number of parameters of the method, expecting 0 parameters
*/
@Test
public void testMethodParameters() {
try {
@ -68,16 +99,27 @@ public class E2E_MultipleClasses {
}
}
/**
* Tests the number of fields in the class, expecting 1 field
*/
@Test
public void testFieldCount() {
Assertions.assertEquals(1, util.getFieldCount());
}
/**
* Tests the names of the fields in the class, expecting the field "anotherClass"
*/
@Test
public void testFieldNames() {
Assertions.assertTrue(util.getFieldNames().contains("anotherClass"));
}
/**
* Tests the type of the fields in the class, expecting the field to be of type MultipleClasses2
*/
@Test
public void testFieldType() {
try {
@ -87,6 +129,9 @@ public class E2E_MultipleClasses {
}
}
/**
* Tests the value of the field "anotherClass", expecting the field to be of type MultipleClasses2
*/
@Test
public void testFieldValues() {
try {
@ -96,6 +141,10 @@ public class E2E_MultipleClasses {
}
}
/**
* Tests the invocation of the constructor, expecting the returned object to be of type MultipleClasses1,
* and the field "anotherClass" to be initialized with an object of type MultipleClasses2
*/
@Test
public void testInvokeConstructor() {
try {
@ -108,6 +157,9 @@ public class E2E_MultipleClasses {
}
}
/**
* Tests the invocation of the method "getIFromAnotherClass", expecting the returned value to be 4
*/
@Test
public void testInvokeGetIFromAnotherClass() {
try {
@ -118,6 +170,10 @@ public class E2E_MultipleClasses {
}
}
/**
* Tests the compilation without Exception to the class 'MultipleClasses2' and the correct dependency of the class
* 'MultipleClasses1' on 'MultipleClasses2' by just executing the compilation
*/
public static void main(String[] args) {
Compiler.generateByteCodeFilesFromFiles(List.of("src/test/testFiles/E2EFeatures/MultipleClasses1.java",
"src/test/testFiles/E2EFeatures/MultipleClasses2.java"));

View File

@ -5,28 +5,42 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.List;
/**
* Test class for testing if the compilation of the class 'Operators' at src/test/testFiles/E2EFeatures/Operators.java was successful,
* if the class contains the expected fields, methods and constructors and works as expected
*/
public class E2E_Operators {
/**
* The BytecodeTestUtil instance for the test class, which provides methods for testing the compiled class
*/
private BytecodeTestUtil util;
/**
* Initializes the BytecodeTestUtil instance for the test class
*/
@BeforeEach
public void setUp() {
try {
util = new BytecodeTestUtil(List.of("src/test/testFiles/E2EFeatures/Operators.java"), "Operators");
util = new BytecodeTestUtil("src/test/testFiles/E2EFeatures/Operators.java", "Operators");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Tests the number of constructors in the class, expecting 1 constructor, which is the default constructor
*/
@Test
public void testConstructorCount() {
Assertions.assertEquals(1, util.getConstructorCount());
// default constructor
}
/**
* Tests name, parameter count and type of the returned object of the default constructor,
* expecting the default constructor to be named "Operators", not to have any parameters and to return an object of type Operators
*/
@Test
public void testDefaultConstructor() {
Assertions.assertEquals("Operators", util.getConstructorNames().get(0));
@ -38,11 +52,20 @@ public class E2E_Operators {
}
}
/**
* Tests the number of methods in the class, expecting 8 methods
*/
@Test
public void testMethodCount() {
Assertions.assertEquals(8, util.getMethodCount());
}
/**
* Tests the names of the methods in the class, expecting the methods to be named "add", "sub", "mul", "div", "mod",
* "dotBeforeLine", "brackets" and "callOperatedMethods"
*/
@Test
public void testMethodNames() {
Assertions.assertTrue(util.getMethodNames().contains("add"));
@ -55,6 +78,9 @@ public class E2E_Operators {
Assertions.assertTrue(util.getMethodNames().contains("callOperatedMethods"));
}
/**
* Tests the return type of the methods, expecting "int" for all methods
*/
@Test
public void testMethodReturnType() {
try {
@ -71,6 +97,10 @@ public class E2E_Operators {
}
}
/**
* Tests the number and types of the parameters of the methods in the class, expecting the method
* "add", "sub", "mul", "div", "mod", "dotBeforeLine", "brackets" and "callOperatedMethods" to have 2 parameters of type int
*/
@Test
public void testMethodParameters() {
try {
@ -103,11 +133,19 @@ public class E2E_Operators {
}
}
/**
* Tests the number of fields in the class, expecting 0 fields
*/
@Test
public void testFieldCount() {
Assertions.assertEquals(0, util.getFieldCount());
}
/**
* Tests the invocation of the default constructor, expecting the returned object to be of type Operators
*/
@Test
public void testInvokeDefaultConstructor() {
try {
@ -118,6 +156,9 @@ public class E2E_Operators {
}
}
/**
* Tests the invocation of the method "add" with the parameters 3 and 5, expecting the returned value to be 8
*/
@Test
public void testAdd() {
try {
@ -128,6 +169,9 @@ public class E2E_Operators {
}
}
/**
* Tests the invocation of the method "sub" with the parameters 5 and 3, expecting the returned value to be 2
*/
@Test
public void testSub() {
try {
@ -138,6 +182,9 @@ public class E2E_Operators {
}
}
/**
* Tests the invocation of the method "mul" with the parameters 5 and 3, expecting the returned value to be 15
*/
@Test
public void testMul() {
try {
@ -148,6 +195,9 @@ public class E2E_Operators {
}
}
/**
* Tests the invocation of the method "div" with the parameters 5 and 3, expecting the returned value to be 1
*/
@Test
public void testDiv() {
try {
@ -158,6 +208,9 @@ public class E2E_Operators {
}
}
/**
* Tests the invocation of the method "mod" with the parameters 5 and 3, expecting the returned value to be 2
*/
@Test
public void testMod() {
try {
@ -168,6 +221,10 @@ public class E2E_Operators {
}
}
/**
* Tests the invocation of the method "dotBeforeLine" with the parameters 5 and 3, expecting the returned value to be 19
* (to see why the result is 19, see the method "dotBeforeLine" in file src/test/testFiles/E2EFeatures/Operators.java)
*/
@Test
public void testDotBeforeLine() {
try {
@ -178,6 +235,10 @@ public class E2E_Operators {
}
}
/**
* Tests the invocation of the method "brackets" with the parameters 5 and 3, expecting the returned value to be 40
* (to see why the result is 40, see the method "brackets" in file src/test/testFiles/E2EFeatures/Operators.java)
*/
@Test
public void testBrackets() {
try {
@ -188,6 +249,10 @@ public class E2E_Operators {
}
}
/**
* Tests the invocation of the method "callOperatedMethods" with the parameters 5 and 3, expecting the returned value to be 28
* (to see why the result is 28, see the method "callOperatedMethods" in file src/test/testFiles/E2EFeatures/Operators.java)
*/
@Test
public void testCallOperatedMethods() {
try {

View File

@ -5,27 +5,44 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.List;
/**
* Test class for testing if the compilation of the class 'Overloaded' at src/test/testFiles/E2EFeatures/Overloaded.java was successful,
* if the class contains the expected fields, methods and constructors and works as expected
*/
public class E2E_Overloaded {
/**
* The BytecodeTestUtil instance for the test class, which provides methods for testing the compiled class
*/
private BytecodeTestUtil util;
/**
* Initializes the BytecodeTestUtil instance for the test class
*/
@BeforeEach
public void setUp() {
try {
util = new BytecodeTestUtil(List.of("src/test/testFiles/E2EFeatures/Overloaded.java"), "Overloaded");
util = new BytecodeTestUtil("src/test/testFiles/E2EFeatures/Overloaded.java", "Overloaded");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Tests the number of constructors in the class, expecting 1 constructor, which is the default constructor
*/
@Test
public void testConstructorCount() {
Assertions.assertEquals(1, util.getConstructorCount());
// default constructor
}
/**
* Tests name, parameter count and type of the returned object of the default constructor,
* expecting the default constructor to be named "Overloaded", not to have any parameters and to return an object of type Overloaded
*/
@Test
public void testDefaultConstructor() {
Assertions.assertEquals("Overloaded", util.getConstructorNames().get(0));
@ -37,16 +54,27 @@ public class E2E_Overloaded {
}
}
/**
* Tests the number of methods in the class, expecting 3 methods
*/
@Test
public void testMethodCount() {
Assertions.assertEquals(3, util.getMethodCount());
}
/**
* Tests the names of the methods in the class, expecting the methods to be named "overloadedMethod"
*/
@Test
public void testMethodNames() {
Assertions.assertTrue(util.getMethodNames().contains("overloadedMethod"));
}
/**
* Tests the return type of each implementation of method "overloadedMethod", expecting "int"
*/
@Test
public void testMethodReturnType() {
try {
@ -58,6 +86,9 @@ public class E2E_Overloaded {
}
}
/**
* Tests the number of parameters of each implementation of method "overloadedMethod", expecting 0, 1 and 2 parameters
*/
@Test
public void testMethodParameters() {
try {
@ -69,6 +100,9 @@ public class E2E_Overloaded {
}
}
/**
* Tests the types of the parameters of each implementation of method "overloadedMethod", expecting "int" for all parameters
*/
@Test
public void testMethodParameterTypes() {
try {
@ -80,11 +114,21 @@ public class E2E_Overloaded {
}
}
/**
* Tests the number of fields in the class, expecting 0 fields
*/
@Test
public void testFieldCount() {
Assertions.assertEquals(0, util.getFieldCount());
}
/**
* Tests the invocation of the default constructor, expecting to return an object of type Overloaded
*/
@Test
public void testInvokeDefaultConstructor() {
try {
@ -95,6 +139,9 @@ public class E2E_Overloaded {
}
}
/**
* Tests the invocation of the method "overloadedMethod" without parameters, expecting the return value to be 0
*/
@Test
public void testInvokeOverloadedMethod1() {
try {
@ -105,6 +152,9 @@ public class E2E_Overloaded {
}
}
/**
* Tests the invocation of the method "overloadedMethod" with one parameter, expecting the return value to be the same as the parameter
*/
@Test
public void testInvokeOverloadedMethod2() {
try {
@ -115,6 +165,9 @@ public class E2E_Overloaded {
}
}
/**
* Tests the invocation of the method "overloadedMethod" with two parameters, expecting the return value to be the sum of the parameters
*/
@Test
public void testInvokeOverloadedMethod3() {
try {

View File

@ -7,27 +7,43 @@ import E2ETests.BytecodeTestUtil;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.util.List;
/**
* Test class for testing if the compilation of the class 'Print' at src/test/testFiles/E2EFeatures/Print.java was successful,
* if the class contains the expected fields, methods and constructors and works as expected
*/
public class E2E_Print {
/**
* The BytecodeTestUtil instance for the test class, which provides methods for testing the compiled class
*/
private BytecodeTestUtil util;
/**
* Initializes the BytecodeTestUtil instance for the test class
*/
@BeforeEach
public void setUp() {
try {
util = new BytecodeTestUtil(List.of("src/test/testFiles/E2EFeatures/Print.java"), "Print");
util = new BytecodeTestUtil("src/test/testFiles/E2EFeatures/Print.java", "Print");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Tests the number of constructors in the class, expecting 1 constructor, which is the default constructor
*/
@Test
public void testConstructorCount() {
Assertions.assertEquals(1, util.getConstructorCount());
// default constructor
}
/**
* Tests name, parameter count and type of the returned object of the default constructor,
* expecting the default constructor to be named "Print", not to have any parameters and to return an object of type Print
*/
@Test
public void testDefaultConstructor() {
Assertions.assertEquals("Print", util.getConstructorNames().get(0));
@ -39,17 +55,28 @@ public class E2E_Print {
}
}
/**
* Tests the number of methods in the class, expecting 2 methods
*/
@Test
public void testMethodCount() {
Assertions.assertEquals(2, util.getMethodCount());
}
/**
* Tests the names of the methods in the class, expecting the methods to be named "printIt" and "printMoreComplex"
*/
@Test
public void testMethodNames() {
Assertions.assertTrue(util.getMethodNames().contains("printIt"));
Assertions.assertTrue(util.getMethodNames().contains("printMoreComplex"));
}
/**
* Tests the return type of the methods, expecting the method "printIt" to return void and the method "printMoreComplex" to return void
*/
@Test
public void testMethodReturnType() {
try {
@ -60,10 +87,15 @@ public class E2E_Print {
}
}
/**
* Tests the number and types of the parameters of the methods, expecting the method "printIt" to have 1 parameter of type char
* and the method "printMoreComplex" to have 2 parameters of type int
*/
@Test
public void testMethodParameters() {
try {
Assertions.assertEquals(1, util.getMethodParameterCount("printIt", new Class<?>[]{char.class}));
Assertions.assertEquals("char", util.getMethodParameterTypes("printIt", new Class<?>[]{char.class}).get(0));
Assertions.assertEquals(2, util.getMethodParameterCount("printMoreComplex", new Class<?>[]{int.class, int.class}));
Assertions.assertEquals("int", util.getMethodParameterTypes("printMoreComplex", new Class<?>[]{int.class, int.class}).get(0));
Assertions.assertEquals("int", util.getMethodParameterTypes("printMoreComplex", new Class<?>[]{int.class, int.class}).get(1));
@ -72,11 +104,21 @@ public class E2E_Print {
}
}
/**
* Tests the number of fields in the class, expecting 0 fields
*/
@Test
public void testFieldCount() {
Assertions.assertEquals(0, util.getFieldCount());
}
/**
* Tests the invocation of the default constructor, expecting an object of type Print to be returned
*/
@Test
public void testInvokeDefaultConstructor() {
try {
@ -87,6 +129,9 @@ public class E2E_Print {
}
}
/**
* Tests the invocation of the method "printIt", expecting the method to print the character 'a' to the console
*/
@Test
public void testInvokePrintIt() {
try {
@ -105,6 +150,10 @@ public class E2E_Print {
}
}
/**
* Tests the invocation of the method "printMoreComplex", expecting the method to print the result of the comparison of the two integers to the console,#
* in this case the result of the comparison of 5 and 10, which is true
*/
@Test
public void testInvokePrintMoreComplex() {
try {

View File

@ -5,27 +5,44 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import E2ETests.BytecodeTestUtil;
import java.util.List;
/**
* Test class for testing if the compilation of the class 'Return' at src/test/testFiles/E2EFeatures/Return.java was successful,
* if the class contains the expected fields, methods and constructors and works as expected
*/
public class E2E_Return {
/**
* The BytecodeTestUtil instance for the test class, which provides methods for testing the compiled class
*/
private BytecodeTestUtil util;
/**
* Initializes the BytecodeTestUtil instance for the test class
*/
@BeforeEach
public void setUp() {
try {
util = new BytecodeTestUtil(List.of("src/test/testFiles/E2EFeatures/Return.java"), "Return");
util = new BytecodeTestUtil("src/test/testFiles/E2EFeatures/Return.java", "Return");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Tests the number of constructors in the class, expecting 1 constructor, which is the default constructor
*/
@Test
public void testConstructorCount() {
Assertions.assertEquals(1, util.getConstructorCount());
// default constructor
}
/**
* Tests name, parameter count and type of the returned object of the default constructor,
* expecting the default constructor to be named "Return", not to have any parameters and to return an object of type Return
*/
@Test
public void testDefaultConstructor() {
Assertions.assertEquals("Return", util.getConstructorNames().get(0));
@ -37,11 +54,20 @@ public class E2E_Return {
}
}
/**
* Tests the number of methods in the class, expecting 6 methods
*/
@Test
public void testMethodCount() {
Assertions.assertEquals(6, util.getMethodCount());
}
/**
* Tests the names of the methods in the class, expecting the methods to be named "returnInt", "returnVoid",
* "returnBoolean", "returnChar", "returnObject" and "returnAndInterruptFor"
*/
@Test
public void testMethodNames() {
Assertions.assertTrue(util.getMethodNames().contains("returnInt"));
@ -52,6 +78,11 @@ public class E2E_Return {
Assertions.assertTrue(util.getMethodNames().contains("returnAndInterruptFor"));
}
/**
* Tests the return type of the methods, expecting "int" for the method "returnInt", "void" for the method "returnVoid",
* "boolean" for the method "returnBoolean", "char" for the method "returnChar", "Return" for the method "returnObject"
* and "int" for the method "returnAndInterruptFor"
*/
@Test
public void testMethodReturnType() {
try {
@ -66,6 +97,9 @@ public class E2E_Return {
}
}
/**
* Tests the number of parameters of the methods, expecting 0 parameters for all methods
*/
@Test
public void testMethodParameters() {
try {
@ -80,11 +114,21 @@ public class E2E_Return {
}
}
/**
* Tests the number of fields in the class, expecting 0 fields
*/
@Test
public void testFieldCount() {
Assertions.assertEquals(0, util.getFieldCount());
}
/**
* Tests the invocation of the default constructor, expecting the returned object to be of type Return
*/
@Test
public void testInvokeDefaultConstructor() {
try {
@ -95,6 +139,9 @@ public class E2E_Return {
}
}
/**
* Tests the return value of the method "returnInt", expecting the method to return the integer 10
*/
@Test
public void testReturnInt() {
try {
@ -105,6 +152,9 @@ public class E2E_Return {
}
}
/**
* Tests the return value of the method "returnVoid", expecting the method to return null
*/
@Test
public void testReturnVoid() {
try {
@ -114,6 +164,9 @@ public class E2E_Return {
}
}
/**
* Tests the return value of the method "returnBoolean", expecting the method to return true
*/
@Test
public void testReturnBoolean() {
try {
@ -124,6 +177,9 @@ public class E2E_Return {
}
}
/**
* Tests the return value of the method "returnChar", expecting the method to return the character 'a'
*/
@Test
public void testReturnChar() {
try {
@ -134,6 +190,9 @@ public class E2E_Return {
}
}
/**
* Tests the return value of the method "returnObject", expecting the method to return an object of type Return
*/
@Test
public void testReturnObject() {
try {
@ -144,6 +203,11 @@ public class E2E_Return {
}
}
/**
* Tests the return value of the method "returnAndInterruptFor", expecting the method to return the integer 5
* (method contains a for loop with 10 iterations who are going from 10 to 1, but the loop is interrupted after 5
* iterations by a return statement)
*/
@Test
public void testReturnAndInterruptFor() {
try {

View File

@ -5,27 +5,44 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.List;
/**
* Test class for testing if the compilation of the class 'Unary' at src/test/testFiles/E2EFeatures/Unary.java was successful,
* if the class contains the expected fields, methods and constructors and works as expected
*/
public class E2E_Unary {
/**
* The BytecodeTestUtil instance for the test class, which provides methods for testing the compiled class
*/
private BytecodeTestUtil util;
/**
* Initializes the BytecodeTestUtil instance for the test class
*/
@BeforeEach
public void setUp() {
try {
util = new BytecodeTestUtil(List.of("src/test/testFiles/E2EFeatures/Unary.java"), "Unary");
util = new BytecodeTestUtil("src/test/testFiles/E2EFeatures/Unary.java", "Unary");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Tests the number of constructors in the class, expecting 1 constructor, which is the default constructor
*/
@Test
public void testConstructorCount() {
Assertions.assertEquals(1, util.getConstructorCount());
// default constructor
}
/**
* Tests name, parameter count and type of the returned object of the default constructor,
* expecting the default constructor to be named "Unary", not to have any parameters and to return an object of type Unary
*/
@Test
public void testDefaultConstructor() {
Assertions.assertEquals("Unary", util.getConstructorNames().get(0));
@ -37,17 +54,28 @@ public class E2E_Unary {
}
}
/**
* Tests the number of methods in the class, expecting 2 methods
*/
@Test
public void testMethodCount() {
Assertions.assertEquals(2, util.getMethodCount());
}
/**
* Tests the names of the methods in the class, expecting the methods to be named "testMinus" and "testNot"
*/
@Test
public void testMethodNames() {
Assertions.assertTrue(util.getMethodNames().contains("testMinus"));
Assertions.assertTrue(util.getMethodNames().contains("testNot"));
}
/**
* Tests the return type of the methods, expecting "int" for the method "testMinus" and "boolean" for the method "testNot"
*/
@Test
public void testMethodReturnType() {
try {
@ -60,6 +88,10 @@ public class E2E_Unary {
}
}
/**
* Tests the number and types of the parameters of the methods in the class, expecting the method "testMinus" to have 1 parameter of type int
* and the method "testNot" to have 1 parameter of type boolean
*/
@Test
public void testMethodParameters() {
try {
@ -76,11 +108,21 @@ public class E2E_Unary {
}
}
/**
* Tests the number of fields in the class, expecting 0 fields
*/
@Test
public void testFieldCount() {
Assertions.assertEquals(0, util.getFieldCount());
}
/**
* Tests the invocation of the default constructor, expecting the returned object to be of type Unary
*/
@Test
public void testInvokeDefaultConstructor() {
try {
@ -90,6 +132,9 @@ public class E2E_Unary {
}
}
/**
* Tests the invocation of the method "testMinus", expecting the returned value to be -5, when passing 5 as parameter
*/
@Test
public void testInvokeTestMinus() {
try {
@ -100,6 +145,9 @@ public class E2E_Unary {
}
}
/**
* Tests the invocation of the method "testNot", expecting the returned value to be true, when passing false as parameter
*/
@Test
public void testInvokeTestNot() {
try {

View File

@ -5,28 +5,45 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import E2ETests.BytecodeTestUtil;
import java.util.List;
/**
* Test class for testing if the compilation of the class 'VariableDefWithDecl' at src/test/testFiles/E2EFeatures/VariableDefWithDecl.java was successful,
* if the class contains the expected fields, methods and constructors and works as expected
*/
public class E2E_VariableDefWithDecl {
/**
* The BytecodeTestUtil instance for the test class, which provides methods for testing the compiled class
*/
private BytecodeTestUtil util;
/**
* Initializes the BytecodeTestUtil instance for the test class
*/
@BeforeEach
public void setUp() {
try {
util = new BytecodeTestUtil(List.of("src/test/testFiles/E2EFeatures/VariableDefWithDecl.java"),
util = new BytecodeTestUtil("src/test/testFiles/E2EFeatures/VariableDefWithDecl.java",
"VariableDefWithDecl");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Tests the number of constructors in the class, expecting 1 constructor, which is the default constructor
*/
@Test
public void testConstructorCount() {
Assertions.assertEquals(1, util.getConstructorCount());
// default constructor
}
/**
* Tests name, parameter count and type of the returned object of the default constructor,
* expecting the default constructor to be named "VariableDefWithDecl", not to have any parameters and to return an object of type VariableDefWithDecl
*/
@Test
public void testDefaultConstructor() {
Assertions.assertEquals("VariableDefWithDecl", util.getConstructorNames().get(0));
@ -38,17 +55,28 @@ public class E2E_VariableDefWithDecl {
}
}
/**
* Tests the number of methods in the class, expecting 2 methods
*/
@Test
public void testMethodCount() {
Assertions.assertEquals(2, util.getMethodCount());
}
/**
* Tests the names of the methods in the class, expecting the methods to be named "testDefWithDeclInOne" and "testDefWithDeclSeparate"
*/
@Test
public void testMethodNames() {
Assertions.assertTrue(util.getMethodNames().contains("testDefWithDeclInOne"));
Assertions.assertTrue(util.getMethodNames().contains("testDefWithDeclSeparate"));
}
/**
* Tests the return type of the methods "testDefWithDeclInOne" and "testDefWithDeclSeparate", expecting "int" for both methods
*/
@Test
public void testMethodReturnType() {
try {
@ -59,6 +87,10 @@ public class E2E_VariableDefWithDecl {
}
}
/**
* Tests the number of parameters of the methods "testDefWithDeclInOne" and "testDefWithDeclSeparate",
* expecting 0 parameters for both methods
*/
@Test
public void testMethodParameters() {
try {
@ -71,11 +103,21 @@ public class E2E_VariableDefWithDecl {
}
}
/**
* Tests the number of fields in the class, expecting 0 fields
*/
@Test
public void testFieldCount() {
Assertions.assertEquals(0, util.getFieldCount());
}
/**
* Tests the invocation of the default constructor, expecting the returned object to be of type VariableDefWithDecl
*/
@Test
public void testInvokeDefaultConstructor() {
try {
@ -86,6 +128,9 @@ public class E2E_VariableDefWithDecl {
}
}
/**
* Tests the invocation of the method "testDefWithDeclInOne", expecting the returned value to be 10
*/
@Test
public void testDefWithDeclInOne() {
try {
@ -96,6 +141,9 @@ public class E2E_VariableDefWithDecl {
}
}
/**
* Tests the invocation of the method "testDefWithDeclSeparate", expecting the returned value to be 10
*/
@Test
public void testDefWithDeclSeparate() {
try {

View File

@ -5,26 +5,41 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import E2ETests.BytecodeTestUtil;
import java.util.List;
/**
* Test class for testing if the compilation of the class 'While' at src/test/testFiles/E2EFeatures/While.java was successful,
* if the class contains the expected fields, methods and constructors and works as expected
*/
public class E2E_While {
/**
* The BytecodeTestUtil instance for the test class, which provides methods for testing the compiled class
*/
private BytecodeTestUtil util;
/**
* Initializes the BytecodeTestUtil instance for the test class
*/
@BeforeEach
public void setUp() {
try {
util = new BytecodeTestUtil(List.of("src/test/testFiles/E2EFeatures/While.java"), "While");
util = new BytecodeTestUtil("src/test/testFiles/E2EFeatures/While.java", "While");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
/**
* Tests the number of constructors in the class, expecting 1 constructor
*/
@Test
public void testConstructorCount() {
Assertions.assertEquals(1, util.getConstructorCount());
}
/**
* Tests name, parameter count and type of the returned object of the constructor,
* expecting the constructor to be named "While", not to have any parameters and to return an object of type While
*/
@Test
public void testConstructor() {
Assertions.assertEquals("While", util.getConstructorNames().get(0));
@ -36,17 +51,28 @@ public class E2E_While {
}
}
/**
* Tests the number of methods in the class, expecting 2 methods
*/
@Test
public void testMethodCount() {
Assertions.assertEquals(2, util.getMethodCount());
}
/**
* Tests the names of the methods in the class, expecting the methods to be named "whileLoop" and "doWhileLoop"
*/
@Test
public void testMethodNames() {
Assertions.assertTrue(util.getMethodNames().contains("whileLoop"));
Assertions.assertTrue(util.getMethodNames().contains("doWhileLoop"));
}
/**
* Tests the return type of the methods, expecting both methods to return void
*/
@Test
public void testMethodReturnType() {
try {
@ -57,7 +83,9 @@ public class E2E_While {
}
}
/**
* Tests the number of parameters of the methods, expecting both methods to have 0 parameters
*/
@Test
public void testMethodParameters() {
try {
@ -68,23 +96,37 @@ public class E2E_While {
}
}
/**
* Tests the number of fields in the class, expecting 2 fields
*/
@Test
public void testFieldCount() {
Assertions.assertEquals(2, util.getFieldCount());
}
/**
* Tests the names of the fields in the class, expecting the fields "whileRepetitions" and "doWhileRepetitions"
*/
@Test
public void testFieldNames() {
Assertions.assertTrue(util.getFieldNames().contains("whileRepetitions"));
Assertions.assertTrue(util.getFieldNames().contains("doWhileRepetitions"));
}
/**
* Tests the types of the fields in the class, expecting both fields to be of type int
*/
@Test
public void testFieldTypes() {
Assertions.assertEquals("int", util.getFieldTypes().get(0));
Assertions.assertEquals("int", util.getFieldTypes().get(1));
}
/**
* Tests the values of the fields in the class, expecting the fields "whileRepetitions" and "doWhileRepetitions" to be 1
*/
@Test
public void testFieldValues() {
try {
@ -95,6 +137,10 @@ public class E2E_While {
}
}
/**
* Tests the invocation of the constructor, expecting the returned object to be of type While and the fields
* "whileRepetitions" and "doWhileRepetitions" to be 1 after the initialization through constructor invocation
*/
@Test
public void testInvokeConstructor() {
try {
@ -107,6 +153,10 @@ public class E2E_While {
}
}
/**
* Tests the invocation of the method "whileLoop", expecting the field "whileRepetitions" to be 1 before the method invocation
* and 5 after the method invocation, the field "doWhileRepetitions" to be 1 before the method invocation and 1 after the method invocation
*/
@Test
public void testInvokeWhileLoop() {
try {
@ -120,6 +170,10 @@ public class E2E_While {
}
}
/**
* Tests the invocation of the method "doWhileLoop", expecting the field "whileRepetitions" to be 1 before the method invocation
* and 1 after the method invocation, the field "doWhileRepetitions" to be 1 before the method invocation and 6 after the method invocation
*/
@Test
public void testInvokeDoWhileLoop() {
try {

View File

@ -1,6 +1,8 @@
package HelpClasses;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.platform.commons.support.HierarchyTraversalMode;
import org.junit.platform.commons.support.ReflectionSupport;
@ -11,30 +13,51 @@ import java.util.List;
import java.util.Optional;
public class TestFileTester {
/**
* Execute all methods annotated with @Test in the given class.
*
* @param testClass The class containing the test methods.
*/
public static void run(Class<?> testClass) {
List<String> failedTests = new ArrayList<>();
// Finde alle Methoden, die mit @Test annotiert sind
// Find all methods annotated with @Test in the given class and save them in a list
List<Method> testMethods = ReflectionSupport.findMethods(
testClass,
method -> method.isAnnotationPresent(Test.class),
HierarchyTraversalMode.TOP_DOWN
);
// Execute for all test methods found
for (Method testMethod : testMethods) {
try {
// Erstelle eine Instanz der Testklasse
// Create an instance of the test class
Object testInstance = ReflectionSupport.newInstance(testClass);
// Führe die Setup-Methode aus (falls vorhanden)
Optional<Method> setUpMethodOptional = ReflectionSupport.findMethod(testClass, "setUp");
if (setUpMethodOptional.isPresent()) {
setUpMethodOptional.get().invoke(testInstance);
// Execute all methods annotated with @BeforeEach in the given class
List<Method>beforeEachMethods = ReflectionSupport.findMethods(
testClass,
method -> method.isAnnotationPresent(BeforeEach.class),
HierarchyTraversalMode.TOP_DOWN
);
for (Method beforeEachMethod : beforeEachMethods) {
beforeEachMethod.invoke(testInstance);
}
// Führe die Testmethode aus
// Execute the test method
testMethod.invoke(testInstance);
// Execute all methods annotated with @AfterEach in the given class
List<Method> afterEachMethods = ReflectionSupport.findMethods(
testClass,
method -> method.isAnnotationPresent(AfterEach.class),
HierarchyTraversalMode.TOP_DOWN
);
for (Method afterEachMethod : afterEachMethods) {
afterEachMethod.invoke(testInstance);
}
} catch (Exception e) {
// If the test method throws an exception, save the exception message in the failedTests list
if (e.getCause() != null) {
failedTests.add(testMethod.getName() + ": " + e.getCause().getMessage());
} else {
@ -43,6 +66,7 @@ public class TestFileTester {
}
}
// If there are failed tests, print them and fail the test class, otherwise print a success message
if (!failedTests.isEmpty()) {
failedTests.forEach(System.err::println);
Assertions.fail("Ein oder mehrere Tests sind fehlgeschlagen.");

View File

@ -7,33 +7,43 @@ import java.util.List;
import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* Tests for calling a variable outside its scope.
* see src/test/testFiles/Negative/CallVariableOutsideScope for the test files.
*/
public class CallVariableOutsideScope {
// Having a variable declared inside an Else-block and trying to call it outside the block.
@Test
public void CallVariableOutsideScopeOfElse() {
assertThrows(Exception.class, () -> Compiler.generateByteCodeArrayFromFiles(List.of("src/test/testFiles/Negative/CallVariableOutsideScope/OfElse.java")));
}
// Having a variable declared inside a For-loop and trying to call it outside the loop.
@Test
public void CallVariableOutsideScopeOfFor() {
assertThrows(Exception.class, () -> Compiler.generateByteCodeArrayFromFiles(List.of("src/test/testFiles/Negative/CallVariableOutsideScope/OfFor.java")));
}
// Having a variable declared inside an If-block and trying to call it outside the block.
@Test
public void CallVariableOutsideScopeOfIf() {
assertThrows(Exception.class, () -> Compiler.generateByteCodeArrayFromFiles(List.of("src/test/testFiles/Negative/CallVariableOutsideScope/OfIf.java")));
}
// Having a variable declared inside an IfElse-block and trying to call it outside the block.
@Test
public void CallVariableOutsideScopeOfIfElse() {
assertThrows(Exception.class, () -> Compiler.generateByteCodeArrayFromFiles(List.of("src/test/testFiles/Negative/CallVariableOutsideScope/OfIfElse.java")));
}
// Having a variable declared inside a Method and trying to call it outside the method.
@Test
public void CallVariableOutsideScopeOfMethod() {
assertThrows(Exception.class, () -> Compiler.generateByteCodeArrayFromFiles(List.of("src/test/testFiles/Negative/CallVariableOutsideScope/OfMethod.java")));
}
// Having a variable declared inside a While-loop and trying to call it outside the loop.
@Test
public void CallVariableOutsideScopeOfWhile() {
assertThrows(Exception.class, () -> Compiler.generateByteCodeArrayFromFiles(List.of("src/test/testFiles/Negative/CallVariableOutsideScope/OfWhile.java")));

View File

@ -7,7 +7,13 @@ import java.util.List;
import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* Tests for forbidden particularities in implementation.
* see src/test/testFiles/Negative/ForbiddenParticularitiesInImplementation for the test files.
*/
public class ForbiddenParticularitiesInImplementation {
// Using any access modifier other than public
@Test
public void ForbiddenParticularitiesInImplementationAccessModifier() {
assertThrows(Exception.class, () -> Compiler.generateByteCodeArrayFromFiles(List.of(
@ -15,6 +21,7 @@ public class ForbiddenParticularitiesInImplementation {
"AccessModifier.java")));
}
// Addressing a field without using this
@Test
public void ForbiddenParticularitiesInImplementationAddressingFieldWithoutThis() {
assertThrows(Exception.class, () -> Compiler.generateByteCodeArrayFromFiles(List.of(
@ -22,6 +29,7 @@ public class ForbiddenParticularitiesInImplementation {
"AddressingFieldWithoutThis.java")));
}
// Using i-- outside a for-loop or a statement
@Test
public void ForbiddenParticularitiesInImplementationIMinusMinus() {
assertThrows(Exception.class, () -> Compiler.generateByteCodeArrayFromFiles(List.of(
@ -29,6 +37,7 @@ public class ForbiddenParticularitiesInImplementation {
"IMinusMinusNotInForOrStatement.java")));
}
// Using i++ outside a for-loop or a statement
@Test
public void ForbiddenParticularitiesInImplementationIPlusPlus() {
assertThrows(Exception.class, () -> Compiler.generateByteCodeArrayFromFiles(List.of(
@ -36,6 +45,7 @@ public class ForbiddenParticularitiesInImplementation {
"IPlusPlusNotInForOrStatement.java")));
}
// Using --i
@Test
public void ForbiddenParticularitiesInImplementationMinusMinusI() {
assertThrows(Exception.class, () -> Compiler.generateByteCodeArrayFromFiles(List.of(
@ -43,6 +53,7 @@ public class ForbiddenParticularitiesInImplementation {
"MinusMinusI.java")));
}
// Using ++i
@Test
public void ForbiddenParticularitiesInImplementationPlusPlusI() {
assertThrows(Exception.class, () -> Compiler.generateByteCodeArrayFromFiles(List.of(
@ -50,6 +61,7 @@ public class ForbiddenParticularitiesInImplementation {
"PlusPlusI.java")));
}
// Using System.out.println
@Test
public void ForbiddenParticularitiesInImplementationUsingSystemOut() {
assertThrows(Exception.class, () -> Compiler.generateByteCodeArrayFromFiles(List.of(

View File

@ -7,6 +7,11 @@ import java.util.List;
import static org.junit.jupiter.api.Assertions.assertThrows;
/**
* Tests for missing components.
* see src/test/testFiles/Negative/MissingComponents for the test files.
*/
public class MissingComponents {
@Test