File tree Expand file tree Collapse file tree
core-java/src/test/java/org/baeldung/java Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1414import com .google .common .base .Charsets ;
1515import com .google .common .io .Files ;
1616
17- public class CoreJavaIoIntegrationTest {
17+ public class JavaIoIntegrationTest {
1818 protected final Logger logger = LoggerFactory .getLogger (getClass ());
1919
2020 // tests - iterate lines in a file
Original file line number Diff line number Diff line change 77import org .apache .commons .math3 .random .RandomDataGenerator ;
88import org .junit .Test ;
99
10- public class CoreJavaRandomUnitTest {
10+ public class JavaRandomUnitTest {
1111
1212 // tests - random long
1313
Original file line number Diff line number Diff line change 1+ package org .baeldung .java ;
2+
3+ import java .util .Date ;
4+ import java .util .Timer ;
5+ import java .util .TimerTask ;
6+
7+ import org .junit .Test ;
8+
9+ public class JavaTimerUnitTest {
10+
11+ // tests
12+
13+ @ Test
14+ public void givenUsingTimer_whenSchedulingTaskOnce_thenCorrect () throws InterruptedException {
15+ final TimerTask timerTask = new TimerTask () {
16+ @ Override
17+ public void run () {
18+ System .out .println ("Task performed on " + new Date () + "\n " + "Thread's name: " + Thread .currentThread ().getName ());
19+ }
20+ };
21+
22+ final Timer timer = new Timer ("Timer" );
23+ final long delay = 1000L ;
24+ timer .schedule (timerTask , delay );
25+
26+ Thread .sleep (delay * 2 );
27+ timer .cancel ();
28+ }
29+
30+ }
You can’t perform that action at this time.
0 commit comments