Skip to content

Commit

Permalink
fix: change how setSeries converts array to ArrayList (#927) (#950) (#…
Browse files Browse the repository at this point in the history
…952)

Because setSeries(...series) uses Arrays.asList to convert from array to List, one cannot call addSeries after calling setSeries(...series) since it throws a UnsupportedOperationException.

Fix vaadin/vaadin-charts#515

Co-authored-by: Knoobie <[email protected]>
  • Loading branch information
DiegoCardoso and knoobie authored May 7, 2021
1 parent 68841c9 commit 7a7b53e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public void addSeries(Series series) {
* @param series
*/
public void setSeries(List<Series> series) {
this.series = series;
this.series = new ArrayList<>(series);
for (Series s : series) {
s.setConfiguration(this);
addSeriesToDrilldownConfiguration(s);
Expand Down
Original file line number Diff line number Diff line change
@@ -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> 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());
}
}

0 comments on commit 7a7b53e

Please sign in to comment.