custom charts: Add unit tests for core classes
authorGeneviève Bastien <gbastien+lttng@versatic.net>
Thu, 5 Jan 2017 20:57:22 +0000 (15:57 -0500)
committerGenevieve Bastien <gbastien+lttng@versatic.net>
Tue, 31 Jan 2017 14:10:01 +0000 (09:10 -0500)
Change-Id: Ib5d4e40d031beb38f8bf4d543b3c1ca95a450eed
Signed-off-by: Geneviève Bastien <gbastien+lttng@versatic.net>
Reviewed-on: https://git.eclipse.org/r/88122
Reviewed-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
15 files changed:
tmf/org.eclipse.tracecompass.tmf.chart.core.tests/.classpath
tmf/org.eclipse.tracecompass.tmf.chart.core.tests/META-INF/MANIFEST.MF
tmf/org.eclipse.tracecompass.tmf.chart.core.tests/build.properties
tmf/org.eclipse.tracecompass.tmf.chart.core.tests/src/org/eclipse/tracecompass/tmf/chart/core/tests/chart/ChartDataTest.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.chart.core.tests/src/org/eclipse/tracecompass/tmf/chart/core/tests/chart/ChartModelTest.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.chart.core.tests/src/org/eclipse/tracecompass/tmf/chart/core/tests/chart/ChartSeriesTest.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.chart.core.tests/src/org/eclipse/tracecompass/tmf/chart/core/tests/consumer/NumericalConsumerTest.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.chart.core.tests/src/org/eclipse/tracecompass/tmf/chart/core/tests/resolver/DoubleResolverTest.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.chart.core.tests/src/org/eclipse/tracecompass/tmf/chart/core/tests/resolver/LongResolverTest.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.chart.core.tests/stubs/org/eclipse/tracecompass/tmf/chart/core/tests/stubs/StubChartProvider.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.chart.core.tests/stubs/org/eclipse/tracecompass/tmf/chart/core/tests/stubs/StubObject.java [new file with mode: 0644]
tmf/org.eclipse.tracecompass.tmf.chart.core/META-INF/MANIFEST.MF
tmf/org.eclipse.tracecompass.tmf.chart.core/src/org/eclipse/tracecompass/internal/provisional/tmf/chart/core/descriptor/DataChartNumericalDescriptor.java
tmf/org.eclipse.tracecompass.tmf.chart.core/src/org/eclipse/tracecompass/internal/provisional/tmf/chart/core/descriptor/DataChartStringDescriptor.java
tmf/pom.xml

index 5480bc80152d9604a26638ad3345b275e8994da7..aed35557fedd7efa43bfe401b6545ee3cc4ac7fc 100644 (file)
@@ -11,5 +11,6 @@
                </attributes>
        </classpathentry>
        <classpathentry kind="src" path="src"/>
+       <classpathentry kind="src" path="stubs"/>
        <classpathentry kind="output" path="bin"/>
 </classpath>
index 34db13603feb8543c3d83388d54b7668f047895d..a0ee4a98627c8fa3aa687ebaff4225ec1a229957 100644 (file)
@@ -12,3 +12,7 @@ Require-Bundle: org.eclipse.core.runtime,
  org.junit,
  org.eclipse.tracecompass.common.core,
  org.eclipse.tracecompass.tmf.chart.core
+Export-Package: org.eclipse.tracecompass.internal.tmf.chart.core.tests;x-internal:=true,
+ org.eclipse.tracecompass.tmf.chart.core.tests.chart,
+ org.eclipse.tracecompass.tmf.chart.core.tests.resolver,
+ org.eclipse.tracecompass.tmf.chart.core.tests.stubs
index 43d166e291531e3b6d1171863676546bf4384b60..7e8caffc785d788d1dd9df9fefd8ecf617b4c4d3 100644 (file)
@@ -7,7 +7,8 @@
 # http://www.eclipse.org/legal/epl-v10.html
 ###############################################################################
 
