diff --git a/Uenung6/MyApplicationExtraTest/MyApplicationExtraTest.java b/Uebung6/MyApplicationExtraTest/MyApplicationExtraTest.java similarity index 100% rename from Uenung6/MyApplicationExtraTest/MyApplicationExtraTest.java rename to Uebung6/MyApplicationExtraTest/MyApplicationExtraTest.java diff --git a/Uenung6/MyApplicationExtraTest/SubjectInstance.java b/Uebung6/MyApplicationExtraTest/SubjectInstance.java similarity index 100% rename from Uenung6/MyApplicationExtraTest/SubjectInstance.java rename to Uebung6/MyApplicationExtraTest/SubjectInstance.java diff --git a/Uebung6/MyApplicationExtraTest2.java b/Uebung6/MyApplicationExtraTest2.java new file mode 100644 index 0000000000000000000000000000000000000000..159d291fca01d1b9e8e761212c513b6e3c43a113 --- /dev/null +++ b/Uebung6/MyApplicationExtraTest2.java @@ -0,0 +1,123 @@ +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; + } + +} diff --git a/Uebung6/README.md b/Uebung6/README.md new file mode 100644 index 0000000000000000000000000000000000000000..9b2ef29078e12a8ece7da65688d94bc59c7ac9e0 --- /dev/null +++ b/Uebung6/README.md @@ -0,0 +1,4 @@ +## 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 diff --git a/Uenung6/.gitkeep b/Uenung6/.gitkeep deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/Uenung6/MyApplicationExtraTest/.gitkeep b/Uenung6/MyApplicationExtraTest/.gitkeep deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/Uenung6/README.md b/Uenung6/README.md deleted file mode 100644 index fdbf412dadf3cc77fc826d0335b1b01b4932e68d..0000000000000000000000000000000000000000 --- a/Uenung6/README.md +++ /dev/null @@ -1,2 +0,0 @@ -##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