1 /*
   2  * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package test.javafx.scene.chart;
  27 
  28 import test.com.sun.javafx.scene.control.infrastructure.ControlTestUtils;
  29 import java.lang.reflect.InvocationTargetException;
  30 import java.lang.reflect.Method;
  31 import java.util.Arrays;
  32 import java.util.Collection;
  33 import javafx.scene.chart.AreaChart;
  34 import javafx.scene.chart.Axis;
  35 import javafx.scene.chart.Chart;
  36 import javafx.scene.chart.LineChart;
  37 import javafx.scene.chart.NumberAxis;
  38 import javafx.scene.chart.StackedAreaChart;
  39 import javafx.scene.chart.XYChart;
  40 import javafx.scene.chart.XYChartShim;
  41 import static org.junit.Assert.assertEquals;
  42 import org.junit.Test;
  43 import org.junit.runner.RunWith;
  44 import org.junit.runners.Parameterized;
  45 
  46 @RunWith(Parameterized.class)
  47 public class XYNumberLineChartsTest extends XYNumberChartsTestBase {
  48     private Class chartClass;
  49     private int seriesFadeOutTime;
  50 
  51     @Parameterized.Parameters
  52     public static Collection implementations() {
  53         return Arrays.asList(new Object[][] {
  54             { AreaChart.class, 400 },
  55             { LineChart.class, 900 },
  56             { StackedAreaChart.class, 400 }
  57         });
  58     }
  59 
  60     public XYNumberLineChartsTest(Class chartClass, int seriesFadeOutTime) {
  61         this.chartClass = chartClass;
  62         this.seriesFadeOutTime = seriesFadeOutTime;
  63     }
  64 
  65     @Override
  66     protected Chart createChart() {
  67         try {
  68             chart = (XYChart<Number, Number>) chartClass.getConstructor(Axis.class, Axis.class).
  69                 newInstance(new NumberAxis(), new NumberAxis());
  70             Method setCreateSymbolsMethod = chartClass.getMethod("setCreateSymbols", Boolean.TYPE);
  71             setCreateSymbolsMethod.invoke(chart, false);
  72         } catch (InvocationTargetException e) {
  73             throw new AssertionError(e.getCause());
  74         } catch (Exception e) {
  75             throw new AssertionError(e);
  76         }
  77         return chart;
  78     }
  79 
  80     @Test
  81     public void testSeriesClearAnimatedWithoutSymbols_rt_40632() {
  82         checkSeriesClearAnimated_rt_40632();
  83     }
  84 
  85     @Test
  86     public void testSeriesRemoveWithoutSymbols() {
  87         // 1 area group
  88         checkSeriesRemove(1);
  89     }
  90 
  91     @Test
  92     public void testSeriesRemoveWithoutSymbolsAnimated_rt_22124() {
  93         startAppWithSeries();
  94         // 1 area group
  95         assertEquals(1, XYChartShim.getPlotChildren(chart).size());
  96 
  97         chart.setAnimated(true);
  98         ControlTestUtils.runWithExceptionHandler(() -> {
  99             // tests RT-22124
 100             chart.getData().remove(0);
 101         });
 102         toolkit.setAnimationTime(seriesFadeOutTime/2);
 103         assertEquals(1, XYChartShim.getPlotChildren(chart).size());
 104         // tests RT-46086
 105         assertEquals(0.5, XYChartShim.getPlotChildren(chart).get(0).getOpacity(), 0.0);
 106         toolkit.setAnimationTime(seriesFadeOutTime);
 107         assertEquals(0, XYChartShim.getPlotChildren(chart).size());
 108     }
 109 
 110     @Test
 111     public void testDataWithoutSymbolsAddWithAnimation_rt_39353() {
 112         startAppWithSeries();
 113         chart.setAnimated(true);
 114         series.getData().add(new XYChart.Data<>(30, 30));
 115         ControlTestUtils.runWithExceptionHandler(() -> {
 116             toolkit.setAnimationTime(0);
 117         });
 118     }
 119 
 120     @Override
 121     void checkSeriesStyleClasses(XYChart.Series<?, ?> series, int seriesIndex, int colorIndex) {
 122         throw new UnsupportedOperationException("Not supported yet.");
 123     }
 124 
 125     @Override
 126     void checkDataStyleClasses(XYChart.Data<?, ?> data, int seriesIndex, int dataIndex, int colorIndex) {
 127         throw new UnsupportedOperationException("Not supported yet.");
 128     }
 129 }