KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > wcf > utils > JDK13UtilsTest


1 package com.tonbeller.wcf.utils;
2
3 import java.io.UnsupportedEncodingException JavaDoc;
4
5 import junit.framework.TestCase;
6
7 public class JDK13UtilsTest extends TestCase {
8   public void testEncode() throws UnsupportedEncodingException JavaDoc {
9     boolean is13 = System.getProperty("java.vm.version").startsWith("1.3");
10     
11     String JavaDoc s1 = JDK13Utils.urlEncode("ß", "ISO-8859-1");
12     String JavaDoc s2 = JDK13Utils.urlEncode("ß", "UTF-8");
13     if (is13)
14       assertEquals(s1, s2);
15     else
16       assertNotSame(s1, s2);
17   }
18   
19
20   class Ex extends RuntimeException JavaDoc {
21     Ex() {
22       cause = this;
23     }
24     Ex(String JavaDoc message) {
25       super(message);
26       cause = this;
27     }
28     Ex(String JavaDoc message, Throwable JavaDoc cause) {
29       super(message);
30       this.cause = cause;
31     }
32     Throwable JavaDoc cause;
33     public Throwable JavaDoc getCause() {
34       return cause;
35     }
36   }
37   public void testCause1() {
38     Exception JavaDoc c = new Ex("cause");
39     Exception JavaDoc w = new Ex("wrapper", c);
40     assertEquals(c, JDK13Utils.getCause(w));
41   }
42
43   public void testCause2() {
44     assertNull(JDK13Utils.getCause(new Ex()));
45   }
46   
47 }
48
Popular Tags