1 42 43 package org.jfree.chart.urls.junit; 44 45 import java.io.ByteArrayInputStream ; 46 import java.io.ByteArrayOutputStream ; 47 import java.io.ObjectInput ; 48 import java.io.ObjectInputStream ; 49 import java.io.ObjectOutput ; 50 import java.io.ObjectOutputStream ; 51 52 import junit.framework.Test; 53 import junit.framework.TestCase; 54 import junit.framework.TestSuite; 55 56 import org.jfree.chart.urls.StandardPieURLGenerator; 57 import org.jfree.data.general.DefaultPieDataset; 58 59 62 public class StandardPieURLGeneratorTests extends TestCase { 63 64 69 public static Test suite() { 70 return new TestSuite(StandardPieURLGeneratorTests.class); 71 } 72 73 78 public StandardPieURLGeneratorTests(String name) { 79 super(name); 80 } 81 82 85 public void testSerialization() { 86 87 StandardPieURLGenerator g1 = new StandardPieURLGenerator( 88 "index.html?", "cat" 89 ); 90 StandardPieURLGenerator g2 = null; 91 92 try { 93 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 94 ObjectOutput out = new ObjectOutputStream (buffer); 95 out.writeObject(g1); 96 out.close(); 97 98 ObjectInput in = new ObjectInputStream ( 99 new ByteArrayInputStream (buffer.toByteArray()) 100 ); 101 g2 = (StandardPieURLGenerator) in.readObject(); 102 in.close(); 103 } 104 catch (Exception e) { 105 System.out.println(e.toString()); 106 } 107 assertEquals(g1, g2); 108 109 } 110 111 114 public void testURL() { 115 DefaultPieDataset dataset = new DefaultPieDataset(); 116 dataset.setValue("Alpha", new Double (5.0)); 117 dataset.setValue("Beta", new Double (5.5)); 118 StandardPieURLGenerator g1 = new StandardPieURLGenerator( 119 "chart.jsp", "category" 120 ); 121 String url = g1.generateURL(dataset, "Beta", 0); 122 assertEquals("chart.jsp?category=Beta&pieIndex=0", url); 123 } 124 125 } 126 | Popular Tags |