diff --git a/marker/etc/MarkerDiagram.png b/marker/etc/MarkerDiagram.png
new file mode 100644
index 000000000..6ed4f9c56
Binary files /dev/null and b/marker/etc/MarkerDiagram.png differ
diff --git a/marker/etc/MarkerDiagram.ucls b/marker/etc/MarkerDiagram.ucls
new file mode 100644
index 000000000..0f8376e40
--- /dev/null
+++ b/marker/etc/MarkerDiagram.ucls
@@ -0,0 +1,41 @@
+
+
+ * Marker interface vs annotation + * Marker interfaces and marker annotations both have their uses, + * neither of them is obsolete or always better then the other one. + * If you want to define a type that does not have any new methods associated with it, + * a marker interface is the way to go. + * If you want to mark program elements other than classes and interfaces, + * to allow for the possibility of adding more information to the marker in the future, + * or to fit the marker into a framework that already makes heavy use of annotation types, + * then a marker annotation is the correct choice */ public class App { + + /** + * Program entry point + * + * @param args command line args + */ public static void main(String[] args) { + Guard guard = new Guard(); + Thief thief = new Thief(); if (guard instanceof Permission) { guard.enter(); + } else { + System.out.println("You have no permission to enter, please leave this area"); + } + + if (thief instanceof Permission) { + thief.steal(); + } else { + thief.doNothing(); } } } diff --git a/marker/src/main/java/Thief.java b/marker/src/main/java/Thief.java new file mode 100644 index 000000000..33eac5aca --- /dev/null +++ b/marker/src/main/java/Thief.java @@ -0,0 +1,12 @@ +/** + * Created by Alexis on 02-May-17. + */ +public class Thief { + protected static void steal() { + System.out.println("Steal valuable items"); + } + + protected static void doNothing() { + System.out.println("Pretend nothing happened and just leave"); + } +} diff --git a/marker/src/test/java/AppTest.java b/marker/src/test/java/AppTest.java new file mode 100644 index 000000000..615a3c910 --- /dev/null +++ b/marker/src/test/java/AppTest.java @@ -0,0 +1,17 @@ +/** + * Created by Alexis on 01-May-17. + */ + +import org.junit.Test; + +/** + * Application test + */ +public class AppTest { + + @Test + public void test() { + String[] args = {}; + App.main(args); + } +} diff --git a/marker/src/test/java/GuardTest.java b/marker/src/test/java/GuardTest.java new file mode 100644 index 000000000..459447367 --- /dev/null +++ b/marker/src/test/java/GuardTest.java @@ -0,0 +1,16 @@ +import org.junit.Test; + +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.junit.Assert.assertThat; + +/** + * Created by Alexis on 02-May-17. + */ +public class GuardTest { + + @Test + public void testGuard() { + Guard guard = new Guard(); + assertThat(guard, instanceOf(Permission.class)); + } +} diff --git a/marker/src/test/java/ThiefTest.java b/marker/src/test/java/ThiefTest.java new file mode 100644 index 000000000..37409ecb3 --- /dev/null +++ b/marker/src/test/java/ThiefTest.java @@ -0,0 +1,15 @@ +/** + * Created by Alexis on 02-May-17. + */ + +import org.junit.Test; + +import static org.junit.Assert.assertFalse; + +public class ThiefTest { + @Test + public void testGuard() { + Thief thief = new Thief(); + assertFalse(thief instanceof Permission); + } +}