/src/test/java/com/googlecode/charts4j/GChartsTest.java

http://charts4j.googlecode.com/ · Java · 88 lines · 68 code · 20 blank · 0 comment · 0 complexity · 3354a7b68ce4221e9247ddaf911a078d MD5 · raw file

  1. package com.googlecode.charts4j;
  2. import static com.googlecode.charts4j.UrlUtil.normalize;
  3. import static org.junit.Assert.assertEquals;
  4. import java.util.logging.Level;
  5. import java.util.logging.Logger;
  6. import org.junit.After;
  7. import org.junit.AfterClass;
  8. import org.junit.Before;
  9. import org.junit.BeforeClass;
  10. import org.junit.Test;
  11. public class GChartsTest {
  12. @BeforeClass
  13. public static void setUpBeforeClass() throws Exception {
  14. Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).setLevel(Level.ALL);
  15. }
  16. @AfterClass
  17. public static void tearDownAfterClass() throws Exception {
  18. }
  19. @Before
  20. public void setUp() throws Exception {
  21. }
  22. @After
  23. public void tearDown() throws Exception {
  24. }
  25. @Test
  26. public void testNewLineChart0() {
  27. try {
  28. Line[] lines = null;
  29. GCharts.newLineChart(lines);
  30. } catch (NullPointerException e) {
  31. return;
  32. }
  33. }
  34. @Test
  35. public void testNewLineChart1() {
  36. try {
  37. Line[] lines = { TestUtil.getBasicLine(), null };
  38. GCharts.newLineChart(lines);
  39. } catch (NullPointerException e) {
  40. return;
  41. }
  42. }
  43. @Test
  44. public void testPloymorphicPlots() {
  45. Plot curve = Plots.newPlot(Data.newData(10, 99, 30));
  46. Line line = Plots.newLine(Data.newData(70, 5, 50), Color.RED, "foo");
  47. LineChart lc = GCharts.newLineChart(curve, line);
  48. Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(lc.toURLString());
  49. String expectedString = "http://chart.apis.google.com/chart?chs=200x125&chd=e:Ga.WTN,szDNgA&chdl=+|foo&chco=000000,FF0000&cht=lc";
  50. assertEquals("Junit error", normalize(expectedString), normalize(lc.toURLString()));
  51. RadarChart rc = GCharts.newRadarChart(curve, line);
  52. Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(rc.toURLString());
  53. expectedString = "http://chart.apis.google.com/chart?chs=200x125&chd=e:Ga.WTN,szDNgA&chdl=+|foo&chco=000000,FF0000&cht=r";
  54. assertEquals("Junit error", normalize(expectedString), normalize(rc.toURLString()));
  55. BarChart bc = GCharts.newBarChart(curve, line);
  56. Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(bc.toURLString());
  57. expectedString = "http://chart.apis.google.com/chart?chs=200x125&chd=e:Ga.WTN,szDNgA&chdl=+|foo&chco=000000,FF0000&chbh=23,4,8&cht=bvg";
  58. assertEquals("Junit error", normalize(expectedString), normalize(bc.toURLString()));
  59. XYLineChart xyc = GCharts.newXYLineChart(curve, line);
  60. Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(xyc.toURLString());
  61. expectedString = "http://chart.apis.google.com/chart?chs=200x125&chd=e:AAgA..,Ga.WTN,AAgA..,szDNgA&chdl=+|foo&chco=000000,FF0000&cht=lxy";
  62. assertEquals("Junit error", normalize(expectedString), normalize(xyc.toURLString()));
  63. ScatterPlot sp = GCharts.newScatterPlot(line);
  64. Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).info(sp.toURLString());
  65. expectedString = "http://chart.apis.google.com/chart?chs=200x125&chd=e:AAgA..,szDNgA&chco=FF0000&chdl=foo&chm=o,FF0000,0,0,10,0&cht=s";
  66. assertEquals("Junit error", normalize(expectedString), normalize(sp.toURLString()));
  67. }
  68. }