@@ -0,0 +1,2159 @@
+package no.ssb.vtl.script.operations;%0A%0Aimport com.google.common.collect.ImmutableList;%0Aimport no.ssb.vtl.model.*;%0Aimport no.ssb.vtl.script.support.DatasetCloseWatcher;%0Aimport org.junit.Before;%0Aimport org.junit.Test;%0A%0Aimport java.util.stream.Stream;%0A%0Aimport static no.ssb.vtl.model.Component.*;%0Aimport static org.assertj.core.api.Assertions.assertThat;%0A%0Apublic class AggregationOperationTest %7B%0A%0A    private DatasetCloseWatcher dataset;%0A%0A    @Before%0A    public void setUp() throws Exception %7B%0A%0A        StaticDataset staticDataset = StaticDataset.create()%0A                .addComponent(%22id1%22, Role.IDENTIFIER, String.class)%0A                .addComponent(%22id2%22, Role.IDENTIFIER, String.class)%0A                .addComponent(%22m1%22, Role.IDENTIFIER, Long.class)%0A%0A                .addPoints(%22a%22, %221%22, 1L)%0A                .addPoints(%22a%22, %222%22, 2L)%0A                .addPoints(%22a%22, %223%22, 4L)%0A                .addPoints(%22a%22, %224%22, 8L)%0A%0A                .addPoints(%22b%22, %221%22, 1L)%0A                .addPoints(%22b%22, %222%22, 2L)%0A                .addPoints(%22b%22, %223%22, 4L)%0A                .addPoints(%22b%22, %224%22, 8L)%0A%0A                .addPoints(%22c%22, %221%22, 1L)%0A                .addPoints(%22c%22, %222%22, 2L)%0A                .addPoints(%22c%22, %223%22, 4L)%0A                .addPoints(%22c%22, %224%22, 8L)%0A%0A                .build();%0A%0A        this.dataset = DatasetCloseWatcher.wrap(staticDataset);%0A    %7D%0A%0A    @Test%0A    public void testClosesStreams() %7B%0A%0A%0A        DataStructure structure = this.dataset.getDataStructure();%0A        AggregationOperation aggregationOperation = new AggregationOperation(%0A                this.dataset,%0A                ImmutableList.of(structure.get(%22id1%22)),%0A                ImmutableList.of(structure.get(%22m1%22)),%0A                vtlNumbers -%3E vtlNumbers.stream().reduce(VTLNumber.of(0L), VTLNumber::add)%0A        );%0A%0A        try (Stream%3CDataPoint%3E data = aggregationOperation.getData()) %7B%0A            assertThat(data).containsExactly(%0A                    DataPoint.create(%22a%22,15),%0A                    DataPoint.create(%22b%22,15),%0A                    DataPoint.create(%22c%22,15)%0A            );%0A        %7D finally %7B%0A            assertThat(dataset.allStreamWereClosed()).isTrue();%0A        %7D%0A%0A    %7D%0A%7D

Check that aggregation closes the stream it uses