KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > thoughtworks > xstream > core > JVMTest


1 package com.thoughtworks.xstream.core;
2
3 import junit.framework.TestCase;
4
5 public class JVMTest extends TestCase {
6
7     public void testDoesNotInsantiateStaticBlocksWhenLoadingClasses() {
8         try {
9             new JVM().loadClass("com.thoughtworks.xstream.core.EvilClass");
10         } catch (ExceptionInInitializerError JavaDoc error) {
11             fail("Static block was called");
12         }
13     }
14
15     public void testGetMajorJavaVersion() {
16         assertEquals("1.5.0_01", 1.5f, JVM.getMajorJavaVersion("1.5.0_01"), 0.001f);
17         assertEquals("1.4.2_05", 1.4f, JVM.getMajorJavaVersion("1.4.2_05"), 0.001f);
18         assertEquals("1.3.1_08", 1.3f, JVM.getMajorJavaVersion("1.3.1_08"), 0.001f);
19         assertEquals("PERC(R)", JVM.DEFAULT_JAVA_VERSION, JVM.getMajorJavaVersion("PERC(R) VM 4.1.0519 Platform: [Linux]"), 0.001f);
20     }
21 }
22
23 class EvilClass {
24
25     static {
26         evil();
27     }
28
29     static void evil() {
30         throw new RuntimeException JavaDoc("Evil");
31     }
32 }
33
Popular Tags