Java 11 migraiton: marker

This commit is contained in:
Anurag Agarwal
2020-04-12 21:11:48 +00:00
parent 751b3b9452
commit e6c74a5fb9
6 changed files with 14 additions and 29 deletions

View File

@ -21,9 +21,6 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* Created by Alexis on 28-Apr-17. With Marker interface idea is to make empty interface and extend * Created by Alexis on 28-Apr-17. With Marker interface idea is to make empty interface and extend
* it. Basically it is just to identify the special objects from normal objects. Like in case of * it. Basically it is just to identify the special objects from normal objects. Like in case of
@ -46,22 +43,10 @@ public class App {
* @param args command line args * @param args command line args
*/ */
public static void main(String[] args) { public static void main(String[] args) {
var guard = new Guard();
final Logger logger = LoggerFactory.getLogger(App.class); var thief = new Thief();
Guard guard = new Guard();
Thief thief = new Thief();
if (guard instanceof Permission) {
guard.enter(); guard.enter();
} else {
logger.info("You have no permission to enter, please leave this area");
}
if (thief instanceof Permission) {
thief.steal();
} else {
thief.doNothing(); thief.doNothing();
} }
} }
}

View File

@ -31,8 +31,7 @@ public class Guard implements Permission {
private static final Logger LOGGER = LoggerFactory.getLogger(Guard.class); private static final Logger LOGGER = LoggerFactory.getLogger(Guard.class);
protected static void enter() { protected void enter() {
LOGGER.info("You can enter"); LOGGER.info("You can enter");
} }
} }

View File

@ -35,7 +35,7 @@ public class Thief {
LOGGER.info("Steal valuable items"); LOGGER.info("Steal valuable items");
} }
protected static void doNothing() { protected void doNothing() {
LOGGER.info("Pretend nothing happened and just leave"); LOGGER.info("Pretend nothing happened and just leave");
} }
} }

View File

@ -30,7 +30,6 @@ public class AppTest {
@Test @Test
public void test() { public void test() {
String[] args = {}; App.main(new String[]{});
App.main(args);
} }
} }

View File

@ -33,7 +33,7 @@ public class GuardTest {
@Test @Test
public void testGuard() { public void testGuard() {
Guard guard = new Guard(); var guard = new Guard();
assertThat(guard, instanceOf(Permission.class)); assertThat(guard, instanceOf(Permission.class));
} }
} }

View File

@ -21,9 +21,11 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
import org.junit.jupiter.api.Test; import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.jupiter.api.Assertions.assertFalse; import org.junit.jupiter.api.Test;
/** /**
* Thief test * Thief test
@ -31,7 +33,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse;
public class ThiefTest { public class ThiefTest {
@Test @Test
public void testThief() { public void testThief() {
Thief thief = new Thief(); var thief = new Thief();
assertFalse(thief instanceof Permission); assertThat(thief, not(instanceOf(Permission.class)));
} }
} }