[Schmitzm-commits] r1095 - in trunk/src_junit/schmitzm: jfree/feature/style swing

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Sun Oct 10 22:05:48 CEST 2010


Author: alfonx
Date: 2010-10-10 22:05:47 +0200 (Sun, 10 Oct 2010)
New Revision: 1095

Modified:
   trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java
   trunk/src_junit/schmitzm/swing/TestingUtil.java
Log:
TestingUtil.testGui(jfreechart, frameTitle) f?\195?\188r JFreeChart Testing hinzugef?\195?\188gt und daduch FeatureChartStyleTest vereinfacht.

Modified: trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java
===================================================================
--- trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java	2010-10-10 19:47:27 UTC (rev 1094)
+++ trunk/src_junit/schmitzm/jfree/feature/style/FeatureChartStyleTest.java	2010-10-10 20:05:47 UTC (rev 1095)
@@ -55,76 +55,59 @@
 	private static Logger log = Logger.getLogger(FeatureChartStyleTest.class);
 
 	FeatureChartStyleXMLFactory xmlFactoryFeature = new FeatureChartStyleXMLFactory();
-	ChartStyleXMLFactory xmlFactoryBasic = new ChartStyleXMLFactory();
+	ChartStyleXMLFactory<ChartStyle> xmlFactoryBasic = new ChartStyleXMLFactory<ChartStyle>();
 
-    @Test
-    public void testChartStyleCopyToWithScatterChartStyle() throws IOException, CQLException,
-            InterruptedException {
+	@Test
+	public void testChartStyleCopyToWithScatterChartStyle() throws Throwable {
 
-        FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil.getTestFeatures();
-        FeatureChartStyle style1 = new FeatureScatterChartStyle("1");
-        style1.setAttributeName(0, "jahr");
-        style1.setAttributeName(1, "w_bev");
-        JFreeChart chart = style1.applyToFeatureCollection(testFeatures);
-        assertNotNull("applyToFeatureCollection lieferte null!", chart);
-        assertXMLOutputAndInput(xmlFactoryFeature, style1, "testCopyTo_01");
-        
-        FeatureChartStyle style2 =  new FeatureScatterChartStyle(style1.getID());
-        style1.copyTo( style2 );
-        assertXMLOutputAndInput(xmlFactoryFeature, style2, "testCopyTo_02");
-        
-        assertXMLEqual(xmlFactoryFeature, style1, style2, "testCopyTo_Eq");
-        
-        if (INTERACTIVE) {
-          ChartFrame chartFrame = new ChartFrame(
-            "Sechs Linien (3x2), Zwei Achsen", chart);
-          chartFrame.pack();
-          chartFrame.setVisible(true);
-          while (chartFrame.isVisible()) {
-            Thread.sleep(100);
-          }
-        }
-    }
-    
-    @Test
-    public void testChartStyleCopyToWithBasicChartStyle() throws IOException, CQLException,
-            InterruptedException {
+		FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil
+				.getTestFeatures();
+		FeatureChartStyle style1 = new FeatureScatterChartStyle("1");
+		style1.setAttributeName(0, "jahr");
+		style1.setAttributeName(1, "w_bev");
+		JFreeChart chart = style1.applyToFeatureCollection(testFeatures);
+		assertNotNull("applyToFeatureCollection lieferte null!", chart);
+		assertXMLOutputAndInput(xmlFactoryFeature, style1, "testCopyTo_01");
 
-        FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil.getTestFeatures();
-        FeatureChartStyle style1 = new FeatureBasicChartStyle("1", ChartType.BAR);
-        style1.setAttributeName(0, "jahr");
-        style1.setAttributeName(1, "w_bev");
-        JFreeChart chart = style1.applyToFeatureCollection(testFeatures);
-        assertNotNull("applyToFeatureCollection lieferte null!", chart);
-        assertXMLOutputAndInput(xmlFactoryFeature, style1, "testCopyTo_01");
-        
-        
-        FeatureChartStyle style2 =  new FeatureBasicChartStyle(style1.getID(), ChartType.BAR);
-        style1.copyTo( style2 );
-        assertXMLOutputAndInput(xmlFactoryFeature, style2, "testCopyTo_02");
-        
-        assertXMLEqual(xmlFactoryFeature, style1, style2, "testCopyTo_Eq");
-        
-        
-        if (INTERACTIVE) {
-          ChartFrame chartFrame = new ChartFrame(
-            "Sechs Linien (3x2), Zwei Achsen", chart);
-          chartFrame.pack();
-          chartFrame.setVisible(true);
-          while (chartFrame.isVisible()) {
-            Thread.sleep(100);
-          }
-        }
-    }
+		FeatureChartStyle style2 = new FeatureScatterChartStyle(style1.getID());
+		style1.copyTo(style2);
+		assertXMLOutputAndInput(xmlFactoryFeature, style2, "testCopyTo_02");
 
-    @Ignore
+		assertXMLEqual(xmlFactoryFeature, style1, style2, "testCopyTo_Eq");
+
+		TestingUtil.testGui(chart, "Sechs Linien (3x2), Zwei Achsen");
+	}
+
 	@Test
