Skip to content

Commit e6c74a5

Browse files
Java 11 migraiton: marker
1 parent 751b3b9 commit e6c74a5

File tree

6 files changed

+14
-29
lines changed

6 files changed

+14
-29
lines changed

marker/src/main/java/App.java

+4-19
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
* THE SOFTWARE.
2222
*/
2323

24-
import org.slf4j.Logger;
25-
import org.slf4j.LoggerFactory;
26-
2724
/**
2825
* Created by Alexis on 28-Apr-17. With Marker interface idea is to make empty interface and extend
2926
* it. Basically it is just to identify the special objects from normal objects. Like in case of
@@ -46,22 +43,10 @@ public class App {
4643
* @param args command line args
4744
*/
4845
public static void main(String[] args) {
49-
50-
final Logger logger = LoggerFactory.getLogger(App.class);
51-
Guard guard = new Guard();
52-
Thief thief = new Thief();
53-
54-
if (guard instanceof Permission) {
55-
guard.enter();
56-
} else {
57-
logger.info("You have no permission to enter, please leave this area");
58-
}
59-
60-
if (thief instanceof Permission) {
61-
thief.steal();
62-
} else {
63-
thief.doNothing();
64-
}
46+
var guard = new Guard();
47+
var thief = new Thief();
48+
guard.enter();
49+
thief.doNothing();
6550
}
6651
}
6752

marker/src/main/java/Guard.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ public class Guard implements Permission {
3131

3232
private static final Logger LOGGER = LoggerFactory.getLogger(Guard.class);
3333

34-
protected static void enter() {
35-
34+
protected void enter() {
3635
LOGGER.info("You can enter");
3736
}
3837
}

marker/src/main/java/Thief.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ protected static void steal() {
3535
LOGGER.info("Steal valuable items");
3636
}
3737

38-
protected static void doNothing() {
38+
protected void doNothing() {
3939
LOGGER.info("Pretend nothing happened and just leave");
4040
}
4141
}

marker/src/test/java/AppTest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ public class AppTest {
3030

3131
@Test
3232
public void test() {
33-
String[] args = {};
34-
App.main(args);
33+
App.main(new String[]{});
3534
}
3635
}

marker/src/test/java/GuardTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class GuardTest {
3333

3434
@Test
3535
public void testGuard() {
36-
Guard guard = new Guard();
36+
var guard = new Guard();
3737
assertThat(guard, instanceOf(Permission.class));
3838
}
3939
}

marker/src/test/java/ThiefTest.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,19 @@
2121
* THE SOFTWARE.
2222
*/
2323

24-
import org.junit.jupiter.api.Test;
24+
import static org.hamcrest.CoreMatchers.instanceOf;
25+
import static org.hamcrest.CoreMatchers.not;
26+
import static org.hamcrest.MatcherAssert.assertThat;
2527

26-
import static org.junit.jupiter.api.Assertions.assertFalse;
28+
import org.junit.jupiter.api.Test;
2729

2830
/**
2931
* Thief test
3032
*/
3133
public class ThiefTest {
3234
@Test
3335
public void testThief() {
34-
Thief thief = new Thief();
35-
assertFalse(thief instanceof Permission);
36+
var thief = new Thief();
37+
assertThat(thief, not(instanceOf(Permission.class)));
3638
}
3739
}

0 commit comments

Comments
 (0)