diff --git a/.github/workflows/snapshot-release.yml b/.github/workflows/snapshot-release.yml index b4103ae3..e1e0e69b 100644 --- a/.github/workflows/snapshot-release.yml +++ b/.github/workflows/snapshot-release.yml @@ -82,7 +82,7 @@ jobs: - name: Deploy plugins to gh-pages (snapshot) run: | mkdir -p _site/plugins/snapshot - unzip -q plugin/vstar-plugins.zip -d _site/plugins/snapshot/ + unzip -o -q plugin/vstar-plugins.zip -d _site/plugins/snapshot/ - name: Commit and push to gh-pages working-directory: _site run: | diff --git a/src/org/aavso/tools/vstar/ui/dialog/DiscrepantReportDialog.java b/src/org/aavso/tools/vstar/ui/dialog/DiscrepantReportDialog.java index 2c20c591..0a99d3e9 100644 --- a/src/org/aavso/tools/vstar/ui/dialog/DiscrepantReportDialog.java +++ b/src/org/aavso/tools/vstar/ui/dialog/DiscrepantReportDialog.java @@ -58,6 +58,15 @@ public class DiscrepantReportDialog extends AbstractOkCancelDialog { * The observation to be reported as discrepant. */ public DiscrepantReportDialog(String auid, ValidObservation ob) { + this(auid, ob, true); + } + + /** + * Package-private constructor that optionally suppresses display. + * Pass {@code show=false} to build without calling + * {@code Mediator.getUI()} or {@code setVisible(true)}. + */ + DiscrepantReportDialog(String auid, ValidObservation ob, boolean show) { super("AAVSO Discrepant Report"); this.auid = auid; this.name = ob.getName(); @@ -84,8 +93,10 @@ public DiscrepantReportDialog(String auid, ValidObservation ob) { contentPane.add(topPane); this.pack(); - setLocationRelativeTo(Mediator.getUI().getContentPane()); - this.setVisible(true); + if (show) { + setLocationRelativeTo(Mediator.getUI().getContentPane()); + this.setVisible(true); + } } public String getComments() { diff --git a/src/org/aavso/tools/vstar/ui/dialog/PolynomialDegreeDialog.java b/src/org/aavso/tools/vstar/ui/dialog/PolynomialDegreeDialog.java index 8249a01b..f933720a 100644 --- a/src/org/aavso/tools/vstar/ui/dialog/PolynomialDegreeDialog.java +++ b/src/org/aavso/tools/vstar/ui/dialog/PolynomialDegreeDialog.java @@ -51,6 +51,15 @@ public class PolynomialDegreeDialog extends AbstractOkCancelDialog implements * The maximum degree value. */ public PolynomialDegreeDialog(int minDegree, int maxDegree) { + this(minDegree, maxDegree, true); + } + + /** + * Package-private constructor that optionally suppresses display. + * Pass {@code show=false} to build without calling + * {@code Mediator.getUI()} or {@code setVisible(true)}. + */ + PolynomialDegreeDialog(int minDegree, int maxDegree, boolean show) { super(LocaleProps.get("POLYNOMIAL_DEGREE_DLG_TITLE")); degree = (maxDegree - minDegree) / 2; @@ -69,8 +78,10 @@ public PolynomialDegreeDialog(int minDegree, int maxDegree) { contentPane.add(topPane); this.pack(); - setLocationRelativeTo(Mediator.getUI().getContentPane()); - this.setVisible(true); + if (show) { + setLocationRelativeTo(Mediator.getUI().getContentPane()); + this.setVisible(true); + } } /** diff --git a/src/org/aavso/tools/vstar/ui/dialog/RadioButtonDialog.java b/src/org/aavso/tools/vstar/ui/dialog/RadioButtonDialog.java index f57c3522..e14e455d 100644 --- a/src/org/aavso/tools/vstar/ui/dialog/RadioButtonDialog.java +++ b/src/org/aavso/tools/vstar/ui/dialog/RadioButtonDialog.java @@ -55,6 +55,16 @@ public class RadioButtonDialog extends AbstractOkCancelDialog implements ActionL */ public RadioButtonDialog(String title, Collection options, String initialOption) { + this(title, options, initialOption, true); + } + + /** + * Package-private constructor that optionally suppresses display. + * Pass {@code show=false} to build without calling + * {@code Mediator.getUI()} or {@code setVisible(true)}. + */ + RadioButtonDialog(String title, Collection options, + String initialOption, boolean show) { super(title); this.options = options; @@ -75,8 +85,10 @@ public RadioButtonDialog(String title, Collection options, contentPane.add(topPane); this.pack(); - setLocationRelativeTo(Mediator.getUI().getContentPane()); - this.setVisible(true); + if (show) { + setLocationRelativeTo(Mediator.getUI().getContentPane()); + this.setVisible(true); + } } /** diff --git a/test/AllTests.java b/test/AllTests.java index 9f86933c..080aeac6 100644 --- a/test/AllTests.java +++ b/test/AllTests.java @@ -59,8 +59,14 @@ import org.aavso.tools.vstar.ui.dialog.AboutBoxTest; import org.aavso.tools.vstar.ui.dialog.AbstractOkCancelDialogTest; 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.MultiEntryComponentDialogTest; +import org.aavso.tools.vstar.ui.dialog.PeriodAnalysisPluginDialogsTest; +import org.aavso.tools.vstar.ui.dialog.PhaseParameterDialogTest; +import org.aavso.tools.vstar.ui.dialog.PolynomialDegreeDialogTest; +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.model.list.AbstractSyntheticObservationTableModelTest; import org.aavso.tools.vstar.ui.model.list.PeriodAnalysisDataTableModelTest; @@ -140,6 +146,12 @@ public static Test suite() { suite.addTestSuite(AboutBoxTest.class); suite.addTestSuite(DoubleFieldTest.class); suite.addTestSuite(MultiEntryComponentDialogTest.class); + suite.addTestSuite(PolynomialDegreeDialogTest.class); + suite.addTestSuite(RadioButtonDialogTest.class); + suite.addTestSuite(DiscrepantReportDialogTest.class); + suite.addTestSuite(PhaseParameterDialogTest.class); + suite.addTestSuite(SeriesTypeCreationDialogTest.class); + suite.addTestSuite(PeriodAnalysisPluginDialogsTest.class); // $JUnit-END$ return suite; diff --git a/test/org/aavso/tools/vstar/ui/dialog/DiscrepantReportDialogTest.java b/test/org/aavso/tools/vstar/ui/dialog/DiscrepantReportDialogTest.java new file mode 100644 index 00000000..a150cf18 --- /dev/null +++ b/test/org/aavso/tools/vstar/ui/dialog/DiscrepantReportDialogTest.java @@ -0,0 +1,100 @@ +/** + * 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.Locale; + +import junit.framework.TestCase; + +import org.aavso.tools.vstar.data.Magnitude; +import org.aavso.tools.vstar.data.ValidObservation; + +/** + * Tests for {@link DiscrepantReportDialog}. + * + * Uses the package-private 3-argument constructor (show=false) to build the + * dialog without displaying it, avoiding the {@code Mediator.getUI()} call and + * the blocking {@code setVisible(true)}. + * + * Part of issue #579 (GUI code coverage). + */ +public class DiscrepantReportDialogTest extends TestCase { + + private ValidObservation ob; + + @Override + protected void setUp() { + Locale.setDefault(Locale.ENGLISH); + ob = new ValidObservation(); + ob.setName("R Car"); + ob.setJD(2458000.5); + ob.setMagnitude(new Magnitude(7.8, 0.1)); + } + + public void testConstruction() { + DiscrepantReportDialog d = new DiscrepantReportDialog("123-CVF", ob, false); + try { + assertNotNull(d); + } finally { + d.dispose(); + } + } + + public void testTitle() { + DiscrepantReportDialog d = new DiscrepantReportDialog("123-CVF", ob, false); + try { + assertEquals("AAVSO Discrepant Report", d.getTitle()); + } finally { + d.dispose(); + } + } + + public void testIsModal() { + DiscrepantReportDialog d = new DiscrepantReportDialog("123-CVF", ob, false); + try { + assertTrue(d.isModal()); + } finally { + d.dispose(); + } + } + + public void testIsCancelledByDefault() { + DiscrepantReportDialog d = new DiscrepantReportDialog("123-CVF", ob, false); + try { + assertTrue(d.isCancelled()); + } finally { + d.dispose(); + } + } + + public void testInitialCommentsAreEmpty() { + DiscrepantReportDialog d = new DiscrepantReportDialog("123-CVF", ob, false); + try { + assertEquals("", d.getComments()); + } finally { + d.dispose(); + } + } + + public void testCancelActionLeavesDialogCancelled() { + DiscrepantReportDialog d = new DiscrepantReportDialog("123-CVF", ob, false); + d.cancelAction(); + assertTrue(d.isCancelled()); + d.dispose(); + } +} diff --git a/test/org/aavso/tools/vstar/ui/dialog/PeriodAnalysisPluginDialogsTest.java b/test/org/aavso/tools/vstar/ui/dialog/PeriodAnalysisPluginDialogsTest.java new file mode 100644 index 00000000..c390aa35 --- /dev/null +++ b/test/org/aavso/tools/vstar/ui/dialog/PeriodAnalysisPluginDialogsTest.java @@ -0,0 +1,236 @@ +/** + * 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.Arrays; +import java.util.List; +import java.util.Locale; +import java.util.Optional; + +import junit.framework.TestCase; + +/** + * Tests for the {@link MultiEntryComponentDialog} configurations created by + * the period-analysis plugins (Workstream B of issue #579). + * + * Because {@link MultiEntryComponentDialog}'s public constructors show the + * dialog, tests use the package-private 5-argument constructor (show=false). + * These tests live in the same package ({@code org.aavso.tools.vstar.ui.dialog}) + * to access that constructor. + * + * Each inner test group replicates the exact field setup from one plugin's + * {@code createParamDialog()} / {@code executeAlgorithm()} method, verifying + * field names, default values and range bounds. + */ +public class PeriodAnalysisPluginDialogsTest extends TestCase { + + @Override + protected void setUp() { + Locale.setDefault(Locale.ENGLISH); + } + + private MultiEntryComponentDialog build(String title, List> fields) { + return new MultiEntryComponentDialog(title, null, fields, Optional.empty(), false); + } + + // ----------------------------------------------------------------------- + // DcDftFrequencyRangePeriodAnalysisPlugin + // ----------------------------------------------------------------------- + + public void testDcDftFrequencyRangeDialogConstruction() { + DoubleField loFreq = new DoubleField("Low Frequency", 0.0, null, 0.01); + DoubleField hiFreq = new DoubleField("High Frequency", 0.0, null, 10.0); + DoubleField resolution = new DoubleField("Resolution", 0.0, null, 0.1); + + List> fields = Arrays.asList( + (ITextComponent) loFreq, + (ITextComponent) hiFreq, + (ITextComponent) resolution); + + MultiEntryComponentDialog d = build("Parameters", fields); + try { + assertEquals("Parameters", d.getTitle()); + assertTrue(d.isCancelled()); + assertTrue(d.isModal()); + + assertEquals("Low Frequency", loFreq.getName()); + assertEquals(0.0, loFreq.getMin(), 0.0); + assertNull(loFreq.getMax()); + assertEquals(0.01, loFreq.getValue(), 0.0); + + assertEquals("High Frequency", hiFreq.getName()); + assertEquals(0.0, hiFreq.getMin(), 0.0); + assertNull(hiFreq.getMax()); + assertEquals(10.0, hiFreq.getValue(), 0.0); + + assertEquals("Resolution", resolution.getName()); + assertEquals(0.0, resolution.getMin(), 0.0); + assertNull(resolution.getMax()); + assertEquals(0.1, resolution.getValue(), 0.0); + } finally { + d.dispose(); + } + } + + public void testDcDftFrequencyRangeFieldCount() { + DoubleField loFreq = new DoubleField("Low Frequency", 0.0, null, 0.01); + DoubleField hiFreq = new DoubleField("High Frequency", 0.0, null, 10.0); + DoubleField resolution = new DoubleField("Resolution", 0.0, null, 0.1); + + List> fields = Arrays.asList( + (ITextComponent) loFreq, + (ITextComponent) hiFreq, + (ITextComponent) resolution); + + MultiEntryComponentDialog d = build("Parameters", fields); + try { + assertEquals(3, fields.size()); + } finally { + d.dispose(); + } + } + + // ----------------------------------------------------------------------- + // DcDftPeriodRangePeriodAnalysisPlugin + // ----------------------------------------------------------------------- + + public void testDcDftPeriodRangeDialogConstruction() { + DoubleField loPeriod = new DoubleField("Low Period", 0.0, null, 1.0); + DoubleField hiPeriod = new DoubleField("High Period", 0.0, null, 100.0); + DoubleField resolution = new DoubleField("Resolution", 0.0, null, 0.1); + + List> fields = Arrays.asList( + (ITextComponent) loPeriod, + (ITextComponent) hiPeriod, + (ITextComponent) resolution); + + MultiEntryComponentDialog d = build("Parameters", fields); + try { + assertEquals("Parameters", d.getTitle()); + assertTrue(d.isCancelled()); + + assertEquals("Low Period", loPeriod.getName()); + assertEquals(0.0, loPeriod.getMin(), 0.0); + assertNull(loPeriod.getMax()); + assertEquals(1.0, loPeriod.getValue(), 0.0); + + assertEquals("High Period", hiPeriod.getName()); + assertEquals(0.0, hiPeriod.getMin(), 0.0); + assertNull(hiPeriod.getMax()); + assertEquals(100.0, hiPeriod.getValue(), 0.0); + + assertEquals("Resolution", resolution.getName()); + assertEquals(0.0, resolution.getMin(), 0.0); + assertNull(resolution.getMax()); + } finally { + d.dispose(); + } + } + + // ----------------------------------------------------------------------- + // WeightedWaveletZTransformWithPeriodRangePlugin + // ----------------------------------------------------------------------- + + public void testWWZPeriodRangeDialogConstruction() { + DoubleField minPeriod = new DoubleField("Minimum Period", 0.0, null, 1.0); + DoubleField maxPeriod = new DoubleField("Maximum Period", 0.0, null, 100.0); + DoubleField deltaPeriod = new DoubleField("Period Step", null, null, 0.5); + DoubleField decay = new DoubleField("Decay", null, null, 0.001); + DoubleField timeDivisions = new DoubleField("Time Divisions", null, null, 50.0); + + List> fields = Arrays.asList( + (ITextComponent) minPeriod, + (ITextComponent) maxPeriod, + (ITextComponent) deltaPeriod, + (ITextComponent) decay, + (ITextComponent) timeDivisions); + + MultiEntryComponentDialog d = build("WWZ Parameters", fields); + try { + assertEquals("WWZ Parameters", d.getTitle()); + assertTrue(d.isCancelled()); + assertEquals(5, fields.size()); + + assertEquals("Minimum Period", minPeriod.getName()); + assertEquals(0.0, minPeriod.getMin(), 0.0); + assertNull(minPeriod.getMax()); + + assertEquals("Maximum Period", maxPeriod.getName()); + assertEquals(0.0, maxPeriod.getMin(), 0.0); + assertNull(maxPeriod.getMax()); + + assertEquals("Period Step", deltaPeriod.getName()); + assertNull(deltaPeriod.getMin()); + assertNull(deltaPeriod.getMax()); + + assertEquals("Decay", decay.getName()); + assertEquals(0.001, decay.getValue(), 0.0); + + assertEquals("Time Divisions", timeDivisions.getName()); + assertEquals(50.0, timeDivisions.getValue(), 0.0); + } finally { + d.dispose(); + } + } + + // ----------------------------------------------------------------------- + // WeightedWaveletZTransformWithFrequencyRangePlugin + // ----------------------------------------------------------------------- + + public void testWWZFrequencyRangeDialogConstruction() { + DoubleField minFreq = new DoubleField("Minimum Frequency", 0.0, null, 0.01); + DoubleField maxFreq = new DoubleField("Maximum Frequency", 0.0, null, 10.0); + DoubleField deltaFreq = new DoubleField("Frequency Step", null, null, 0.05); + DoubleField decay = new DoubleField("Decay", null, null, 0.001); + DoubleField timeDivisions = new DoubleField("Time Divisions", null, null, 50.0); + + List> fields = Arrays.asList( + (ITextComponent) minFreq, + (ITextComponent) maxFreq, + (ITextComponent) deltaFreq, + (ITextComponent) decay, + (ITextComponent) timeDivisions); + + MultiEntryComponentDialog d = build("WWZ Parameters", fields); + try { + assertEquals("WWZ Parameters", d.getTitle()); + assertTrue(d.isCancelled()); + assertEquals(5, fields.size()); + + assertEquals("Minimum Frequency", minFreq.getName()); + assertEquals(0.0, minFreq.getMin(), 0.0); + assertNull(minFreq.getMax()); + + assertEquals("Maximum Frequency", maxFreq.getName()); + assertEquals(0.0, maxFreq.getMin(), 0.0); + assertNull(maxFreq.getMax()); + + assertEquals("Frequency Step", deltaFreq.getName()); + assertNull(deltaFreq.getMin()); + assertNull(deltaFreq.getMax()); + + assertEquals("Decay", decay.getName()); + assertEquals(0.001, decay.getValue(), 0.0); + + assertEquals("Time Divisions", timeDivisions.getName()); + assertEquals(50.0, timeDivisions.getValue(), 0.0); + } finally { + d.dispose(); + } + } +} diff --git a/test/org/aavso/tools/vstar/ui/dialog/PhaseParameterDialogTest.java b/test/org/aavso/tools/vstar/ui/dialog/PhaseParameterDialogTest.java new file mode 100644 index 00000000..19a8a242 --- /dev/null +++ b/test/org/aavso/tools/vstar/ui/dialog/PhaseParameterDialogTest.java @@ -0,0 +1,107 @@ +/** + * 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.Locale; + +import junit.framework.TestCase; + +/** + * Tests for {@link PhaseParameterDialog}. + * + * The {@link PhaseParameterDialog} constructor does NOT call + * {@code Mediator.getUI()} — that call is deferred to {@code showDialog()}. + * Therefore the dialog can be constructed in a headless test without any + * special constructor variant. + * + * Part of issue #579 (GUI code coverage). + */ +public class PhaseParameterDialogTest extends TestCase { + + @Override + protected void setUp() { + Locale.setDefault(Locale.ENGLISH); + } + + public void testConstruction() { + PhaseParameterDialog d = new PhaseParameterDialog(); + try { + assertNotNull(d); + } finally { + d.dispose(); + } + } + + public void testTitle() { + PhaseParameterDialog d = new PhaseParameterDialog(); + try { + assertEquals("Phase Plot", d.getTitle()); + } finally { + d.dispose(); + } + } + + public void testIsModal() { + PhaseParameterDialog d = new PhaseParameterDialog(); + try { + assertTrue(d.isModal()); + } finally { + d.dispose(); + } + } + + public void testInitialPeriodIsZero() { + PhaseParameterDialog d = new PhaseParameterDialog(); + try { + assertEquals(0.0, d.getPeriod(), 0.0); + } finally { + d.dispose(); + } + } + + public void testInitialEpochIsZero() { + PhaseParameterDialog d = new PhaseParameterDialog(); + try { + assertEquals(0.0, d.getEpoch(), 0.0); + } finally { + d.dispose(); + } + } + + public void testSetPeriodField() { + PhaseParameterDialog d = new PhaseParameterDialog(); + try { + d.setPeriodField(3.14); + // period field set to text; the numeric value is only updated by okAction + assertEquals(0.0, d.getPeriod(), 0.0); + } finally { + d.dispose(); + } + } + + public void testSetEpochField() { + PhaseParameterDialog d = new PhaseParameterDialog(); + try { + d.setEpochField(2450000.0); + // epoch field set to text; the numeric value is only updated by okAction + assertEquals(0.0, d.getEpoch(), 0.0); + } finally { + d.dispose(); + } + } +} diff --git a/test/org/aavso/tools/vstar/ui/dialog/PolynomialDegreeDialogTest.java b/test/org/aavso/tools/vstar/ui/dialog/PolynomialDegreeDialogTest.java new file mode 100644 index 00000000..232f4c37 --- /dev/null +++ b/test/org/aavso/tools/vstar/ui/dialog/PolynomialDegreeDialogTest.java @@ -0,0 +1,107 @@ +/** + * 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.Locale; + +import junit.framework.TestCase; + +/** + * Tests for {@link PolynomialDegreeDialog}. + * + * Uses the package-private 3-argument constructor (show=false) to build the + * dialog without displaying it, avoiding the {@code Mediator.getUI()} call and + * the blocking {@code setVisible(true)}. + * + * Part of issue #579 (GUI code coverage). + */ +public class PolynomialDegreeDialogTest extends TestCase { + + @Override + protected void setUp() { + Locale.setDefault(Locale.ENGLISH); + } + + public void testConstruction() { + PolynomialDegreeDialog d = new PolynomialDegreeDialog(1, 10, false); + try { + assertNotNull(d); + } finally { + d.dispose(); + } + } + + public void testTitle() { + PolynomialDegreeDialog d = new PolynomialDegreeDialog(1, 10, false); + try { + assertEquals("Polynomial Degree", d.getTitle()); + } finally { + d.dispose(); + } + } + + public void testIsModal() { + PolynomialDegreeDialog d = new PolynomialDegreeDialog(1, 10, false); + try { + assertTrue(d.isModal()); + } finally { + d.dispose(); + } + } + + public void testIsCancelledByDefault() { + PolynomialDegreeDialog d = new PolynomialDegreeDialog(1, 10, false); + try { + assertTrue(d.isCancelled()); + } finally { + d.dispose(); + } + } + + public void testInitialDegreeIsHalfRange() { + PolynomialDegreeDialog d = new PolynomialDegreeDialog(0, 10, false); + try { + assertEquals(5, d.getDegree()); + } finally { + d.dispose(); + } + } + + public void testInitialDegreeWithMinOne() { + PolynomialDegreeDialog d = new PolynomialDegreeDialog(1, 11, false); + try { + assertEquals(5, d.getDegree()); + } finally { + d.dispose(); + } + } + + public void testOkActionClearsCancelledFlag() { + PolynomialDegreeDialog d = new PolynomialDegreeDialog(1, 10, false); + assertTrue(d.isCancelled()); + d.okAction(); + assertFalse(d.isCancelled()); + } + + public void testCancelActionLeavesDialogCancelled() { + PolynomialDegreeDialog d = new PolynomialDegreeDialog(1, 10, false); + d.cancelAction(); + assertTrue(d.isCancelled()); + d.dispose(); + } +} diff --git a/test/org/aavso/tools/vstar/ui/dialog/RadioButtonDialogTest.java b/test/org/aavso/tools/vstar/ui/dialog/RadioButtonDialogTest.java new file mode 100644 index 00000000..01961192 --- /dev/null +++ b/test/org/aavso/tools/vstar/ui/dialog/RadioButtonDialogTest.java @@ -0,0 +1,123 @@ +/** + * 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.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.Locale; + +import junit.framework.TestCase; + +/** + * Tests for {@link RadioButtonDialog}. + * + * Uses the package-private 4-argument constructor (show=false) to build the + * dialog without displaying it, avoiding the {@code Mediator.getUI()} call and + * the blocking {@code setVisible(true)}. + * + * Part of issue #579 (GUI code coverage). + */ +public class RadioButtonDialogTest extends TestCase { + + @Override + protected void setUp() { + Locale.setDefault(Locale.ENGLISH); + } + + private static Collection options(String... vals) { + return new LinkedHashSet(Arrays.asList(vals)); + } + + public void testConstruction() { + Collection opts = options("Alpha", "Beta", "Gamma"); + RadioButtonDialog d = new RadioButtonDialog("Choose", opts, "Alpha", false); + try { + assertNotNull(d); + } finally { + d.dispose(); + } + } + + public void testTitle() { + Collection opts = options("A", "B"); + RadioButtonDialog d = new RadioButtonDialog("Pick One", opts, "A", false); + try { + assertEquals("Pick One", d.getTitle()); + } finally { + d.dispose(); + } + } + + public void testIsModal() { + Collection opts = options("X", "Y"); + RadioButtonDialog d = new RadioButtonDialog("T", opts, "X", false); + try { + assertTrue(d.isModal()); + } finally { + d.dispose(); + } + } + + public void testIsCancelledByDefault() { + Collection opts = options("Red", "Blue"); + RadioButtonDialog d = new RadioButtonDialog("Color", opts, "Red", false); + try { + assertTrue(d.isCancelled()); + } finally { + d.dispose(); + } + } + + public void testInitialOptionIsSelectedOption() { + Collection opts = options("Red", "Blue", "Green"); + RadioButtonDialog d = new RadioButtonDialog("Color", opts, "Blue", false); + try { + assertEquals("Blue", d.getSelectedOption()); + } finally { + d.dispose(); + } + } + + public void testOkActionClearsCancelledFlag() { + Collection opts = options("Yes", "No"); + RadioButtonDialog d = new RadioButtonDialog("Confirm", opts, "Yes", false); + assertTrue(d.isCancelled()); + d.okAction(); + assertFalse(d.isCancelled()); + } + + public void testCancelActionLeavesDialogCancelled() { + Collection opts = options("Yes", "No"); + RadioButtonDialog d = new RadioButtonDialog("Confirm", opts, "Yes", false); + d.cancelAction(); + assertTrue(d.isCancelled()); + d.dispose(); + } + + public void testSingleOptionConstruction() { + Collection opts = Collections.singleton("Only"); + RadioButtonDialog d = new RadioButtonDialog("Solo", opts, "Only", false); + try { + assertEquals("Only", d.getSelectedOption()); + } finally { + d.dispose(); + } + } +} diff --git a/test/org/aavso/tools/vstar/ui/dialog/SeriesTypeCreationDialogTest.java b/test/org/aavso/tools/vstar/ui/dialog/SeriesTypeCreationDialogTest.java new file mode 100644 index 00000000..eb58f4ac --- /dev/null +++ b/test/org/aavso/tools/vstar/ui/dialog/SeriesTypeCreationDialogTest.java @@ -0,0 +1,90 @@ +/** + * 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.ArrayList; +import java.util.List; +import java.util.Locale; + +import junit.framework.TestCase; + +import org.aavso.tools.vstar.data.ValidObservation; + +/** + * Tests for {@link SeriesTypeCreationDialog}. + * + * The {@link SeriesTypeCreationDialog} constructor does NOT call + * {@code Mediator.getUI()} or {@code setVisible(true)} — it only calls + * {@code pack()}. Therefore it can be constructed in a headless test without + * any special constructor variant. + * + * Part of issue #579 (GUI code coverage). + */ +public class SeriesTypeCreationDialogTest extends TestCase { + + private List emptyObs; + + @Override + protected void setUp() { + Locale.setDefault(Locale.ENGLISH); + emptyObs = new ArrayList(); + } + + public void testConstruction() { + SeriesTypeCreationDialog d = new SeriesTypeCreationDialog(emptyObs); + try { + assertNotNull(d); + } finally { + d.dispose(); + } + } + + public void testTitle() { + SeriesTypeCreationDialog d = new SeriesTypeCreationDialog(emptyObs); + try { + assertEquals("Create Series", d.getTitle()); + } finally { + d.dispose(); + } + } + + public void testIsModal() { + SeriesTypeCreationDialog d = new SeriesTypeCreationDialog(emptyObs); + try { + assertTrue(d.isModal()); + } finally { + d.dispose(); + } + } + + public void testIsCancelledByDefault() { + SeriesTypeCreationDialog d = new SeriesTypeCreationDialog(emptyObs); + try { + assertTrue(d.isCancelled()); + } finally { + d.dispose(); + } + } + + public void testCancelActionLeavesDialogCancelled() { + SeriesTypeCreationDialog d = new SeriesTypeCreationDialog(emptyObs); + d.cancelAction(); + assertTrue(d.isCancelled()); + d.dispose(); + } +}