22
33import org .junit .jupiter .api .Assertions ;
44import org .junit .jupiter .api .Test ;
5+ import pl .mperor .lab .common .TestUtils ;
56
67import javax .imageio .ImageIO ;
78import java .awt .image .BufferedImage ;
9+ import java .beans .EventHandler ;
810import java .io .*;
911import java .net .InetSocketAddress ;
1012import java .net .ServerSocket ;
1113import java .nio .channels .ServerSocketChannel ;
1214import java .nio .channels .SocketChannel ;
1315import java .nio .file .Files ;
1416import java .nio .file .Path ;
17+ import java .nio .file .attribute .BasicFileAttributes ;
18+ import java .nio .file .attribute .FileTime ;
19+ import java .time .Instant ;
1520import java .util .concurrent .CountDownLatch ;
1621import java .util .concurrent .Executors ;
1722import java .util .logging .Logger ;
@@ -34,11 +39,17 @@ public void testAssertionKeyWord() {
3439
3540 @ Test
3641 public void testNewInputOutputAkaNIO () throws IOException {
42+ Instant beforeAccessTime = Instant .now ();
3743 Path path = Path .of ("src" , "test" , "resources" , "nio.txt" );
44+
3845 byte [] fileBytes = Files .readAllBytes (path );
3946 String content = new String (fileBytes );
40-
4147 Assertions .assertEquals ("Hello NIO!" , content );
48+
49+ var fileTime = Files .readAttributes (path , BasicFileAttributes .class )
50+ .lastAccessTime ();
51+ System .out .printf ("📃 File '%s' - last access time: ⌚%s%n: " , path .getFileName (), fileTime );
52+ Assertions .assertTrue (FileTime .from (beforeAccessTime ).compareTo (fileTime ) <= 0 );
4253 }
4354
4455 @ Test
@@ -125,4 +136,17 @@ private void handleConnectedClient(ServerSocket serverSocket) throws IOException
125136 }
126137 }
127138
139+ @ Test
140+ public void testJavaBeansEventHandler () {
141+ var out = TestUtils .setTempSystemOut ();
142+ Runnable runnable = EventHandler .create (Runnable .class , this , "run" ); // () -> run();
143+ runnable .run ();
144+ Assertions .assertEquals ("Run was called!" , out .all ());
145+ TestUtils .resetSystemOut ();
146+ }
147+
148+ public void run () {
149+ System .out .print ("Run was called!" );
150+ }
151+
128152}
0 commit comments