diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-10-02 23:09:52 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-10-02 23:09:52 +0200 |
commit | ee925d0a8d31556a37f98b6738e6f767b489e288 (patch) | |
tree | 28b2f547b2e8c55fcc469b051e0498979f39dcaa /plugins/sonar-core-plugin | |
parent | 1b8bc4096ef135efe3bd303d4029536e825d37c8 (diff) | |
download | sonarqube-ee925d0a8d31556a37f98b6738e6f767b489e288.tar.gz sonarqube-ee925d0a8d31556a37f98b6738e6f767b489e288.zip |
Code clean-up
* mark JFreechart as deprecated
* complete some javadoc
Diffstat (limited to 'plugins/sonar-core-plugin')
4 files changed, 99 insertions, 3 deletions
diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/charts/AbstractChartTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/charts/AbstractChartTest.java new file mode 100644 index 00000000000..31223db492f --- /dev/null +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/charts/AbstractChartTest.java @@ -0,0 +1,99 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.plugins.core.charts; + +import org.apache.commons.io.FileUtils; +import org.jfree.chart.ChartUtilities; +import org.jfree.ui.ApplicationFrame; +import org.jfree.ui.RefineryUtilities; + +import javax.swing.JPanel; + +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.image.BufferedImage; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; + +import static org.junit.Assert.assertTrue; + +public abstract class AbstractChartTest { + protected void assertChartSizeGreaterThan(BufferedImage img, int size) throws IOException { + ByteArrayOutputStream output = new ByteArrayOutputStream(); + ChartUtilities.writeBufferedImageAsPNG(output, img); + assertTrue("PNG size in bits=" + output.size(), output.size() > size); + } + + protected void assertChartSizeLesserThan(BufferedImage img, int size) throws IOException { + ByteArrayOutputStream output = new ByteArrayOutputStream(); + ChartUtilities.writeBufferedImageAsPNG(output, img); + assertTrue("PNG size in bits=" + output.size(), output.size() < size); + } + + protected void saveChart(BufferedImage img, String name) throws IOException { + File target = new File("target/tmp-chart", name); + FileUtils.forceMkdir(target.getParentFile()); + ByteArrayOutputStream imgOutput = new ByteArrayOutputStream(); + ChartUtilities.writeBufferedImageAsPNG(imgOutput, img); + OutputStream out = new FileOutputStream(target); + out.write(imgOutput.toByteArray()); + out.close(); + + } + + protected static void displayTestPanel(BufferedImage image) { + ApplicationFrame frame = new ApplicationFrame("testframe"); + BufferedPanel imgPanel = new BufferedPanel(image); + frame.setContentPane(imgPanel); + frame.pack(); + RefineryUtilities.centerFrameOnScreen(frame); + frame.setVisible(true); + } + + protected static Date stringToDate(String sDate) throws ParseException { + SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yy hh'h'mm"); + return sdf.parse(sDate); + } + + private static class BufferedPanel extends JPanel { + private final BufferedImage chartImage; + + public BufferedPanel(BufferedImage chartImage) { + this.chartImage = chartImage; + } + + @Override + protected void paintComponent(Graphics graphics) { + super.paintComponent(graphics); + graphics.drawImage(chartImage, 0, 0, null); + } + + @Override + public Dimension getPreferredSize() { + return new Dimension(chartImage.getWidth(), chartImage.getHeight()); + } + } +} diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/charts/DistributionAreaChartTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/charts/DistributionAreaChartTest.java index 6ae7fed839a..6a535abad16 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/charts/DistributionAreaChartTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/charts/DistributionAreaChartTest.java @@ -20,7 +20,6 @@ package org.sonar.plugins.core.charts; import org.junit.Test; -import org.sonar.api.charts.AbstractChartTest; import org.sonar.api.charts.ChartParameters; import java.awt.image.BufferedImage; diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/charts/DistributionBarChartTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/charts/DistributionBarChartTest.java index 4cf1e46dece..a0937082942 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/charts/DistributionBarChartTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/charts/DistributionBarChartTest.java @@ -20,7 +20,6 @@ package org.sonar.plugins.core.charts; import org.junit.Test; -import org.sonar.api.charts.AbstractChartTest; import org.sonar.api.charts.ChartParameters; import java.awt.image.BufferedImage; diff --git a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/charts/XradarChartTest.java b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/charts/XradarChartTest.java index 39a304c2e67..d48d049c440 100644 --- a/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/charts/XradarChartTest.java +++ b/plugins/sonar-core-plugin/src/test/java/org/sonar/plugins/core/charts/XradarChartTest.java @@ -20,7 +20,6 @@ package org.sonar.plugins.core.charts; import org.junit.Test; -import org.sonar.api.charts.AbstractChartTest; import org.sonar.api.charts.ChartParameters; import java.awt.image.BufferedImage; |