-	public void testLineChartDualAxis() throws IOException, CQLException,
-			InterruptedException {
+	public void testChartStyleCopyToWithBasicChartStyle() throws Throwable {
 
 		FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil
 				.getTestFeatures();
+		FeatureChartStyle style1 = new FeatureBasicChartStyle("1",
+				ChartType.BAR);
+		style1.setAttributeName(0, "jahr");
+		style1.setAttributeName(1, "w_bev");
+		JFreeChart chart = style1.applyToFeatureCollection(testFeatures);
+		assertNotNull("applyToFeatureCollection lieferte null!", chart);
+		assertXMLOutputAndInput(xmlFactoryFeature, style1, "testCopyTo_01");
 
+		FeatureChartStyle style2 = new FeatureBasicChartStyle(style1.getID(),
+				ChartType.BAR);
+		style1.copyTo(style2);
+		assertXMLOutputAndInput(xmlFactoryFeature, style2, "testCopyTo_02");
+
+		assertXMLEqual(xmlFactoryFeature, style1, style2, "testCopyTo_Eq");
+
+		TestingUtil.testGui(chart, "Sechs Linien (3x2), Zwei Achsen");
+	}
+
+	@Ignore
+	@Test
+	public void testLineChartDualAxis() throws Throwable {
+
+		FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil
+				.getTestFeatures();
+
 		// Daten auf korrektheit überprüfen
 		String groupAttribName = "code"; // KreisZahl
 		SimpleFeatureType testDatenSchema = testFeatures.getSchema();
@@ -188,30 +171,18 @@
 		JFreeChart lineChart = lineChartStyle
 				.applyToFeatureCollection(testFeatures);
 		assertNotNull("applyToFeatureCollection lieferte null!", lineChart);
+		TestingUtil.testGui(lineChart, "Sechs Linien (3x2), Zwei Achsen");
 
-		if (INTERACTIVE) {
-			ChartFrame chartFrame = new ChartFrame(
-					"Sechs Linien (3x2), Zwei Achsen", lineChart);
-			chartFrame.pack();
-			chartFrame.setVisible(true);
-			while (chartFrame.isVisible()) {
-				Thread.sleep(100);
-			}
-		}
-		
-		assertXMLOutputAndInput(xmlFactoryFeature,lineChartStyle,"testDoubleLineChart");
+		assertXMLOutputAndInput(xmlFactoryFeature, lineChartStyle,
+				"testDoubleLineChart");
 
 	}
-	
-	
 
 	/**
 	 * If tests are run on a system with head, we may theoretically open dialgs,
 	 * frames etc.
 	 **/
 
-	boolean INTERACTIVE = !GraphicsEnvironment.isHeadless();
-
 	public CategoryDataset createSampleCategoryDataset1(boolean nullSecondary) {
 		// row keys...
 		String series1 = "Series 1";
@@ -272,8 +243,7 @@
 
 	@Test
 	@Ignore
-	public void testBarChartDualAxisWithSampleData() throws IOException,
-			InterruptedException {
+	public void testBarChartDualAxisWithSampleData() throws Throwable {
 		ChartAxisStyle domainAxisStyle = new ChartAxisStyle("jahreszahlen",
 				Color.red, 0., 0.);
 		ChartAxisStyle rangeAxisStyle = new ChartAxisStyle("deut. maenner",
@@ -313,15 +283,7 @@
 		JFreeChart barChart = barChartStyle.applyToDataset(data1, data2);
 		assertNotNull("applyToDataset lieferte null!", barChart);
 
-		if (INTERACTIVE) {
-			ChartFrame chartFrame = new ChartFrame(
-					"Sechs Linien (3x2), Zwei Achsen", barChart);
-			chartFrame.pack();
-			chartFrame.setVisible(true);
-			while (chartFrame.isVisible()) {
-				Thread.sleep(100);
-			}
-		}
+		TestingUtil.testGui(barChart, "bar chart");
 
 		File testFile = File.createTempFile("testDoubleLineChart", ".xml");
 		xmlFactoryBasic.writeStyleToFile(barChartStyle, "testDoubleLineChart",
@@ -349,9 +311,9 @@
 	}
 
 	@Test
-	public void testKECKbarChart() throws IOException, InterruptedException {
+	public void testKECKbarChart() throws Throwable {
 		String titleAttName = "jahr";
-		String xAxisAttName = "title"; //"code";
+		String xAxisAttName = "title"; // "code";
 		String yAxisAttName = "dm_u3";
 		String yAxisAttName2 = "w_bev";
 		String groupAttName = "jahr";
@@ -375,20 +337,21 @@
 		ChartAxisStyle xAxisStyle = new ChartAxisStyle();
 		xAxisStyle.setLabel("Regionen");
 		ChartAxisStyle yAxisStyle = new ChartAxisStyle();
-        yAxisStyle.setLabel("Deutsch, Männlich unter 3 Jahre");
-        yAxisStyle.setValuesFont( SwingUtil.DEFAULT_FONT.deriveFont(20f) );
-        yAxisStyle.setValuesPaint( Color.RED );
+		yAxisStyle.setLabel("Deutsch, Männlich unter 3 Jahre");
+		yAxisStyle.setValuesFont(SwingUtil.DEFAULT_FONT.deriveFont(20f));
+		yAxisStyle.setValuesPaint(Color.RED);
 		ChartAxisStyle yAxisStyle2 = new ChartAxisStyle();
-        yAxisStyle2.setLabel("Weiblich");
-        yAxisStyle2.setValuesFont( SwingUtil.DEFAULT_FONT.deriveFont(8f).deriveFont(Font.BOLD+Font.ITALIC) );
-        yAxisStyle2.setValuesPaint( Color.BLUE );
+		yAxisStyle2.setLabel("Weiblich");
+		yAxisStyle2.setValuesFont(SwingUtil.DEFAULT_FONT.deriveFont(8f)
+				.deriveFont(Font.BOLD + Font.ITALIC));
+		yAxisStyle2.setValuesPaint(Color.BLUE);
 
 		FeatureBasicChartStyle chartStyle = new FeatureBasicChartStyle(
 				"keckBarChart", ChartType.BAR);
 		chartStyle.setLegend(true);
 		// Domain Axis
 		chartStyle.setAttributeName(0, xAxisAttName);
-        chartStyle.setAxisStyle(0, xAxisStyle);
+		chartStyle.setAxisStyle(0, xAxisStyle);
 		// Range Axis
 		chartStyle.setAttributeName(1, yAxisAttName);
 		chartStyle.setSeriesAttributeName(groupAttName);
@@ -403,14 +366,17 @@
 		chartStyle.setForceCategories(true);
 
 		// Farben aus Palette zuweisen
-        ChartRendererStyle chartRendererStyle = new ChartRendererStyle();
-        chartRendererStyle.setSeriesLegendTooltip(0, new ChartLabelStyle("test"));
-        chartRendererStyle.setDefaultLegendTooltip(new ChartLabelStyle("TEST"));
-        ChartRendererStyle chartRendererStyle2 = new ChartRendererStyle();
-        chartRendererStyle2.setSeriesLegendTooltip(0, new ChartLabelStyle("test2"));
-        chartRendererStyle2.setDefaultLegendTooltip(new ChartLabelStyle("TEST2"));
-        chartStyle.setRendererStyle(0, chartRendererStyle);
-        chartStyle.setRendererStyle(1, chartRendererStyle2);
+		ChartRendererStyle chartRendererStyle = new ChartRendererStyle();
+		chartRendererStyle.setSeriesLegendTooltip(0,
+				new ChartLabelStyle("test"));
+		chartRendererStyle.setDefaultLegendTooltip(new ChartLabelStyle("TEST"));
+		ChartRendererStyle chartRendererStyle2 = new ChartRendererStyle();
+		chartRendererStyle2.setSeriesLegendTooltip(0, new ChartLabelStyle(
+				"test2"));
+		chartRendererStyle2
+				.setDefaultLegendTooltip(new ChartLabelStyle("TEST2"));
+		chartStyle.setRendererStyle(0, chartRendererStyle);
+		chartStyle.setRendererStyle(1, chartRendererStyle2);
 
 		// Hintergrund auf weiss stellen
 		ChartPlotStyle chartPlotStyle = new ChartPlotStyle();
@@ -420,29 +386,21 @@
 		chartStyle.setPlotStyle(chartPlotStyle);
 
 		JFreeChart barChart = chartStyle.applyToFeatureCollection(features);
-		
-		
-//		// Maximale Breite der Bars einstellen
-//		BarRenderer renderer = (BarRenderer) barChart.getCategoryPlot()
-//				.getRenderer();
-//		renderer.setMaximumBarWidth(0.1);
 
-		if (INTERACTIVE) {
-			ChartFrame chartFrame = new ChartFrame(
-					"KECK, 4 Vergelichregionen, 2 Variablen", barChart);
-			chartFrame.pack();
-			chartFrame.setVisible(true);
-			while (chartFrame.isVisible()) {
-				Thread.sleep(100);
-			}
-		}
-        assertXMLOutputAndInput(xmlFactoryFeature,chartStyle,"testKECKBarChart");
+		// // Maximale Breite der Bars einstellen
+		// BarRenderer renderer = (BarRenderer) barChart.getCategoryPlot()
+		// .getRenderer();
+		// renderer.setMaximumBarWidth(0.1);
+
+		TestingUtil.testGui(barChart, "bar chart");
+
+		assertXMLOutputAndInput(xmlFactoryFeature, chartStyle,
+				"testKECKBarChart");
 	}
 
 	@Test
-//	@Ignore
-	public void testBarChartDualAxis() throws IOException, CQLException,
-			InterruptedException {
+	// @Ignore
+	public void testBarChartDualAxis() throws Throwable {
 
 		FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil
 				.getTestFeatures();
@@ -513,15 +471,7 @@
 				.applyToFeatureCollection(testFeatures);
 		assertNotNull("applyToFeatureCollection lieferte null!", barChart);
 
-		if (INTERACTIVE) {
-			ChartFrame chartFrame = new ChartFrame(
-					"Sechs Linien (3x2), Zwei Achsen", barChart);
-			chartFrame.pack();
-			chartFrame.setVisible(true);
-			while (chartFrame.isVisible()) {
-				Thread.sleep(100);
-			}
-		}
+		TestingUtil.testGui(barChart, "bar chart");
 
 		File testFile = File.createTempFile("testDoubleLineChart", ".xml");
 		xmlFactoryFeature.writeStyleToFile(barChartStyle,
@@ -550,8 +500,7 @@
 
 	@Ignore
 	@Test
-	public void testBarChartSortedSeries() throws IOException,
-			InterruptedException {
+	public void testBarChartSortedSeries() throws Throwable {
 
 		FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil
 				.getTestFeatures();
@@ -602,16 +551,9 @@
 		assertNotNull("Es konnte kein PNG aus dem Chart erstellt werden!",
 				chartpng);
 
-		if (INTERACTIVE) {
-			ChartFrame chartFrame = new ChartFrame(
-					"Die Balken sollten ihren Jahreszahlen entsprechend sortiert sein",
-					chart);
-			chartFrame.pack();
-			chartFrame.setVisible(true);
-			while (chartFrame.isVisible()) {
-				Thread.sleep(100);
-			}
-		}
+		TestingUtil
+				.testGui(chart,
+						"Die Balken sollten ihren Jahreszahlen entsprechend sortiert sein");
 	}
 
 	@Ignore
@@ -662,8 +604,7 @@
 
 	@Ignore
 	@Test
-	public void testBarChartForcedCategories() throws IOException,
-			InterruptedException {
+	public void testBarChartForcedCategories() throws Throwable {
 
 		// Testdatenshape einlesen
 		FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil
@@ -724,25 +665,12 @@
 				.applyToFeatureCollection(testFeatures);
 		assertNotNull("applyToFeatureCollection liefte null!", lineChart);
 
-		BufferedImage chartpng = lineChart.createBufferedImage(600, 400);
-		assertNotNull("Es konnte kein PNG aus dem Chart erstellt werden!",
-				chartpng);
-
-		if (INTERACTIVE) {
-			ChartFrame chartFrame = new ChartFrame(
-					"Drei Balken sein, forcedCategory", lineChart);
-			chartFrame.pack();
-			chartFrame.setVisible(true);
-			while (chartFrame.isVisible()) {
-				Thread.sleep(100);
-			}
-		}
+		TestingUtil.testGui(lineChart, "Drei Balken sein, forcedCategory");
 	}
 
-//	@Ignore
+	// @Ignore
 	@Test
-	public void testLineChartAsCategories() throws IOException, CQLException,
-			InterruptedException {
+	public void testLineChartAsCategories() throws Throwable {
 
 		FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil
 				.getTestFeatures();
@@ -803,42 +731,24 @@
 				.applyToFeatureCollection(testFeatures);
 		assertNotNull("applyToFeatureCollection liefte null!", lineChart);
 
-		BufferedImage chartpng = lineChart.createBufferedImage(600, 400);
-		assertNotNull("Es konnte kein PNG aus dem Chart erstellt werden!",
-				chartpng);
+		TestingUtil.testGui(lineChart,
+				"drei linien, forcedCategories, mit series title kreisname");
 
-		if (INTERACTIVE) {
-			ChartFrame chartFrame = new ChartFrame(
-					"drei linien, forcedCategories, mit series title kreisname",
-					lineChart);
-			chartFrame.pack();
-			chartFrame.setVisible(true);
-			while (chartFrame.isVisible()) {
-				Thread.sleep(100);
-			}
-		}
-
 		// Jetzt nur soll noch eine Line kommen:
 		chartRendererStyle.setSeriesLegendLabel(0, null);
 		lineChartStyle.addSeriesAttributeNoDataValue("06532");
 		lineChartStyle.addSeriesAttributeNoDataValue("06531");
 		lineChart = lineChartStyle.applyToFeatureCollection(testFeatures);
 		assertNotNull("applyToFeatureCollection liefte null!", lineChart);
-		if (INTERACTIVE) {
-			ChartFrame chartFrame = new ChartFrame(
-					"test line chart: soll nur line 06533 existieren!",
-					lineChart);
-			chartFrame.pack();
-			chartFrame.setVisible(true);
-			while (chartFrame.isVisible()) {
-				Thread.sleep(100);
-			}
-		}
 
+		TestingUtil.testGui(lineChart,
+				"test line chart: soll nur line 06533 existieren!");
+
 		File testFile = File.createTempFile("testLineChart", ".xml");
+		
+		
 		xmlFactoryFeature.writeStyleToFile(lineChartStyle, "testLineChart",
 				testFile);
-
 		assertTrue(testFile.getAbsolutePath() + " wurde nicht geschrieben!",
 				testFile.exists());
 
@@ -866,10 +776,9 @@
 				writtenXML, IOUtil.readFileAsString(testFile2));
 	}
 
-//	@Ignore
+	// @Ignore
 	@Test
-	public void testLineChartNOTCategories() throws IOException, CQLException,
-			InterruptedException {
+	public void testLineChartNOTCategories() throws Throwable {
 
 		FeatureCollection<SimpleFeatureType, SimpleFeature> testFeatures = TestingUtil
 				.getTestFeatures();
@@ -956,16 +865,8 @@
 		lineChart.getXYPlot().setDomainAxis(numberAxis);
 		lineChartStyle.applyToChart(lineChart);
 
-		if (INTERACTIVE) {
-			ChartFrame chartFrame = new ChartFrame(
-					"drei linien, NOT categories, KreisNamen series titles",
-					lineChart);
-			chartFrame.pack();
-			chartFrame.setVisible(true);
-			while (chartFrame.isVisible()) {
-				Thread.sleep(100);
-			}
-		}
+		TestingUtil.testGui(lineChart,
+				"drei linien, NOT categories, KreisNamen series titles");
 
 		File testFile = File.createTempFile("testLineChart", ".xml");
 		xmlFactoryFeature.writeStyleToFile(lineChartStyle, "testLineChart",
@@ -989,56 +890,59 @@
 				writtenXML, IOUtil.readFileAsString(testFile2));
 	}
 
+	private <S extends ChartStyle> void assertXMLOutputAndInput(
+			ChartStyleXMLFactory<S> xmlFactory, S style, String fileName)
+			throws IOException {
+		File testFile = File.createTempFile(fileName, ".xml");
+		xmlFactory.writeStyleToFile(style, fileName, testFile);
 
-    private <S extends ChartStyle> void assertXMLOutputAndInput(ChartStyleXMLFactory<S> xmlFactory, S style, String fileName) throws IOException {
-      File testFile = File.createTempFile(fileName, ".xml");
-         xmlFactory.writeStyleToFile(style,
-                 fileName, testFile);
+		assertTrue(testFile.getAbsolutePath() + " wurde nicht geschrieben!",
+				testFile.exists());
 
-         assertTrue(testFile.getAbsolutePath() + " wurde nicht geschrieben!",
-                 testFile.exists());
+		String writtenXML = IOUtil.readFileAsString(testFile);
 
-         String writtenXML = IOUtil.readFileAsString(testFile);
+		// XML wieder einlesen
+		S chartAusXMLgelesen = xmlFactory.readStyleFromFile(testFile);
 
-         // XML wieder einlesen
-         S chartAusXMLgelesen = xmlFactory.readStyleFromFile(testFile);
+		// Nochmal in XML schreiben
+		File testFile2 = File.createTempFile(fileName, ".xml");
+		xmlFactory.writeStyleToFile(chartAusXMLgelesen, fileName, testFile2);
+		String readXML = IOUtil.readFileAsString(testFile2);
+		System.out.println("##### WRITTEN XML #####");
+		System.out.println(writtenXML);
+		System.out.println("##### READ XML #####");
+		System.out.println(readXML);
+		System.out.println("#######################");
 
-         // Nochmal in XML schreiben
-         File testFile2 = File.createTempFile(fileName, ".xml");
-         xmlFactory.writeStyleToFile(chartAusXMLgelesen,
-                 fileName, testFile2);
-         String readXML = IOUtil.readFileAsString(testFile2);
-         System.out.println("##### WRITTEN XML #####");
-         System.out.println(writtenXML);
-         System.out.println("##### READ XML #####");
-         System.out.println(readXML);
-         System.out.println("#######################");
+		assertEquals(
+				"Nachdem das Style geschrieben, gelesen und wieder geschrieben wurde ist das XML nicht gleich!",
+				writtenXML, readXML);
+	}
 
-         assertEquals(
-                 "Nachdem das Style geschrieben, gelesen und wieder geschrieben wurde ist das XML nicht gleich!",
-                 writtenXML, readXML);
-    }
+	private <S extends ChartStyle> void assertXMLEqual(
+			ChartStyleXMLFactory<S> xmlFactory, S style1, S style2,
+			String fileName) throws IOException {
+		File testFile1 = File.createTempFile(fileName, ".xml");
+		xmlFactory.writeStyleToFile(style1, fileName, testFile1);
+		assertTrue(testFile1.getAbsolutePath() + " wurde nicht geschrieben!",
+				testFile1.exists());
+		String writtenXML1 = IOUtil.readFileAsString(testFile1);
 
-    private <S extends ChartStyle> void assertXMLEqual(ChartStyleXMLFactory<S> xmlFactory, S style1, S style2, String fileName) throws IOException {
-         File testFile1 = File.createTempFile(fileName, ".xml");
-         xmlFactory.writeStyleToFile(style1, fileName, testFile1);
-         assertTrue(testFile1.getAbsolutePath() + " wurde nicht geschrieben!", testFile1.exists());
-         String writtenXML1 = IOUtil.readFileAsString(testFile1);
-         
-         File testFile2 = File.createTempFile(fileName, ".xml");
-         xmlFactory.writeStyleToFile(style1, fileName, testFile2);
-         assertTrue(testFile2.getAbsolutePath() + " wurde nicht geschrieben!", testFile2.exists());
-         String writtenXML2 = IOUtil.readFileAsString(testFile2);
-         
-         System.out.println("##### STYLE 1 #####");
-         System.out.println(writtenXML1);
-         System.out.println("##### STYLE 2 #####");
-         System.out.println(writtenXML2);
-         System.out.println("#######################");
+		File testFile2 = File.createTempFile(fileName, ".xml");
+		xmlFactory.writeStyleToFile(style1, fileName, testFile2);
+		assertTrue(testFile2.getAbsolutePath() + " wurde nicht geschrieben!",
+				testFile2.exists());
+		String writtenXML2 = IOUtil.readFileAsString(testFile2);
 
-         assertEquals(
-                 "Nachdem Style 1 und 2 geschrieben und als String wieder eingelesen wurden, ist das XML nicht gleich!",
-                 writtenXML1, writtenXML2);
-    }
+		System.out.println("##### STYLE 1 #####");
+		System.out.println(writtenXML1);
+		System.out.println("##### STYLE 2 #####");
+		System.out.println(writtenXML2);
+		System.out.println("#######################");
 
+		assertEquals(
+				"Nachdem Style 1 und 2 geschrieben und als String wieder eingelesen wurden, ist das XML nicht gleich!",
+				writtenXML1, writtenXML2);
+	}
+
 }

Modified: trunk/src_junit/schmitzm/swing/TestingUtil.java
===================================================================
--- trunk/src_junit/schmitzm/swing/TestingUtil.java	2010-10-10 19:47:27 UTC (rev 1094)
+++ trunk/src_junit/schmitzm/swing/TestingUtil.java	2010-10-10 20:05:47 UTC (rev 1095)
@@ -30,6 +30,8 @@
 import org.geotools.map.DefaultMapContext;
 import org.geotools.map.DefaultMapLayer;
 import org.geotools.renderer.lite.StreamingRenderer;
+import org.jfree.chart.ChartFrame;
+import org.jfree.chart.JFreeChart;
 import org.opengis.feature.simple.SimpleFeature;
 import org.opengis.feature.simple.SimpleFeatureType;
 
@@ -39,12 +41,14 @@
 import schmitzm.lang.LangUtil;
 
 /**
- * Helpers to test Swing applications
- * 
- * @author stefan tzeggai
+ * Helpers to test Swing applications.
  */
 public class TestingUtil {
 
+	/**
+	 * All these GUI-initiating testGui(...) methods are only executed if the
+	 * system is not running in headless mode.
+	 */
 	public static final boolean INTERACTIVE = !GraphicsEnvironment.isHeadless();
 
 	/**
@@ -244,7 +248,6 @@
 
 		return DataUtilities.fileToURL(new File(tempDir, fileName));
 	}
-	
 
 	final static String resLocation = "/schmitzm/jfree/feature/style/testLineChartShape/testKreiseLineChart.shp";
 
@@ -270,4 +273,21 @@
 
 		return testFeatures;
 	}
+
+	public static void testGui(JFreeChart chart, String frameTitle)
+			throws Throwable {
+		if (INTERACTIVE) {
+			ChartFrame chartFrame = new ChartFrame(frameTitle, chart);
+			chartFrame.pack();
+
+			testGui(chartFrame);
+
+			// chartFrame.pack();
+			// chartFrame.setVisible(true);
+
+			// while (chartFrame.isVisible()) {
+			// Thread.sleep(100);
+			// }
+		}
+	}
 }



More information about the Schmitzm-commits mailing list