diff --git a/src/org/aavso/tools/vstar/plugin/ob/src/impl/AIDWebServiceXMLAttributeObservationSourcePlugin.java b/src/org/aavso/tools/vstar/plugin/ob/src/impl/AIDWebServiceXMLAttributeObservationSourcePlugin.java index 2bbd05e01..042fb55c7 100644 --- a/src/org/aavso/tools/vstar/plugin/ob/src/impl/AIDWebServiceXMLAttributeObservationSourcePlugin.java +++ b/src/org/aavso/tools/vstar/plugin/ob/src/impl/AIDWebServiceXMLAttributeObservationSourcePlugin.java @@ -47,6 +47,7 @@ * This intrinsic observation source plug-in retrieves AID observations via the * VSX web service. */ +@Deprecated public class AIDWebServiceXMLAttributeObservationSourcePlugin extends AIDWebServiceObservationSourcePluginBase { diff --git a/src/org/aavso/tools/vstar/ui/dialog/InfoDialog.java b/src/org/aavso/tools/vstar/ui/dialog/InfoDialog.java index 0685705ac..83f6405c0 100644 --- a/src/org/aavso/tools/vstar/ui/dialog/InfoDialog.java +++ b/src/org/aavso/tools/vstar/ui/dialog/InfoDialog.java @@ -55,32 +55,50 @@ public class InfoDialog extends JDialog implements ActionListener { * The loaded star messages. */ public InfoDialog(List newStarMessages) { + this(newStarMessages, true); + } + + /** + * Package-private constructor that allows tests to build the dialog without + * displaying it. When {@code show} is {@code false} all Swing setup, + * {@code setLocationRelativeTo}, and {@code setVisible(true)} are skipped so + * that the dialog can be constructed without a live {@code Mediator} UI. + * + * @param newStarMessages + * The loaded star messages (ignored when show is false). + * @param show + * {@code true} to build and display normally; {@code false} for + * tests. + */ + InfoDialog(List newStarMessages, boolean show) { super(DocumentManager.findActiveWindow()); this.setTitle("Information"); - JPanel topPane = new JPanel(); - topPane.setLayout(new BoxLayout(topPane, BoxLayout.PAGE_AXIS)); - topPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); + if (show) { + JPanel topPane = new JPanel(); + topPane.setLayout(new BoxLayout(topPane, BoxLayout.PAGE_AXIS)); + topPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); - JScrollPane scrollPane = new JScrollPane( - createInfoPanel(newStarMessages)); - topPane.add(scrollPane); + JScrollPane scrollPane = new JScrollPane( + createInfoPanel(newStarMessages)); + topPane.add(scrollPane); - topPane.add(Box.createRigidArea(new Dimension(10, 10))); + topPane.add(Box.createRigidArea(new Dimension(10, 10))); - JPanel buttonPane = new JPanel(); - JButton dismissButton = new JButton("Dismiss"); - dismissButton.addActionListener(this); - buttonPane.add(dismissButton, BorderLayout.CENTER); - topPane.add(buttonPane); + JPanel buttonPane = new JPanel(); + JButton dismissButton = new JButton("Dismiss"); + dismissButton.addActionListener(this); + buttonPane.add(dismissButton, BorderLayout.CENTER); + topPane.add(buttonPane); - this.getContentPane().add(topPane); + this.getContentPane().add(topPane); - this.getRootPane().setDefaultButton(dismissButton); + this.getRootPane().setDefaultButton(dismissButton); - this.pack(); - this.setLocationRelativeTo(Mediator.getUI().getContentPane()); - this.setVisible(true); + this.pack(); + this.setLocationRelativeTo(Mediator.getUI().getContentPane()); + this.setVisible(true); + } } /** diff --git a/test/AllTests.java b/test/AllTests.java index 080aeac65..92f588634 100644 --- a/test/AllTests.java +++ b/test/AllTests.java @@ -61,6 +61,8 @@ import org.aavso.tools.vstar.ui.dialog.DateToJdDialogTest; import org.aavso.tools.vstar.ui.dialog.DiscrepantReportDialogTest; import org.aavso.tools.vstar.ui.dialog.DoubleFieldTest; +import org.aavso.tools.vstar.ui.dialog.FileExtensionFilterTest; +import org.aavso.tools.vstar.ui.dialog.InfoDialogTest; import org.aavso.tools.vstar.ui.dialog.MultiEntryComponentDialogTest; import org.aavso.tools.vstar.ui.dialog.PeriodAnalysisPluginDialogsTest; import org.aavso.tools.vstar.ui.dialog.PhaseParameterDialogTest; @@ -68,10 +70,16 @@ import org.aavso.tools.vstar.ui.dialog.RadioButtonDialogTest; import org.aavso.tools.vstar.ui.dialog.SeriesTypeCreationDialogTest; import org.aavso.tools.vstar.ui.dialog.TextDialogTest; +import org.aavso.tools.vstar.ui.dialog.period.PeriodAnalysis2DChartPaneTest; +import org.aavso.tools.vstar.ui.model.list.AAVSOFormatRawDataColumnInfoSourceTest; import org.aavso.tools.vstar.ui.model.list.AbstractSyntheticObservationTableModelTest; import org.aavso.tools.vstar.ui.model.list.PeriodAnalysisDataTableModelTest; import org.aavso.tools.vstar.ui.model.list.ValidObservationTableModelTest; import org.aavso.tools.vstar.ui.model.list.WWZDataTableModelTest; +import org.aavso.tools.vstar.ui.model.plot.ObservationAndMeanPlotModelTest; +import org.aavso.tools.vstar.ui.pane.list.ListSearchPaneTest; +import org.aavso.tools.vstar.ui.pane.list.ObservationListPaneTest; +import org.aavso.tools.vstar.ui.pane.list.SyntheticObservationListPaneTest; import org.aavso.tools.vstar.ui.pane.list.VisibleSeriesRowFilterTest; import org.aavso.tools.vstar.vela.VeLaTest; @@ -139,12 +147,16 @@ public static Test suite() { suite.addTestSuite(PeriodAnalysisDataTableModelTest.class); suite.addTestSuite(WWZDataTableModelTest.class); suite.addTestSuite(AbstractSyntheticObservationTableModelTest.class); + suite.addTestSuite(ListSearchPaneTest.class); + suite.addTestSuite(ObservationListPaneTest.class); + suite.addTestSuite(SyntheticObservationListPaneTest.class); suite.addTestSuite(VisibleSeriesRowFilterTest.class); suite.addTestSuite(DateToJdDialogTest.class); suite.addTestSuite(TextDialogTest.class); suite.addTestSuite(AbstractOkCancelDialogTest.class); suite.addTestSuite(AboutBoxTest.class); suite.addTestSuite(DoubleFieldTest.class); + suite.addTestSuite(FileExtensionFilterTest.class); suite.addTestSuite(MultiEntryComponentDialogTest.class); suite.addTestSuite(PolynomialDegreeDialogTest.class); suite.addTestSuite(RadioButtonDialogTest.class); @@ -152,6 +164,10 @@ public static Test suite() { suite.addTestSuite(PhaseParameterDialogTest.class); suite.addTestSuite(SeriesTypeCreationDialogTest.class); suite.addTestSuite(PeriodAnalysisPluginDialogsTest.class); + suite.addTestSuite(InfoDialogTest.class); + suite.addTestSuite(AAVSOFormatRawDataColumnInfoSourceTest.class); + suite.addTestSuite(ObservationAndMeanPlotModelTest.class); + suite.addTestSuite(PeriodAnalysis2DChartPaneTest.class); // $JUnit-END$ return suite; diff --git a/test/org/aavso/tools/vstar/ui/dialog/FileExtensionFilterTest.java b/test/org/aavso/tools/vstar/ui/dialog/FileExtensionFilterTest.java new file mode 100644 index 000000000..6915ab727 --- /dev/null +++ b/test/org/aavso/tools/vstar/ui/dialog/FileExtensionFilterTest.java @@ -0,0 +1,64 @@ +/** + * VStar: a statistical analysis tool for variable star data. + * Copyright (C) 2009 AAVSO (http://www.aavso.org/) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.aavso.tools.vstar.ui.dialog; + +import java.io.File; +import java.util.Arrays; +import java.util.List; + +import junit.framework.TestCase; + +/** + * Unit tests for {@link FileExtensionFilter}. + */ +public class FileExtensionFilterTest extends TestCase { + + private static final List EXTENSIONS = Arrays.asList(".csv", ".txt"); + + private FileExtensionFilter filter; + + @Override + protected void setUp() { + filter = new FileExtensionFilter(EXTENSIONS); + } + + public void testDirectoryIsAlwaysAccepted() { + File dir = new File(System.getProperty("java.io.tmpdir")); + assertTrue("A directory should always be accepted", filter.accept(dir)); + } + + public void testFileWithMatchingExtensionIsAccepted() { + File f = new File("data.csv"); + assertTrue("A file with a matching extension should be accepted", filter.accept(f)); + } + + public void testFileWithMatchingExtensionCaseInsensitive() { + File f = new File("data.TXT"); + assertTrue("Extension matching should be case-insensitive", filter.accept(f)); + } + + public void testFileWithNonMatchingExtensionIsRejected() { + File f = new File("data.xml"); + assertFalse("A file with a non-matching extension should be rejected", filter.accept(f)); + } + + public void testFileWithNoExtensionIsRejected() { + File f = new File("datafile"); + assertFalse("A file with no extension should be rejected", filter.accept(f)); + } +} diff --git a/test/org/aavso/tools/vstar/ui/dialog/InfoDialogTest.java b/test/org/aavso/tools/vstar/ui/dialog/InfoDialogTest.java new file mode 100644 index 000000000..27cf570c9 --- /dev/null +++ b/test/org/aavso/tools/vstar/ui/dialog/InfoDialogTest.java @@ -0,0 +1,65 @@ +/** + * VStar: a statistical analysis tool for variable star data. + * Copyright (C) 2009 AAVSO (http://www.aavso.org/) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.aavso.tools.vstar.ui.dialog; + +import java.util.Collections; +import java.util.Locale; + +import junit.framework.TestCase; + +/** + * Tests for {@link InfoDialog}. + * + * Uses the package-private {@code InfoDialog(messages, show=false)} constructor + * to build the dialog without displaying it, bypassing the + * {@code Mediator.getUI()} call and the blocking {@code setVisible(true)}. + * + * Note: text-content testing would require a fully populated + * {@link org.aavso.tools.vstar.ui.mediator.message.NewStarMessage} with a + * concrete {@link org.aavso.tools.vstar.input.AbstractObservationRetriever}; + * title and modal-flag verification are sufficient to exercise the constructor + * path without that complexity. + * + * Part of issue #579 (GUI code coverage, prong D). + */ +public class InfoDialogTest extends TestCase { + + @Override + protected void setUp() { + Locale.setDefault(Locale.ENGLISH); + } + + public void testTitle() { + InfoDialog dialog = new InfoDialog(Collections.emptyList(), false); + try { + assertEquals("Information", dialog.getTitle()); + } finally { + dialog.dispose(); + } + } + + public void testNotModal() { + InfoDialog dialog = new InfoDialog(Collections.emptyList(), false); + try { + assertFalse("InfoDialog should not be modal by default", + dialog.isModal()); + } finally { + dialog.dispose(); + } + } +} diff --git a/test/org/aavso/tools/vstar/ui/dialog/period/PeriodAnalysis2DChartPaneTest.java b/test/org/aavso/tools/vstar/ui/dialog/period/PeriodAnalysis2DChartPaneTest.java new file mode 100644 index 000000000..1e430e96f --- /dev/null +++ b/test/org/aavso/tools/vstar/ui/dialog/period/PeriodAnalysis2DChartPaneTest.java @@ -0,0 +1,155 @@ +/** + * VStar: a statistical analysis tool for variable star data. + * Copyright (C) 2009 AAVSO (http://www.aavso.org/) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.aavso.tools.vstar.ui.dialog.period; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +import junit.framework.TestCase; + +import org.aavso.tools.vstar.ui.model.plot.PeriodAnalysis2DPlotModel; +import org.aavso.tools.vstar.util.period.PeriodAnalysisCoordinateType; +import org.jfree.chart.ChartFactory; +import org.jfree.chart.JFreeChart; +import org.jfree.chart.plot.PlotOrientation; + +/** + * Tests for {@link PeriodAnalysis2DChartPane}. + * + * The chart pane's constructor does not call {@code Mediator} (only + * {@link PeriodAnalysis2DChartPane#startup()} and + * {@link PeriodAnalysis2DChartPane#cleanup()} do), so it can be constructed + * and inspected in isolation. + * + * Note: {@code WeightedWaveletZTransformResultDialog} and + * {@code PeriodAnalysis2DResultDialog} both call + * {@code PeriodAnalysisDialogBase#prepareDialog()} in their constructors, which + * in turn calls {@code Mediator.getUI().getContentPane()}. Applying a + * show=false pattern to those dialogs would require changes to the base class + * and each subclass's {@code startup()} call; the chart pane offers the same + * coverage at much lower scaffolding cost. + * + * Part of issue #579 (GUI code coverage, prong D). + */ +public class PeriodAnalysis2DChartPaneTest extends TestCase { + + private PeriodAnalysis2DPlotModel plotModel; + private JFreeChart chart; + private PeriodAnalysis2DChartPane pane; + + @Override + protected void setUp() { + Locale.setDefault(Locale.ENGLISH); + + // Minimal data: two frequency/power pairs. + List frequencies = Arrays.asList(1.0, 2.0, 3.0); + List powers = Arrays.asList(0.3, 0.8, 0.5); + + Map> data = + new HashMap>(); + data.put(PeriodAnalysisCoordinateType.FREQUENCY, frequencies); + data.put(PeriodAnalysisCoordinateType.POWER, powers); + + plotModel = new PeriodAnalysis2DPlotModel( + data, + PeriodAnalysisCoordinateType.FREQUENCY, + PeriodAnalysisCoordinateType.POWER, + false); + + chart = ChartFactory.createXYLineChart( + "Test Chart", "Frequency", "Power", + plotModel, PlotOrientation.VERTICAL, + true, true, false); + + pane = new PeriodAnalysis2DChartPane(chart, plotModel, true); + } + + // --- Basic construction and accessors --- + + public void testGetChartReturnsNonNull() { + assertNotNull(pane.getChart()); + } + + public void testGetChartReturnsSameChart() { + assertSame(chart, pane.getChart()); + } + + public void testGetModelReturnsNonNull() { + assertNotNull(pane.getModel()); + } + + public void testGetModelReturnsSameModel() { + assertSame(plotModel, pane.getModel()); + } + + // --- Chart pane ID --- + + public void testChartPaneIDInitiallyNull() { + assertNull(pane.getChartPaneID()); + } + + public void testSetChartPaneID() { + pane.setChartPaneID("PlotPane0"); + assertEquals("PlotPane0", pane.getChartPaneID()); + } + + // --- Underlying plot model data --- + + public void testPlotModelSeriesCount() { + assertEquals(1, plotModel.getSeriesCount()); + } + + public void testPlotModelItemCount() { + assertEquals(3, plotModel.getItemCount(0)); + } + + public void testPlotModelDomainType() { + assertEquals(PeriodAnalysisCoordinateType.FREQUENCY, + plotModel.getDomainType()); + } + + public void testPlotModelRangeType() { + assertEquals(PeriodAnalysisCoordinateType.POWER, + plotModel.getRangeType()); + } + + public void testPlotModelNotLogarithmicByDefault() { + assertFalse(plotModel.isLogarithmic()); + } + + public void testPlotModelSetLogarithmic() { + plotModel.setLogarithmic(true); + assertTrue(plotModel.isLogarithmic()); + plotModel.setLogarithmic(false); + } + + public void testPlotModelXValues() { + assertEquals(1.0, plotModel.getX(0, 0).doubleValue(), 1e-9); + assertEquals(2.0, plotModel.getX(0, 1).doubleValue(), 1e-9); + assertEquals(3.0, plotModel.getX(0, 2).doubleValue(), 1e-9); + } + + public void testPlotModelYValues() { + assertEquals(0.3, plotModel.getY(0, 0).doubleValue(), 1e-9); + assertEquals(0.8, plotModel.getY(0, 1).doubleValue(), 1e-9); + assertEquals(0.5, plotModel.getY(0, 2).doubleValue(), 1e-9); + } +} diff --git a/test/org/aavso/tools/vstar/ui/model/list/AAVSOFormatRawDataColumnInfoSourceTest.java b/test/org/aavso/tools/vstar/ui/model/list/AAVSOFormatRawDataColumnInfoSourceTest.java new file mode 100644 index 000000000..4800efe54 --- /dev/null +++ b/test/org/aavso/tools/vstar/ui/model/list/AAVSOFormatRawDataColumnInfoSourceTest.java @@ -0,0 +1,171 @@ +/** + * VStar: a statistical analysis tool for variable star data. + * Copyright (C) 2009 AAVSO (http://www.aavso.org/) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.aavso.tools.vstar.ui.model.list; + +import java.util.Collection; +import java.util.Locale; + +import junit.framework.TestCase; + +/** + * Pure unit tests for {@link AAVSOFormatRawDataColumnInfoSource}. + * + * This is a data-only class (column metadata), so no Swing display is needed. + * + * Part of issue #579 (GUI code coverage, prong D). + */ +public class AAVSOFormatRawDataColumnInfoSourceTest extends TestCase { + + // Column indices from the production class (package-private constants + // are not accessible here, so we replicate the expected values). + private static final int EXPECTED_COLUMN_COUNT_NO_LINE_NUMS = 27; + private static final int EXPECTED_COLUMN_COUNT_WITH_LINE_NUMS = 28; + + // Well-known column indices for type assertions. + private static final int DISCREPANT_COLUMN = 25; + private static final int LINE_NUM_COLUMN = 27; + + private AAVSOFormatRawDataColumnInfoSource sourceWithLine; + private AAVSOFormatRawDataColumnInfoSource sourceNoLine; + + @Override + protected void setUp() { + Locale.setDefault(Locale.ENGLISH); + sourceWithLine = new AAVSOFormatRawDataColumnInfoSource(true); + sourceNoLine = new AAVSOFormatRawDataColumnInfoSource(false); + } + + // --- getColumnCount --- + + public void testColumnCountWithLineNumbers() { + assertEquals(EXPECTED_COLUMN_COUNT_WITH_LINE_NUMS, + sourceWithLine.getColumnCount()); + } + + public void testColumnCountWithoutLineNumbers() { + assertEquals(EXPECTED_COLUMN_COUNT_NO_LINE_NUMS, + sourceNoLine.getColumnCount()); + } + + // --- getTableColumnTitle (representative sample) --- + + public void testColumnTitleAtIndexZeroIsTime() { + String title = sourceWithLine.getTableColumnTitle(0); + assertNotNull(title); + assertTrue("Expected 'Time' but got: " + title, + title.equalsIgnoreCase("time")); + } + + public void testColumnTitleMagnitude() { + assertEquals("Magnitude", sourceWithLine.getTableColumnTitle(2)); + } + + public void testColumnTitleUncertainty() { + assertEquals("Uncertainty", sourceWithLine.getTableColumnTitle(3)); + } + + public void testColumnTitleBand() { + assertEquals("Band", sourceWithLine.getTableColumnTitle(4)); + } + + public void testColumnTitleObserverCode() { + assertEquals("Observer Code", sourceWithLine.getTableColumnTitle(5)); + } + + public void testColumnTitleDiscrepant() { + assertEquals("Discrepant?", sourceWithLine.getTableColumnTitle(DISCREPANT_COLUMN)); + } + + public void testColumnTitleLineNum() { + assertEquals("Line", sourceWithLine.getTableColumnTitle(LINE_NUM_COLUMN)); + } + + // --- getTableColumnClass --- + + public void testColumnClassDefaultIsString() { + // Most columns are String. + assertEquals(String.class, sourceWithLine.getTableColumnClass(2)); // Magnitude + assertEquals(String.class, sourceWithLine.getTableColumnClass(4)); // Band + assertEquals(String.class, sourceWithLine.getTableColumnClass(5)); // Observer Code + } + + public void testColumnClassDiscrepantIsBoolean() { + assertEquals(Boolean.class, + sourceWithLine.getTableColumnClass(DISCREPANT_COLUMN)); + } + + public void testColumnClassLineNumIsInteger() { + assertEquals(Integer.class, + sourceWithLine.getTableColumnClass(LINE_NUM_COLUMN)); + } + + // --- getColumnNames --- + + public void testGetColumnNamesNotNull() { + Collection names = sourceWithLine.getColumnNames(); + assertNotNull(names); + } + + public void testGetColumnNamesContainsExpected() { + Collection names = sourceWithLine.getColumnNames(); + assertTrue(names.contains("Magnitude")); + assertTrue(names.contains("Band")); + assertTrue(names.contains("Observer Code")); + assertTrue(names.contains("Discrepant?")); + assertTrue(names.contains("Line")); + } + + // --- getColumnIndexByName --- + + public void testGetColumnIndexByNameMagnitude() { + assertEquals(2, sourceWithLine.getColumnIndexByName("Magnitude")); + } + + public void testGetColumnIndexByNameBand() { + assertEquals(4, sourceWithLine.getColumnIndexByName("Band")); + } + + public void testGetColumnIndexByNameDiscrepant() { + assertEquals(DISCREPANT_COLUMN, + sourceWithLine.getColumnIndexByName("Discrepant?")); + } + + public void testGetColumnIndexByNameNullThrows() { + try { + sourceWithLine.getColumnIndexByName(null); + fail("Expected IllegalArgumentException for null name"); + } catch (IllegalArgumentException e) { + // expected + } + } + + public void testGetColumnIndexByNameUnknownThrows() { + try { + sourceWithLine.getColumnIndexByName("NoSuchColumn"); + fail("Expected IllegalArgumentException for unknown name"); + } catch (IllegalArgumentException e) { + // expected + } + } + + // --- getDiscrepantColumnIndex --- + + public void testGetDiscrepantColumnIndex() { + assertEquals(DISCREPANT_COLUMN, sourceWithLine.getDiscrepantColumnIndex()); + } +} diff --git a/test/org/aavso/tools/vstar/ui/model/list/ValidObservationTableModelTest.java b/test/org/aavso/tools/vstar/ui/model/list/ValidObservationTableModelTest.java index 8c3ad49d5..95aea9038 100644 --- a/test/org/aavso/tools/vstar/ui/model/list/ValidObservationTableModelTest.java +++ b/test/org/aavso/tools/vstar/ui/model/list/ValidObservationTableModelTest.java @@ -174,4 +174,12 @@ public void testGetObservations() { assertTrue(result.contains(ob1)); assertTrue(result.contains(ob2)); } + + public void testGetColumnInfoSource() { + assertNotNull(model.getColumnInfoSource()); + } + + public void testGetObsInserter() { + assertNotNull(model.getObsInserter()); + } } diff --git a/test/org/aavso/tools/vstar/ui/model/plot/ObservationAndMeanPlotModelTest.java b/test/org/aavso/tools/vstar/ui/model/plot/ObservationAndMeanPlotModelTest.java new file mode 100644 index 000000000..9cb92aa26 --- /dev/null +++ b/test/org/aavso/tools/vstar/ui/model/plot/ObservationAndMeanPlotModelTest.java @@ -0,0 +1,178 @@ +/** + * VStar: a statistical analysis tool for variable star data. + * Copyright (C) 2009 AAVSO (http://www.aavso.org/) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.aavso.tools.vstar.ui.model.plot; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +import junit.framework.TestCase; + +import org.aavso.tools.vstar.data.Magnitude; +import org.aavso.tools.vstar.data.SeriesType; +import org.aavso.tools.vstar.data.ValidObservation; +import org.aavso.tools.vstar.ui.mediator.Mediator; +import org.aavso.tools.vstar.ui.mediator.NewStarType; +import org.aavso.tools.vstar.ui.mediator.StarInfo; +import org.aavso.tools.vstar.ui.mediator.message.NewStarMessage; +import org.aavso.tools.vstar.util.comparator.JDComparator; + +/** + * Unit tests for {@link ObservationAndMeanPlotModel} (which is the concrete + * subclass of the abstract {@link ObservationPlotModel}). + * + * Construction requires a live {@link Mediator} singleton with at least one + * {@link NewStarMessage} registered, because + * {@link ObservationPlotModel#isSeriesVisibleByDefault} calls + * {@code Mediator.getInstance().getLatestNewStarMessage()}. We satisfy this by + * directly adding a minimal message to the Mediator's list before each test and + * removing it afterwards. + * + * Part of issue #579 (GUI code coverage, prong D). + */ +public class ObservationAndMeanPlotModelTest extends TestCase { + + private static final double JD1 = 2451545.0; + private static final double JD2 = 2451565.0; + private static final double JD3 = 2451585.0; + private static final double MAG = 5.5; + private static final double ERR = 0.05; + + private ObservationAndMeanPlotModel model; + private List obsList; + + @Override + protected void setUp() { + Locale.setDefault(Locale.ENGLISH); + + // Build a few minimal observations. + obsList = new ArrayList(); + for (double jd : new double[]{JD1, JD2, JD3}) { + ValidObservation ob = new ValidObservation(); + ob.setJD(jd); + ob.setMagnitude(new Magnitude(MAG, ERR)); + ob.setBand(SeriesType.Unspecified); + obsList.add(ob); + } + + // Register a minimal NewStarMessage with Mediator so that + // isSeriesVisibleByDefault() does not throw a NullPointerException. + StarInfo starInfo = new StarInfo("Test Star", "TST0001"); + Map> categoryMap = + new HashMap>(); + categoryMap.put(SeriesType.Unspecified, obsList); + + NewStarMessage msg = new NewStarMessage( + NewStarType.NEW_STAR_FROM_DATABASE, + starInfo, obsList, categoryMap, + MAG - 1.0, MAG + 1.0, null); + + Mediator.getInstance().getNewStarMessageList().add(msg); + + // Build the obs-source map and construct the model. + Map> obsSourceListMap = + new HashMap>(); + obsSourceListMap.put(SeriesType.Unspecified, obsList); + + model = new ObservationAndMeanPlotModel( + obsSourceListMap, + JDCoordSource.instance, + new JDComparator(), + JDTimeElementEntity.instance, + null); + } + + @Override + protected void tearDown() { + // Remove the message we added so the singleton stays clean for other tests. + Mediator.getInstance().getNewStarMessageList().clear(); + } + + // --- Series structure --- + + public void testSeriesCountIncludesUnspecifiedAndMeans() { + // At minimum: Unspecified + MEANS series. + assertTrue("Expected at least 2 series; got " + model.getSeriesCount(), + model.getSeriesCount() >= 2); + } + + public void testUnspecifiedSeriesExists() { + assertTrue(model.seriesExists(SeriesType.Unspecified)); + } + + public void testMeansSeriesExists() { + assertTrue(model.seriesExists(SeriesType.MEANS)); + } + + // --- Item count --- + + public void testItemCountInUnspecifiedSeries() { + int seriesNum = model.getSrcTypeToSeriesNumMap().get(SeriesType.Unspecified); + assertEquals(obsList.size(), model.getItemCount(seriesNum)); + } + + // --- Coordinate retrieval --- + + public void testGetXReturnsJD() { + int seriesNum = model.getSrcTypeToSeriesNumMap().get(SeriesType.Unspecified); + // Observations are sorted by JD; item 0 should be JD1. + Number x = model.getX(seriesNum, 0); + assertNotNull(x); + assertEquals(JD1, x.doubleValue(), 1e-6); + } + + public void testGetYReturnsMagnitude() { + int seriesNum = model.getSrcTypeToSeriesNumMap().get(SeriesType.Unspecified); + Number y = model.getY(seriesNum, 0); + assertNotNull(y); + assertEquals(MAG, y.doubleValue(), 1e-6); + } + + // --- ValidObservation retrieval --- + + public void testGetValidObservationReturnsCorrectOb() { + int seriesNum = model.getSrcTypeToSeriesNumMap().get(SeriesType.Unspecified); + ValidObservation ob = model.getValidObservation(seriesNum, 0); + assertNotNull(ob); + assertEquals(JD1, ob.getJD(), 1e-6); + } + + // --- Error / uncertainty --- + + public void testGetMagErrorNonNegative() { + int seriesNum = model.getSrcTypeToSeriesNumMap().get(SeriesType.Unspecified); + double err = model.getMagError(seriesNum, 0); + assertTrue("Error should be non-negative", err >= 0.0); + } + + // --- Mean series number --- + + public void testMeansSeriesNumNotNegative() { + assertTrue("meansSeriesNum should be >= 0 after construction", + model.getMeansSeriesNum() >= 0); + } + + // --- Time element entity --- + + public void testTimeElementEntityIsJD() { + assertNotNull(model.getTimeElementEntity()); + assertTrue(model.getTimeElementEntity() instanceof JDTimeElementEntity); + } +} diff --git a/test/org/aavso/tools/vstar/ui/pane/list/ListSearchPaneTest.java b/test/org/aavso/tools/vstar/ui/pane/list/ListSearchPaneTest.java new file mode 100644 index 000000000..50dff59ff --- /dev/null +++ b/test/org/aavso/tools/vstar/ui/pane/list/ListSearchPaneTest.java @@ -0,0 +1,120 @@ +/** + * VStar: a statistical analysis tool for variable star data. + * Copyright (C) 2009 AAVSO (http://www.aavso.org/) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.aavso.tools.vstar.ui.pane.list; + +import java.util.Locale; + +import javax.swing.RowFilter; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableRowSorter; + +import junit.framework.TestCase; + +/** + * Pure unit tests for {@link ListSearchPane}. + * + * Uses a plain {@link DefaultTableModel} and {@link TableRowSorter} to drive + * the pane without any production model dependency. No display is required + * since {@code ListSearchPane} is a {@code JPanel} that only accesses the + * row sorter and model data structures. + * + * Part of issue #579 (prong C): GUI code coverage. + */ +public class ListSearchPaneTest extends TestCase { + + private DefaultTableModel tableModel; + private TableRowSorter rowSorter; + private ListSearchPane pane; + + @Override + protected void setUp() { + Locale.setDefault(Locale.ENGLISH); + + tableModel = new DefaultTableModel( + new Object[][] { + { "Alpha", "1.0" }, + { "Beta", "2.0" }, + { "Gamma", "3.0" } + }, + new String[] { "Name", "Value" }); + + rowSorter = new TableRowSorter(tableModel); + pane = new ListSearchPane(tableModel, rowSorter); + } + + public void testConstructionDoesNotThrow() { + assertNotNull(pane); + } + + public void testPaneIsNotNull() { + assertNotNull(pane); + } + + public void testDisableDoesNotThrow() { + pane.disable(); + } + + public void testEnableDoesNotThrow() { + pane.enable(); + } + + public void testDisableThenEnableDoesNotThrow() { + pane.disable(); + pane.enable(); + } + + public void testSetRowFilterNullDoesNotThrow() { + pane.setRowFilter(null); + } + + @SuppressWarnings("unchecked") + public void testSetRowFilterAppliesFilter() { + RowFilter filter = + RowFilter.regexFilter("Alpha"); + pane.setRowFilter(filter); + assertEquals(1, rowSorter.getViewRowCount()); + } + + public void testSetDefaultRowFilterDoesNotThrow() { + RowFilter customDefault = + RowFilter.regexFilter(".*"); + pane.setDefaultRowFilter(customDefault); + } + + public void testConstructionWithEmptyModel() { + DefaultTableModel emptyModel = new DefaultTableModel( + new Object[][] {}, + new String[] { "Col1", "Col2" }); + TableRowSorter sorter = + new TableRowSorter(emptyModel); + ListSearchPane emptyPane = + new ListSearchPane(emptyModel, sorter); + assertNotNull(emptyPane); + } + + public void testConstructionWithSingleColumnModel() { + DefaultTableModel singleCol = new DefaultTableModel( + new Object[][] { { "row1" }, { "row2" } }, + new String[] { "Only" }); + TableRowSorter sorter = + new TableRowSorter(singleCol); + ListSearchPane singlePane = + new ListSearchPane(singleCol, sorter); + assertNotNull(singlePane); + } +} diff --git a/test/org/aavso/tools/vstar/ui/pane/list/ObservationListPaneTest.java b/test/org/aavso/tools/vstar/ui/pane/list/ObservationListPaneTest.java new file mode 100644 index 000000000..882c4de31 --- /dev/null +++ b/test/org/aavso/tools/vstar/ui/pane/list/ObservationListPaneTest.java @@ -0,0 +1,174 @@ +/** + * VStar: a statistical analysis tool for variable star data. + * Copyright (C) 2009 AAVSO (http://www.aavso.org/) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.aavso.tools.vstar.ui.pane.list; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; + +import javax.swing.JTable; + +import org.aavso.tools.vstar.data.InvalidObservation; +import org.aavso.tools.vstar.data.Magnitude; +import org.aavso.tools.vstar.data.SeriesType; +import org.aavso.tools.vstar.data.ValidObservation; +import org.aavso.tools.vstar.ui.mediator.AnalysisType; +import org.aavso.tools.vstar.ui.model.list.InvalidObservationTableModel; +import org.aavso.tools.vstar.ui.model.list.SimpleFormatRawDataColumnInfoSource; +import org.aavso.tools.vstar.ui.model.list.ValidObservationTableModel; + +import junit.framework.TestCase; + +/** + * Pure unit tests for {@link ObservationListPane}. + * + * Construction is safe headlessly: the constructor uses + * {@code Mediator.getInstance()} (lazy singleton) and creates a plain + * {@code JPanel}, so no {@code setVisible} or {@code Mediator.getUI()} call is + * needed. + * + * Part of issue #579 (prong C): GUI code coverage. + */ +public class ObservationListPaneTest extends TestCase { + + private static final double JD1 = 2451545.0; + private static final double JD2 = 2451546.0; + private static final double MAG = 5.5; + private static final double UNCERTAINTY = 0.01; + + private ValidObservation ob1; + private ValidObservation ob2; + private List observations; + private ValidObservationTableModel validModel; + private Set visibleSeries; + + @Override + protected void setUp() { + Locale.setDefault(Locale.ENGLISH); + + ob1 = new ValidObservation(); + ob1.setJD(JD1); + ob1.setMagnitude(new Magnitude(MAG, UNCERTAINTY)); + ob1.setBand(SeriesType.Visual); + + ob2 = new ValidObservation(); + ob2.setJD(JD2); + ob2.setMagnitude(new Magnitude(6.0, 0.02)); + ob2.setBand(SeriesType.Visual); + + observations = new ArrayList(Arrays.asList(ob1, ob2)); + + Map> obsMap = + new HashMap>(); + obsMap.put(SeriesType.Visual, observations); + + validModel = new ValidObservationTableModel(obsMap, observations, + new SimpleFormatRawDataColumnInfoSource()); + + visibleSeries = new HashSet(Arrays.asList(SeriesType.Visual)); + } + + public void testConstructionWithValidDataOnly() { + ObservationListPane pane = new ObservationListPane( + "Test", validModel, null, true, visibleSeries, + AnalysisType.RAW_DATA); + assertNotNull(pane); + } + + public void testGetValidDataTableIsNotNull() { + ObservationListPane pane = new ObservationListPane( + "Test", validModel, null, true, visibleSeries, + AnalysisType.RAW_DATA); + JTable table = pane.getValidDataTable(); + assertNotNull(table); + } + + public void testGetInvalidDataTableIsNullWhenNotProvided() { + ObservationListPane pane = new ObservationListPane( + "Test", validModel, null, true, visibleSeries, + AnalysisType.RAW_DATA); + assertNull(pane.getInvalidDataTable()); + } + + public void testValidTableModelRowCountMatchesObservations() { + ObservationListPane pane = new ObservationListPane( + "Test", validModel, null, true, visibleSeries, + AnalysisType.RAW_DATA); + assertEquals(2, pane.getValidDataTable().getModel().getRowCount()); + } + + public void testGetLastObSelectedIsNullInitially() { + ObservationListPane pane = new ObservationListPane( + "Test", validModel, null, true, visibleSeries, + AnalysisType.RAW_DATA); + assertNull(pane.getLastObSelected()); + } + + public void testConstructionWithInvalidDataModel() { + List invalidObs = new ArrayList(); + invalidObs.add(new InvalidObservation("bad line", "parse error")); + InvalidObservationTableModel invalidModel = + new InvalidObservationTableModel(invalidObs); + + ObservationListPane pane = new ObservationListPane( + "Test", validModel, invalidModel, false, visibleSeries, + AnalysisType.RAW_DATA); + assertNotNull(pane); + assertNotNull(pane.getInvalidDataTable()); + } + + public void testGetInvalidDataTableNotNullWhenProvided() { + List invalidObs = new ArrayList(); + invalidObs.add(new InvalidObservation("bad line", "parse error")); + InvalidObservationTableModel invalidModel = + new InvalidObservationTableModel(invalidObs); + + ObservationListPane pane = new ObservationListPane( + "Test", validModel, invalidModel, false, visibleSeries, + AnalysisType.RAW_DATA); + assertEquals(1, pane.getInvalidDataTable().getModel().getRowCount()); + } + + public void testConstructionWithEmptyVisibleSeries() { + Set empty = new HashSet(); + ObservationListPane pane = new ObservationListPane( + "Test", validModel, null, true, empty, + AnalysisType.RAW_DATA); + assertNotNull(pane); + assertNotNull(pane.getValidDataTable()); + } + + public void testAutoResizeFalseDoesNotThrow() { + ObservationListPane pane = new ObservationListPane( + "Test", validModel, null, false, visibleSeries, + AnalysisType.RAW_DATA); + assertNotNull(pane.getValidDataTable()); + } + + public void testPhasePlotAnalysisTypeDoesNotThrow() { + ObservationListPane pane = new ObservationListPane( + "Test", validModel, null, true, visibleSeries, + AnalysisType.PHASE_PLOT); + assertNotNull(pane); + } +} diff --git a/test/org/aavso/tools/vstar/ui/pane/list/SyntheticObservationListPaneTest.java b/test/org/aavso/tools/vstar/ui/pane/list/SyntheticObservationListPaneTest.java new file mode 100644 index 000000000..a0d136038 --- /dev/null +++ b/test/org/aavso/tools/vstar/ui/pane/list/SyntheticObservationListPaneTest.java @@ -0,0 +1,127 @@ +/** + * VStar: a statistical analysis tool for variable star data. + * Copyright (C) 2009 AAVSO (http://www.aavso.org/) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ +package org.aavso.tools.vstar.ui.pane.list; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Locale; + +import javax.swing.JTable; + +import org.aavso.tools.vstar.data.DateInfo; +import org.aavso.tools.vstar.data.Magnitude; +import org.aavso.tools.vstar.data.ValidObservation; +import org.aavso.tools.vstar.ui.model.list.RawDataMeanObservationTableModel; + +import junit.framework.TestCase; + +/** + * Pure unit tests for {@link SyntheticObservationListPane}. + * + * Uses {@link RawDataMeanObservationTableModel} as the concrete synthetic + * table model type. Construction only calls {@code Mediator.getInstance()} + * (safe) and creates a plain {@code JPanel}, so no display is needed. + * + * Part of issue #579 (prong C): GUI code coverage. + */ +public class SyntheticObservationListPaneTest extends TestCase { + + private ValidObservation ob1; + private ValidObservation ob2; + private List observations; + private RawDataMeanObservationTableModel model; + + @Override + protected void setUp() { + Locale.setDefault(Locale.ENGLISH); + + ob1 = new ValidObservation(); + ob1.setDateInfo(new DateInfo(2451545.0)); + ob1.setMagnitude(new Magnitude(5.5, 0.01)); + + ob2 = new ValidObservation(); + ob2.setDateInfo(new DateInfo(2451546.0)); + ob2.setMagnitude(new Magnitude(6.0, 0.02)); + + observations = new ArrayList(Arrays.asList(ob1, ob2)); + model = new RawDataMeanObservationTableModel(observations); + } + + public void testConstructionDoesNotThrow() { + SyntheticObservationListPane pane = + new SyntheticObservationListPane( + model, "Mean observations"); + assertNotNull(pane); + } + + public void testConstructionWithNullSummaryDoesNotThrow() { + SyntheticObservationListPane pane = + new SyntheticObservationListPane( + model, null); + assertNotNull(pane); + } + + public void testGetObsTableModelReturnsSameInstance() { + SyntheticObservationListPane pane = + new SyntheticObservationListPane( + model, "Mean observations"); + assertSame(model, pane.getObsTableModel()); + } + + public void testGetObsTableIsNotNull() { + SyntheticObservationListPane pane = + new SyntheticObservationListPane( + model, "Mean observations"); + JTable table = pane.getObsTable(); + assertNotNull(table); + } + + public void testObsTableRowCountMatchesObservations() { + SyntheticObservationListPane pane = + new SyntheticObservationListPane( + model, "Mean observations"); + assertEquals(2, pane.getObsTable().getModel().getRowCount()); + } + + public void testGetLastObSelectedIsNullInitially() { + SyntheticObservationListPane pane = + new SyntheticObservationListPane( + model, "Mean observations"); + assertNull(pane.getLastObSelected()); + } + + public void testConstructionWithEmptyObservations() { + RawDataMeanObservationTableModel emptyModel = + new RawDataMeanObservationTableModel( + new ArrayList()); + SyntheticObservationListPane pane = + new SyntheticObservationListPane( + emptyModel, "Empty"); + assertNotNull(pane); + assertEquals(0, pane.getObsTable().getModel().getRowCount()); + } + + public void testObsTableModelMatchesExpectedRowCount() { + SyntheticObservationListPane pane = + new SyntheticObservationListPane( + model, "Mean observations"); + assertEquals(model.getRowCount(), + pane.getObsTable().getModel().getRowCount()); + } +}