KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > wcf > controller > ThreadLocalStackTest


1 package com.tonbeller.wcf.controller;
2
3 import junit.framework.TestCase;
4
5 public class ThreadLocalStackTest extends TestCase {
6   public void testTLSTack() {
7     ThreadLocalStack tls = new ThreadLocalStack();
8     assertEmpty(tls);
9     tls.push("1");
10     tls.push("2");
11     assertEquals("2", tls.peek(true));
12     assertEquals("2", tls.peek(false));
13     tls.pop();
14     assertEquals("1", tls.peek(true));
15     tls.pop();
16     assertEmpty(tls);
17   }
18
19   private void assertEmpty(ThreadLocalStack tls) {
20     assertNull(tls.peek(false));
21
22     try {
23       tls.peek(true);
24       fail("EmptyThreadLocalStackException expected");
25     } catch (EmptyThreadLocalStackException e) {
26       // OK
27
}
28
29     try {
30       tls.pop();
31       fail("EmptyThreadLocalStackException expected");
32     } catch (EmptyThreadLocalStackException e) {
33       // OK
34
}
35
36   }
37
38 }
39
Popular Tags