-source.. = src/
+source.. = src/,\
+           stubs/
 output.. = bin/
 bin.includes = META-INF/,\
                .,\
diff --git a/tmf/org.eclipse.tracecompass.tmf.chart.core.tests/src/org/eclipse/tracecompass/tmf/chart/core/tests/chart/ChartDataTest.java b/tmf/org.eclipse.tracecompass.tmf.chart.core.tests/src/org/eclipse/tracecompass/tmf/chart/core/tests/chart/ChartDataTest.java
new file mode 100644 (file)
index 0000000..e779237
--- /dev/null
@@ -0,0 +1,98 @@
+/*******************************************************************************
+ * Copyright (c) 2017 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.chart.core.tests.chart;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.chart.ChartData;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.chart.ChartSeries;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.descriptor.IDataChartDescriptor;
+import org.eclipse.tracecompass.tmf.chart.core.tests.stubs.StubChartProvider;
+import org.eclipse.tracecompass.tmf.chart.core.tests.stubs.StubObject;
+import org.junit.Test;
+
+/**
+ * Test the {@link ChartData} class
+ *
+ * @author Geneviève Bastien
+ */
+public class ChartDataTest {
+
+    private final @NonNull StubChartProvider fProvider = new StubChartProvider();
+
+    /**
+     * Test getting the descriptors for x and y series of a chart data
+     */
+    @Test
+    public void testGetDescriptors() {
+        // Create chart data with the string descriptor as x axis and a series
+        // for every other y axis
+        Collection<@NonNull IDataChartDescriptor<StubObject, ?>> dataDescriptors = fProvider.getDataDescriptors();
+        IDataChartDescriptor<StubObject, ?> xDesc = null;
+        for (IDataChartDescriptor<StubObject, ?> desc : dataDescriptors) {
+            if (desc.getName().equals(StubChartProvider.STRING_DESCRIPTOR)) {
+                xDesc = desc;
+                break;
+            }
+        }
+        assertNotNull(xDesc);
+
+        List<@NonNull ChartSeries> list = new ArrayList<>();
+        for (IDataChartDescriptor<StubObject, ?> desc : dataDescriptors) {
+            if (!desc.getName().equals(StubChartProvider.STRING_DESCRIPTOR)) {
+                list.add(new ChartSeries(xDesc, desc));
+            }
+        }
+        assertEquals(3, list.size());
+        ChartData data = new ChartData(fProvider, list);
+
+        // Verify that the series correspond to what has been added
+        Collection<@NonNull ChartSeries> chartSeries = data.getChartSeries();
+        assertEquals(3, chartSeries.size());
+
+        assertEquals(xDesc, data.getX(0));
+        assertEquals(xDesc, data.getX(1));
+        assertEquals(xDesc, data.getX(2));
+
+        assertEquals(list.get(0).getY(), data.getY(0));
+        assertEquals(list.get(1).getY(), data.getY(1));
+        assertEquals(list.get(2).getY(), data.getY(2));
+
+    }
+
+    /**
+     * Test that the series cannot be modified outside the class
+     */
+    @Test
+    public void testImmutableSeries() {
+        // Create chart data with only one series
+        Iterator<@NonNull IDataChartDescriptor<StubObject, ?>> dataDescriptors = fProvider.getDataDescriptors().iterator();
+        IDataChartDescriptor<StubObject, ?> x = dataDescriptors.next();
+        IDataChartDescriptor<StubObject, ?> y = dataDescriptors.next();
+        List<@NonNull ChartSeries> list = new ArrayList<>();
+        list.add(new ChartSeries(x, y));
+        ChartData data = new ChartData(fProvider, list);
+        assertEquals(1, data.getChartSeries().size());
+
+        // Add a new series to the list and make sure it is not in the data
+        // (which should be immutable)
+        y = dataDescriptors.next();
+        list.add(new ChartSeries(x, y));
+        assertEquals(1, data.getChartSeries().size());
+
+    }
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.chart.core.tests/src/org/eclipse/tracecompass/tmf/chart/core/tests/chart/ChartModelTest.java b/tmf/org.eclipse.tracecompass.tmf.chart.core.tests/src/org/eclipse/tracecompass/tmf/chart/core/tests/chart/ChartModelTest.java
new file mode 100644 (file)
index 0000000..9d25423
--- /dev/null
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (c) 2017 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.chart.core.tests.chart;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.chart.ChartModel;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.chart.ChartType;
+import org.junit.Test;
+
+/**
+ * Test the {@link ChartModel} class
+ *
+ * @author Geneviève Bastien
+ */
+public class ChartModelTest {
+
+    /**
+     * Test constructor of the class
+     */
+    @Test
+    public void testConstructor() {
+        // Normal title and x and y log scales
+        String title = "title";
+        ChartModel cm = new ChartModel(ChartType.BAR_CHART, title, true, true);
+        assertEquals(ChartType.BAR_CHART, cm.getChartType());
+        assertEquals(title, cm.getTitle());
+        assertTrue(cm.isXLogscale());
+        assertTrue(cm.isYLogscale());
+
+        // Title with accented characters, y log scale, but not x log scale
+        title = "éèëâ\nbla";
+        cm = new ChartModel(ChartType.SCATTER_CHART, title, false, true);
+        assertEquals(ChartType.SCATTER_CHART, cm.getChartType());
+        assertEquals(title, cm.getTitle());
+        assertFalse(cm.isXLogscale());
+        assertTrue(cm.isYLogscale());
+
+        // Title with special characters, no log scale
+        title = "&?%$/\"()";
+        cm = new ChartModel(ChartType.PIE_CHART, title, false, false);
+        assertEquals(ChartType.PIE_CHART, cm.getChartType());
+        assertEquals(title, cm.getTitle());
+        assertFalse(cm.isXLogscale());
+        assertFalse(cm.isYLogscale());
+    }
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.chart.core.tests/src/org/eclipse/tracecompass/tmf/chart/core/tests/chart/ChartSeriesTest.java b/tmf/org.eclipse.tracecompass.tmf.chart.core.tests/src/org/eclipse/tracecompass/tmf/chart/core/tests/chart/ChartSeriesTest.java
new file mode 100644 (file)
index 0000000..c7bec64
--- /dev/null
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Copyright (c) 2017 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.chart.core.tests.chart;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Collection;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.chart.ChartSeries;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.descriptor.IDataChartDescriptor;
+import org.eclipse.tracecompass.tmf.chart.core.tests.stubs.StubChartProvider;
+import org.eclipse.tracecompass.tmf.chart.core.tests.stubs.StubObject;
+import org.junit.Test;
+
+/**
+ * Test the {@link ChartSeries} class
+ *
+ * @author Geneviève Bastien
+ */
+public class ChartSeriesTest {
+
+    private final StubChartProvider fProvider = new StubChartProvider();
+
+    /**
+     * Test the constructor
+     */
+    @Test
+    public void testConstructor() {
+        Collection<@NonNull IDataChartDescriptor<StubObject, ?>> dataDescriptors = fProvider.getDataDescriptors();
+        IDataChartDescriptor<StubObject, ?> x = dataDescriptors.iterator().next();
+        IDataChartDescriptor<StubObject, ?> y = dataDescriptors.iterator().next();
+        ChartSeries series = new ChartSeries(x, y);
+        assertEquals(x, series.getX());
+        assertEquals(y, series.getY());
+    }
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.chart.core.tests/src/org/eclipse/tracecompass/tmf/chart/core/tests/consumer/NumericalConsumerTest.java b/tmf/org.eclipse.tracecompass.tmf.chart.core.tests/src/org/eclipse/tracecompass/tmf/chart/core/tests/consumer/NumericalConsumerTest.java
new file mode 100644 (file)
index 0000000..0dd0915
--- /dev/null
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * Copyright (c) 2017 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.chart.core.tests.consumer;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.function.Predicate;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.descriptor.IDataChartDescriptor;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.resolver.INumericalResolver;
+import org.eclipse.tracecompass.internal.tmf.chart.core.consumer.NumericalConsumer;
+import org.eclipse.tracecompass.tmf.chart.core.tests.stubs.StubChartProvider;
+import org.eclipse.tracecompass.tmf.chart.core.tests.stubs.StubObject;
+import org.junit.Test;
+
+/**
+ * Test the {@link NumericalConsumer} class
+ *
+ * @author Geneviève Bastien
+ */
+public class NumericalConsumerTest {
+
+    private final @NonNull StubChartProvider fProvider = new StubChartProvider();
+
+    /**
+     * Test the numerical consumer with only the resolver. It should not accept
+     * null values
+     */
+    @Test
+    public void testResolver() {
+        IDataChartDescriptor<StubObject, ?> descriptor = fProvider.getDataDescriptor(StubChartProvider.LONG_DESCRIPTOR);
+        NumericalConsumer consumer = new NumericalConsumer(INumericalResolver.class.cast(descriptor.getResolver()));
+
+        // Test with a first object
+        StubObject obj = new StubObject("str", 1, 10L, 10.0);
+        assertTrue(consumer.test(obj));
+        consumer.accept(obj);
+        assertEquals(Long.valueOf(10L), consumer.getData().get(0));
+
+        // Test with a second object
+        obj = new StubObject("str", 1, 20L, 10.0);
+        assertTrue(consumer.test(obj));
+        consumer.accept(obj);
+        assertEquals(Long.valueOf(20L), consumer.getData().get(1));
+
+        obj = new StubObject("str", 1, null, 10.0);
+        assertFalse(consumer.test(obj));
+
+        // Test eh minimum and maximum values
+        assertEquals(Long.valueOf(10L), consumer.getMin());
+        assertEquals(Long.valueOf(20L), consumer.getMax());
+    }
+
+    /**
+     * Test the numerical consumer with only the resolver and predicate.
+     */
+    @Test
+    public void testWithPredicate() {
+        IDataChartDescriptor<StubObject, ?> descriptor = fProvider.getDataDescriptor(StubChartProvider.LONG_DESCRIPTOR);
+        Predicate<@Nullable Number> predicate = d -> true;
+        NumericalConsumer consumer = new NumericalConsumer(INumericalResolver.class.cast(descriptor.getResolver()), predicate);
+        StubObject obj = new StubObject("str", 1, 10L, 10.0);
+
+        assertTrue(consumer.test(obj));
+        consumer.accept(obj);
+        assertEquals(Long.valueOf(10L), consumer.getData().get(0));
+
+        obj = new StubObject("str", 1, null, 10.0);
+        assertTrue(consumer.test(obj));
+    }
+
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.chart.core.tests/src/org/eclipse/tracecompass/tmf/chart/core/tests/resolver/DoubleResolverTest.java b/tmf/org.eclipse.tracecompass.tmf.chart.core.tests/src/org/eclipse/tracecompass/tmf/chart/core/tests/resolver/DoubleResolverTest.java
new file mode 100644 (file)
index 0000000..f215745
--- /dev/null
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * Copyright (c) 2017 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.chart.core.tests.resolver;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.function.Function;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.resolver.AbstractDoubleResolver;
+import org.eclipse.tracecompass.tmf.chart.core.tests.stubs.StubObject;
+import org.junit.Test;
+
+/**
+ * Test the {@link AbstractDoubleResolver} class
+ *
+ * @author Geneviève Bastien
+ */
+public class DoubleResolverTest {
+
+    private static final AbstractDoubleResolver<StubObject> DOUBLE_RESOLVER = new AbstractDoubleResolver<StubObject>() {
+        @Override
+        public @NonNull Function<StubObject, @Nullable Double> getMapper() {
+            return o -> o.getDbl();
+        }
+    };
+
+    /**
+     * Test the limit values of the long resolver
+     */
+    @Test
+    public void testLimitValues() {
+        assertEquals(Double.MIN_VALUE, DOUBLE_RESOLVER.getMinValue(), 0.000001);
+        assertEquals(Double.MAX_VALUE, DOUBLE_RESOLVER.getMaxValue(), 0.000001);
+        assertEquals(0.0, DOUBLE_RESOLVER.getZeroValue(), 0.000001);
+    }
+
+    /**
+     * Test the {@link AbstractDoubleResolver#getComparator()} method
+     */
+    @Test
+    public void testComparator() {
+        List<@NonNull Double> list = new ArrayList<>();
+        // Add a few items not ordered naturally
+        list.add(0.0);
+        list.add(1234.1234);
+        list.add(-3.45);
+        Collections.sort(list, DOUBLE_RESOLVER.getComparator());
+        assertEquals(Double.valueOf(-3.45), list.get(0), 0.000001);
+        assertEquals(0.0, list.get(1), 0.000001);
+        assertEquals(1234.1234, list.get(2), 0.000001);
+    }
+
+    /**
+     * Test the {@link AbstractDoubleResolver#getMapper()} method
+     */
+    @Test
+    public void testMapper() {
+        Function<StubObject, @Nullable Double> mapper = DOUBLE_RESOLVER.getMapper();
+
+        StubObject obj = new StubObject("str", 1, 0l, -3.45);
+        Double dbl = mapper.apply(obj);
+        assertNotNull(dbl);
+        assertEquals(Double.valueOf(-3.45), dbl, 0.000001);
+
+        obj = new StubObject("str", 1, 0l, 0.0);
+        dbl = mapper.apply(obj);
+        assertNotNull(dbl);
+        assertEquals(0.0, dbl, 0.000001);
+
+        obj = new StubObject("str", 1, 1234l, 1234.1234);
+        dbl = mapper.apply(obj);
+        assertNotNull(dbl);
+        assertEquals(Double.valueOf(1234.1234), dbl, 0.000001);
+
+    }
+
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.chart.core.tests/src/org/eclipse/tracecompass/tmf/chart/core/tests/resolver/LongResolverTest.java b/tmf/org.eclipse.tracecompass.tmf.chart.core.tests/src/org/eclipse/tracecompass/tmf/chart/core/tests/resolver/LongResolverTest.java
new file mode 100644 (file)
index 0000000..56d054c
--- /dev/null
@@ -0,0 +1,83 @@
+/*******************************************************************************
+ * Copyright (c) 2017 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.chart.core.tests.resolver;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.function.Function;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.resolver.AbstractLongResolver;
+import org.eclipse.tracecompass.tmf.chart.core.tests.stubs.StubObject;
+import org.junit.Test;
+
+/**
+ * Test the {@link AbstractLongResolver} class
+ *
+ * @author Geneviève Bastien
+ */
+public class LongResolverTest {
+
+    private static final AbstractLongResolver<StubObject> LONG_RESOLVER = new AbstractLongResolver<StubObject>() {
+        @Override
+        public @NonNull Function<StubObject, @Nullable Long> getMapper() {
+            return o -> o.getLong();
+        }
+    };
+
+    /**
+     * Test the limit values of the long resolver
+     */
+    @Test
+    public void testLimitValues() {
+        assertEquals((Long) Long.MIN_VALUE, LONG_RESOLVER.getMinValue());
+        assertEquals((Long) Long.MAX_VALUE, LONG_RESOLVER.getMaxValue());
+        assertEquals((Long) 0l, LONG_RESOLVER.getZeroValue());
+    }
+
+    /**
+     * Test the {@link AbstractLongResolver#getComparator()} method
+     */
+    @Test
+    public void testComparator() {
+        List<@NonNull Long> list = new ArrayList<>();
+        // Add a few items not ordered naturally
+        list.add(0l);
+        list.add(1234l);
+        list.add(-1234l);
+        Collections.sort(list, LONG_RESOLVER.getComparator());
+        assertEquals(Long.valueOf(-1234l), list.get(0));
+        assertEquals((Long) 0l, list.get(1));
+        assertEquals((Long) 1234l, list.get(2));
+    }
+
+    /**
+     * Test the {@link AbstractLongResolver#getMapper()} method
+     */
+    @Test
+    public void testMapper() {
+        Function<StubObject, @Nullable Long> mapper = LONG_RESOLVER.getMapper();
+
+        StubObject obj = new StubObject("str", 1, -1234l, 0.0);
+        assertEquals(Long.valueOf(-1234l), mapper.apply(obj));
+
+        obj = new StubObject("str", 1, 0l, 0.0);
+        assertEquals(Long.valueOf(0l), mapper.apply(obj));
+
+        obj = new StubObject("str", 1, 1234l, 0.0);
+        assertEquals(Long.valueOf(1234l), mapper.apply(obj));
+
+    }
+
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.chart.core.tests/stubs/org/eclipse/tracecompass/tmf/chart/core/tests/stubs/StubChartProvider.java b/tmf/org.eclipse.tracecompass.tmf.chart.core.tests/stubs/org/eclipse/tracecompass/tmf/chart/core/tests/stubs/StubChartProvider.java
new file mode 100644 (file)
index 0000000..53ba566
--- /dev/null
@@ -0,0 +1,148 @@
+/*******************************************************************************
+ * Copyright (c) 2017 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.chart.core.tests.stubs;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Comparator;
+import java.util.List;
+import java.util.function.Function;
+import java.util.stream.Stream;
+
+import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
+import org.eclipse.tracecompass.common.core.NonNullUtils;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.descriptor.DataChartNumericalDescriptor;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.descriptor.DataChartStringDescriptor;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.descriptor.IDataChartDescriptor;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.model.IDataChartProvider;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.resolver.AbstractDoubleResolver;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.resolver.AbstractLongResolver;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.resolver.INumericalResolver;
+import org.eclipse.tracecompass.internal.provisional.tmf.chart.core.resolver.IStringResolver;
+
+/**
+ * A chart provider that will return a few long values
+ *
+ * @author Geneviève Bastien
+ */
+public class StubChartProvider implements IDataChartProvider<StubObject> {
+
+    /**
+     * Name of this chart provider
+     */
+    public static final @NonNull String NAME = "Long Chart Provider";
+    /**
+     * Name of the String descriptor
+     */
+    public static final @NonNull String STRING_DESCRIPTOR = "String";
+    /**
+     * Name of the Integer descriptor
+     */
+    public static final @NonNull String INTEGER_DESCRIPTOR = "Integer";
+    /**
+     * Name of the Long descriptor
+     */
+    public static final @NonNull String LONG_DESCRIPTOR = "Long";
+    /**
+     * Name of the Double descriptor
+     */
+    public static final @NonNull String DOUBLE_DESCRIPTOR = "Double";
+
+    private final @NonNull List<@NonNull StubObject> fSource = new ArrayList<>();
+
+    @Override
+    public @NonNull String getName() {
+        return NAME;
+    }
+
+    @Override
+    public @NonNull Stream<@NonNull StubObject> getSource() {
+        return NonNullUtils.checkNotNull(fSource.stream());
+    }
+
+    /**
+     * Adds an object to this provider's source. It will be returned with the
+     * stream
+     *
+     * @param obj
+     *            an object to add to the data stream
+     */
+    public void addData(@NonNull StubObject obj) {
+        fSource.add(obj);
+    }
+
+    @Override
+    public @NonNull Collection<@NonNull IDataChartDescriptor<StubObject, ?>> getDataDescriptors() {
+        List<@NonNull IDataChartDescriptor<StubObject, ?>> list = new ArrayList<>();
+        list.add(new DataChartStringDescriptor<>(STRING_DESCRIPTOR, new IStringResolver<StubObject>() {
+
+            @Override
+            public @NonNull Function<StubObject, @Nullable String> getMapper() {
+                return o -> o.getString();
+            }
+        }));
+        list.add(new DataChartNumericalDescriptor<>(INTEGER_DESCRIPTOR, new INumericalResolver<StubObject, @NonNull Integer>() {
+
+            @Override
+            public @NonNull Function<StubObject, @Nullable Integer> getMapper() {
+                return o -> o.getInt();
+            }
+
+            @Override
+            public @NonNull Comparator<@NonNull Integer> getComparator() {
+                return NonNullUtils.checkNotNull(Comparator.naturalOrder());
+            }
+
+            @Override
+            public Integer getMinValue() {
+                return Integer.MIN_VALUE;
+            }
+
+            @Override
+            public Integer getMaxValue() {
+                return Integer.MAX_VALUE;
+            }
+
+            @Override
+            public Integer getZeroValue() {
+                return 0;
+            }
+        }));
+        list.add(new DataChartNumericalDescriptor<>(LONG_DESCRIPTOR, new AbstractLongResolver<StubObject>() {
+
+            @Override
+            public @NonNull Function<StubObject, @Nullable Long> getMapper() {
+                return o -> o.getLong();
+            }
+        }));
+        list.add(new DataChartNumericalDescriptor<>(DOUBLE_DESCRIPTOR, new AbstractDoubleResolver<StubObject>() {
+
+            @Override
+            public @NonNull Function<StubObject, @Nullable Double> getMapper() {
+                return o -> o.getDbl();
+            }
+        }));
+        return list;
+    }
+
+    /**
+     * Get a descriptor with the specified name
+     *
+     * @param name
+     *            The name of the desired descriptor
+     * @return The descriptor
+     */
+    public IDataChartDescriptor<StubObject, ?> getDataDescriptor(String name) {
+        return getDataDescriptors().stream().filter(d -> d.getName().equals(name))
+                .findFirst().get();
+    }
+
+}
diff --git a/tmf/org.eclipse.tracecompass.tmf.chart.core.tests/stubs/org/eclipse/tracecompass/tmf/chart/core/tests/stubs/StubObject.java b/tmf/org.eclipse.tracecompass.tmf.chart.core.tests/stubs/org/eclipse/tracecompass/tmf/chart/core/tests/stubs/StubObject.java
new file mode 100644 (file)
index 0000000..af86abb
--- /dev/null
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * Copyright (c) 2017 École Polytechnique de Montréal
+ *
+ * All rights reserved. This program and the accompanying materials are
+ * made available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.eclipse.tracecompass.tmf.chart.core.tests.stubs;
+
+/**
+ * A stub object to use by this stub
+ *
+ * @author Geneviève Bastien
+ */
+public class StubObject {
+    private final String fString;
+    private final Integer fInt;
+    private final Long fLong;
+    private final Double fDbl;
+
+    /**
+     * Constructor
+     *
+     * @param string
+     *            A string value
+     * @param intVal
+     *            An int value
+     * @param longVal
+     *            A long value
+     * @param dblVal
+     *            A double value
+     */
+    public StubObject(String string, Integer intVal, Long longVal, Double dblVal) {
+        fString = string;
+        fInt = intVal;
+        fLong = longVal;
+        fDbl = dblVal;
+    }
+
+    /**
+     * Get the string value
+     *
+     * @return The string value
+     */
+    public String getString() {
+        return fString;
+    }
+
+    /**
+     * Get the int value
+     *
+     * @return the int value
+     */
+    public Integer getInt() {
+        return fInt;
+    }
+
+    /**
+     * Get the long value
+     *
+     * @return The long value
+     */
+    public Long getLong() {
+        return fLong;
+    }
+
+    /**
+     * Get the double value
+     *
+     * @return the double value
+     */
+    public Double getDbl() {
+        return fDbl;
+    }
+}
index ed20b3f8c2ab3a3f81974bbf7e5971462abcea4c..242aba1bdddcdf713076838c6dd63f11119f4aa1 100644 (file)
@@ -10,10 +10,10 @@ Bundle-ActivationPolicy: lazy
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Require-Bundle: org.eclipse.core.runtime,
  org.eclipse.tracecompass.common.core
-Export-Package: org.eclipse.tracecompass.internal.provisional.tmf.chart.core.chart;x-friends:="org.eclipse.tracecompass.tmf.chart.ui",
- org.eclipse.tracecompass.internal.provisional.tmf.chart.core.descriptor;x-friends:="org.eclipse.tracecompass.tmf.chart.ui",
- org.eclipse.tracecompass.internal.provisional.tmf.chart.core.model;x-friends:="org.eclipse.tracecompass.tmf.chart.ui",
- org.eclipse.tracecompass.internal.provisional.tmf.chart.core.resolver;x-friends:="org.eclipse.tracecompass.tmf.chart.ui",
+Export-Package: org.eclipse.tracecompass.internal.provisional.tmf.chart.core.chart;x-friends:="org.eclipse.tracecompass.tmf.chart.ui,org.eclipse.tracecompass.tmf.chart.core.tests",
+ org.eclipse.tracecompass.internal.provisional.tmf.chart.core.descriptor;x-friends:="org.eclipse.tracecompass.tmf.chart.ui,org.eclipse.tracecompass.tmf.chart.core.tests",
+ org.eclipse.tracecompass.internal.provisional.tmf.chart.core.model;x-friends:="org.eclipse.tracecompass.tmf.chart.ui,org.eclipse.tracecompass.tmf.chart.core.tests",
+ org.eclipse.tracecompass.internal.provisional.tmf.chart.core.resolver;x-friends:="org.eclipse.tracecompass.tmf.chart.ui,org.eclipse.tracecompass.tmf.chart.core.tests",
  org.eclipse.tracecompass.internal.tmf.chart.core;x-internal:=true,
  org.eclipse.tracecompass.internal.tmf.chart.core.aggregator;x-friends:="org.eclipse.tracecompass.tmf.chart.ui,org.eclipse.tracecompass.tmf.chart.core.tests",
  org.eclipse.tracecompass.internal.tmf.chart.core.chart;x-internal:=true,
index e417fa96fe042bfc8630d94b4cb24c8f302e8877..edf554976a2fed6b5a37a3809b70b94dfad0dd3b 100644 (file)
@@ -75,4 +75,9 @@ public class DataChartNumericalDescriptor<T, R extends Number> implements IDataC
         return null;
     }
 
+    @Override
+    public String toString() {
+        return "Numerical Descriptor: " + getName(); //$NON-NLS-1$
+    }
+
 }
index 0c41207ab1ebe945593e0620985d1aebd45012fd..39e23af0f1451918e33647edb143411afcb5fe21 100644 (file)
@@ -64,4 +64,9 @@ public class DataChartStringDescriptor<T> implements IDataChartDescriptor<T, Str
         return fName;
     }
 
+    @Override
+    public String toString() {
+        return "String Descriptor: " + getName(); //$NON-NLS-1$
+    }
+
 }
index 7a21cdd2e0f135400b59da85f8c394eab3eeedb0..d3b9d42e703436a3e8903a302007d58cbaa74db1 100644 (file)
@@ -37,7 +37,7 @@
     <module>org.eclipse.tracecompass.tmf.analysis.xml.ui.tests</module>
 
     <module>org.eclipse.tracecompass.tmf.chart.core</module>
-    <!-- <module>org.eclipse.tracecompass.tmf.chart.core.tests</module> -->
+    <module>org.eclipse.tracecompass.tmf.chart.core.tests</module>
     <module>org.eclipse.tracecompass.tmf.chart.ui</module>
 
     <module>org.eclipse.tracecompass.tmf.remote</module>
This page took 0.03497 seconds and 5 git commands to generate.