1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package th.co.edge.jseq.scenarios;
24
25 import junit.framework.Test;
26 import junit.framework.TestCase;
27 import junit.framework.TestSuite;
28
29 public class HelloWorldScenario extends TestCase {
30 public HelloWorldScenario(String name) {
31 super(name);
32 }
33
34 public static Test suite() {
35 TestSuite suite = new TestSuite(HelloWorldScenario.class);
36 return suite;
37 }
38
39 public static void main(String[] args) {
40 HelloWorldScenario scenario = new HelloWorldScenario("HelloWorld");
41 scenario.test();
42 }
43
44 public void test() {
45 HelloWorld helloWorld = new HelloWorld();
46 helloWorld.hello();
47 }
48 }
49
50 class HelloWorld {
51 Foo foo;
52
53 public HelloWorld() {
54 this.foo = new Foo(this, 2);
55 }
56
57 public void hello() {
58 print("Hello, World!");
59 Thread thread1 = new Thread(new ThreadOne());
60 thread1.start();
61 Thread thread2 = new Thread(new ThreadTwo());
62 thread2.start();
63 try {
64 thread1.join();
65 thread2.join();
66 } catch (InterruptedException e) {
67 }
68 ExceptionTest exceptionTest = new ExceptionTest();
69 exceptionTest.test();
70 }
71
72 public void print(String s) {
73 try {
74 int x = 1 + 2;
75 for (int i = 0; i < 3; i++) {
76 foo.foo();
77 }
78 System.out.println(s + x);
79 } catch (Exception e) {
80 System.out.println(e);
81 }
82 bar();
83 }
84
85 public void bar() {
86 System.out.println("So, there");
87 }
88
89 private static class ThreadOne implements Runnable {
90 public void run() {
91 for (int i = 0; i < 10; i++) {
92 t1();
93 }
94 }
95
96 private void t1() {
97 System.out.println("t1");
98 Thread.yield();
99 }
100 }
101
102 private static class ThreadTwo implements Runnable {
103 public void run() {
104 for (int i = 0; i < 10; i++) {
105 t2();
106 }
107 }
108
109 private void t2() {
110 System.out.println("t2");
111 Thread.yield();
112 }
113 }
114
115 private static class ExceptionTest {
116 public void test() {
117 ExceptionTest2 exceptionTest2 = new ExceptionTest2();
118 try {
119 exceptionTest2.test();
120 } catch (Exception e) {
121 }
122 print();
123 }
124
125 public void print() {
126 System.out.println("Exception test ready");
127 }
128 }
129
130 private static class ExceptionTest2 {
131 public void test() {
132 ExceptionTest3 exceptionTest3 = new ExceptionTest3();
133 exceptionTest3.test();
134 }
135 }
136
137 private static class ExceptionTest3 {
138 public void test() {
139 throw new RuntimeException("foo");
140 }
141 }
142 }