diff --git a/vaadin-charts-flow-parent/vaadin-charts-flow/src/main/java/com/vaadin/flow/component/charts/model/Configuration.java b/vaadin-charts-flow-parent/vaadin-charts-flow/src/main/java/com/vaadin/flow/component/charts/model/Configuration.java index 79cb1830963..ccd95a5a9fe 100644 --- a/vaadin-charts-flow-parent/vaadin-charts-flow/src/main/java/com/vaadin/flow/component/charts/model/Configuration.java +++ b/vaadin-charts-flow-parent/vaadin-charts-flow/src/main/java/com/vaadin/flow/component/charts/model/Configuration.java @@ -147,7 +147,7 @@ public void addSeries(Series series) { * @param series */ public void setSeries(List series) { - this.series = series; + this.series = new ArrayList<>(series); for (Series s : series) { s.setConfiguration(this); addSeriesToDrilldownConfiguration(s); diff --git a/vaadin-charts-flow-parent/vaadin-charts-flow/src/test/java/com/vaadin/flow/component/charts/ConfigurationTest.java b/vaadin-charts-flow-parent/vaadin-charts-flow/src/test/java/com/vaadin/flow/component/charts/ConfigurationTest.java new file mode 100644 index 00000000000..8f27473b4ab --- /dev/null +++ b/vaadin-charts-flow-parent/vaadin-charts-flow/src/test/java/com/vaadin/flow/component/charts/ConfigurationTest.java @@ -0,0 +1,50 @@ +package com.vaadin.flow.component.charts; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.junit.Test; + +import com.vaadin.flow.component.charts.model.Configuration; +import com.vaadin.flow.component.charts.model.ListSeries; +import com.vaadin.flow.component.charts.model.Series; + +/** + * Tests for the {@link Configuration} + * + */ +public class ConfigurationTest { + + @Test(expected = Test.None.class) + public void configurationSetSeriesWithArraysAsListTest() { + Configuration conf = new Configuration(); + + conf.setSeries(Arrays.asList(new ListSeries())); + conf.addSeries(new ListSeries()); + + assertEquals(conf.getSeries().size(), 2); + } + + @Test + public void configurationSetSeriesWithListShouldMakeShallowCopyTest() { + Configuration conf = new Configuration(); + + List series = new ArrayList<>(); + conf.setSeries(series); + + series.add(new ListSeries()); + + assertEquals(conf.getSeries().size(), 0); + } + + @Test + public void configuration_setSeriesAddSeries_noExceptions() { + Configuration conf = new Configuration(); + conf.setSeries(new ListSeries(), new ListSeries()); + conf.addSeries(new ListSeries()); + assertEquals(3, conf.getSeries().size()); + } +}