Skip to content
Snippets Groups Projects
Commit c9f61ba3 authored by Gabriel's avatar Gabriel
Browse files

Rechtschreibfehlerkorrektur Ordner Uebung6, Hinzufügen eines weiteren Tests

parent 3f89ea6d
No related branches found
No related tags found
No related merge requests found
import static org.junit.Assert.assertTrue;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import org.junit.Test;
public class MyApplicationExtraTest {
// ========== SYSTEM ==========
protected static final String EX_NAME_UML2JAVA = "UML2JAVA";
// ========== PUBLIC TEST ==========
@Test(timeout = 666)
public void pubTest_smokeTest() {
Controller c = null;
MyApplication ma = null;
DataStore ds = null;
Subject s = null;
DataStoreObserver dso = null;
Observer o = null;
assertTrue(c == null && ma == null && ds == null && s == null && dso == null && o == null);
ViewTable vt = null;
ViewTableLandscape vtl = null;
ViewTableNormal vtn = null;
ViewSum vs = null;
ViewSumColumn vsc = null;
ViewSumRow vsr = null;
assertTrue(vt == null && vtl == null && vtn == null && vs == null && vsc == null && vsr == null);
}
@Test(timeout = 666)
public void pubTest_interfaceTest() {
assertTrue("MyApplication should implement Controller!", firstInterface(MyApplication.class) == Controller.class);
assertTrue("DataStoreObserver should implement Observer!", firstInterface(DataStoreObserver.class) == Observer.class);
}
@Test(timeout = 666)
public void pubTest_abstractTest() {
assertTrue("DataStore should be a Subclass of Subject!", DataStore.class.getSuperclass() == Subject.class);
assertTrue("ViewTable should be a Subclass of DataStoreObserver!", ViewTable.class.getSuperclass() == DataStoreObserver.class);
assertTrue("ViewTableLandscape should be a Subclass of ViewTable!", ViewTableLandscape.class.getSuperclass() == ViewTable.class);
assertTrue("ViewTableNormal should be a Subclass of ViewTable!", ViewTableNormal.class.getSuperclass() == ViewTable.class);
assertTrue("ViewSum should be a Subclass of DataStoreObserver!", ViewSum.class.getSuperclass() == DataStoreObserver.class);
assertTrue("ViewSumColumn should be a Subclass of ViewSum!", ViewSumColumn.class.getSuperclass() == ViewSum.class);
assertTrue("ViewSumRow should be a Subclass of ViewSum!", ViewSumRow.class.getSuperclass() == ViewSum.class);
}
@Test(timeout = 666)
public void pubTest_attributeTest() {
//JUST SOME NOT ALL
Field[] fields = MyApplication.class.getDeclaredFields();
assertTrue("MyApplication has to declare the private field \"dataStore\"", (fields == null)?false:(fields[0].getName().equals("dataStore") && fields[0].getType() == DataStore.class && Modifier.isPrivate(fields[0].getModifiers())));
fields = DataStoreObserver.class.getDeclaredFields();
assertTrue("DataStoreObserver has to declare the protected field \"dataStore\"", (fields == null)?false:(fields[0].getName().equals("dataStore") && fields[0].getType() == DataStore.class && Modifier.isProtected(fields[0].getModifiers())));
fields = Subject.class.getDeclaredFields();
try {
Field observer = Subject.class.getDeclaredField("observer");
if(!observer.getType().getSimpleName().equals("Observer[]")) assertTrue("Subject has do declare the private field \"observer\"!", false);
if(!Modifier.isPrivate(observer.getModifiers())) assertTrue("Subject has do declare the private field \"observer\"!", false);
}catch(Exception e) {
assertTrue("Subject has do declare the private field \"observer\" and \"MAX_OBSERVERS\"!", false);
e.printStackTrace();
}
}
@Test(timeout = 666)
public void pubTest_methodsAndConstructorsTest() {
//ViewSum
try {
Method sum = ViewSum.class.getDeclaredMethod("sum", int.class);
if(!Modifier.isProtected(sum.getModifiers()) || !Modifier.isAbstract(sum.getModifiers())) assertTrue("ViewSum has to declare the protected abstract method sum(int index)!", false);
Constructor<ViewSum> constructor = ViewSum.class.getDeclaredConstructor(DataStore.class);
if(!Modifier.isProtected(constructor.getModifiers()));
} catch (NoSuchMethodException | SecurityException e) {
assertTrue("ViewSum has to declare the protected abstract method sum(int index) and the protected Constructor ViewSum(DataStore dataStore)!", false);
e.printStackTrace();
}
//DataStoreObserver
try {
Constructor<DataStoreObserver> constructor = DataStoreObserver.class.getDeclaredConstructor(DataStore.class);
if(!Modifier.isProtected(constructor.getModifiers()))assertTrue("DataStoreObserver has to declare the protected Constructor DataStoreObserver(DataStore dataStore)!", false);
} catch (NoSuchMethodException | SecurityException e) {
assertTrue("DataStoreObserver has to declare the protected Constructor DataStoreObserver(DataStore dataStore)!", false);
e.printStackTrace();
}
//ViewSumRow
try {
Method sum = ViewSumRow.class.getDeclaredMethod("sum", int.class);
if(!Modifier.isProtected(sum.getModifiers()) || Modifier.isAbstract(sum.getModifiers()))assertTrue("ViewSumRow has to declare the protected method sum(int index)!", false);
}catch (NoSuchMethodException | SecurityException e) {
assertTrue("ViewSumRow has to declare the protected method sum(int index)!", false);
e.printStackTrace();
}
//ViewSumCol
try {
Method sum = ViewSumColumn.class.getDeclaredMethod("sum", int.class);
if(!Modifier.isPublic(sum.getModifiers()) || Modifier.isAbstract(sum.getModifiers()))assertTrue("ViewSumColumn has to declare the public method sum(int index)!", false);
}catch (NoSuchMethodException | SecurityException e) {
assertTrue("ViewSumColumn has to declare the public method sum(int index)!", false);
e.printStackTrace();
}
//ViewTable
try {
Constructor<ViewTable> constructor = ViewTable.class.getDeclaredConstructor(DataStore.class);
if(!Modifier.isProtected(constructor.getModifiers()))assertTrue("ViewTable has to declare the protected Constructor ViewTable(DataStore dataStore)!", false);
} catch (NoSuchMethodException | SecurityException e) {
assertTrue("ViewTable has to declare the protected Constructor ViewTable(DataStore dataStore)!", false);
e.printStackTrace();
}
try {
Method sum = ViewTable.class.getDeclaredMethod("format", int.class);
if(!Modifier.isProtected(sum.getModifiers()) || !Modifier.isStatic(sum.getModifiers()))assertTrue("ViewSumRow has to declare the protected method sum(int index)!", false);
}catch (NoSuchMethodException | SecurityException e) {
assertTrue("ViewTable has to declare the protected method format(int value)!", false);
e.printStackTrace();
}
}
@SuppressWarnings("rawtypes")
private Type firstInterface(Class c) {
if(c.getGenericInterfaces().length != 0) return c.getGenericInterfaces()[0];
return null;
}
}
## MyApplication
**MyApplicationExtraTest** - Ordner - *(von Mark Emmert, @im23ukuf)*: In dem Ordner befindet sich ein umfassender Test. Beide Dateien werden für den test benötigt, sonst gibt es einen Fehler!
**MyApplicationExtraTest2** *(von David Schwarzbeck, nicht auf Gitlab)*: Eine kleine Erweiterung für die Gruppenaufgabe.
\ No newline at end of file
##MyApplication
*(von Mark Emmert, @im23ukuf)*: In dem Ordner befindet sich ein umfassender Test. Beide Dateien werden für den test benötigt, sonst gibt es einen Fehler!
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment