From 3aeb74eed74bec2e6e4678d060142201e8a92cd2 Mon Sep 17 00:00:00 2001 From: huybrechts Date: Wed, 5 Aug 2009 14:37:04 +0000 Subject: [PATCH] don't write test file to current directory git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@20465 71c3de6d-444a-0410-be80-ed276b4c234a --- .../java/hudson/model/LoadStatisticsTest.java | 63 +++++++++++-------- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/core/src/test/java/hudson/model/LoadStatisticsTest.java b/core/src/test/java/hudson/model/LoadStatisticsTest.java index 2539b64ddd..ba9f1e0757 100644 --- a/core/src/test/java/hudson/model/LoadStatisticsTest.java +++ b/core/src/test/java/hudson/model/LoadStatisticsTest.java @@ -25,10 +25,13 @@ package hudson.model; import hudson.model.MultiStageTimeSeries.TimeScale; import junit.framework.TestCase; + +import org.apache.commons.io.IOUtils; import org.jfree.chart.JFreeChart; import javax.imageio.ImageIO; import java.awt.image.BufferedImage; +import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -36,35 +39,43 @@ import java.io.IOException; * @author Kohsuke Kawaguchi */ public class LoadStatisticsTest extends TestCase { - public void testGraph() throws IOException { - LoadStatistics ls = new LoadStatistics(0, 0) { - public int computeIdleExecutors() { - throw new UnsupportedOperationException(); - } + public void testGraph() throws IOException { + LoadStatistics ls = new LoadStatistics(0, 0) { + public int computeIdleExecutors() { + throw new UnsupportedOperationException(); + } - public int computeTotalExecutors() { - throw new UnsupportedOperationException(); - } + public int computeTotalExecutors() { + throw new UnsupportedOperationException(); + } - public int computeQueueLength() { - throw new UnsupportedOperationException(); - } - }; + public int computeQueueLength() { + throw new UnsupportedOperationException(); + } + }; - for(int i=0;i<50;i++) { - ls.totalExecutors.update(4); - ls.busyExecutors.update(3); - ls.queueLength.update(3); - } + for (int i = 0; i < 50; i++) { + ls.totalExecutors.update(4); + ls.busyExecutors.update(3); + ls.queueLength.update(3); + } - for(int i=0;i<50;i++) { - ls.totalExecutors.update(0); - ls.busyExecutors.update(0); - ls.queueLength.update(1); - } + for (int i = 0; i < 50; i++) { + ls.totalExecutors.update(0); + ls.busyExecutors.update(0); + ls.queueLength.update(1); + } - JFreeChart chart = ls.createTrendChart(TimeScale.SEC10).createChart(); - BufferedImage image = chart.createBufferedImage(400,200); - ImageIO.write(image, "PNG", new FileOutputStream("chart.png")); - } + JFreeChart chart = ls.createTrendChart(TimeScale.SEC10).createChart(); + BufferedImage image = chart.createBufferedImage(400, 200); + + File tempFile = File.createTempFile("chart-", "png"); + FileOutputStream os = new FileOutputStream(tempFile); + try { + ImageIO.write(image, "PNG", os); + } finally { + IOUtils.closeQuietly(os); + tempFile.delete(); + } + } }