diff options
author | Adrien Hopkins <adrien.p.hopkins@gmail.com> | 2025-06-15 19:26:12 -0500 |
---|---|---|
committer | Adrien Hopkins <adrien.p.hopkins@gmail.com> | 2025-06-15 19:26:12 -0500 |
commit | da740edd3972fa049c4c8d0e43448c10a6a65dce (patch) | |
tree | 4a0d4f9fa861560d273249666c7a2acc12e9f235 /src/test/java/sevenUnitsGUI | |
parent | 34f0321a31e728fa66057d0decd9a938d133d596 (diff) |
Format & clean up source code
Diffstat (limited to 'src/test/java/sevenUnitsGUI')
-rw-r--r-- | src/test/java/sevenUnitsGUI/I18nTest.java | 37 | ||||
-rw-r--r-- | src/test/java/sevenUnitsGUI/PrefixRepetitionTest.java | 8 | ||||
-rw-r--r-- | src/test/java/sevenUnitsGUI/PrefixSearchTest.java | 16 | ||||
-rw-r--r-- | src/test/java/sevenUnitsGUI/RoundingTest.java | 10 | ||||
-rw-r--r-- | src/test/java/sevenUnitsGUI/TabbedViewTest.java | 28 |
5 files changed, 48 insertions, 51 deletions
diff --git a/src/test/java/sevenUnitsGUI/I18nTest.java b/src/test/java/sevenUnitsGUI/I18nTest.java index 78f5da4..2f90d76 100644 --- a/src/test/java/sevenUnitsGUI/I18nTest.java +++ b/src/test/java/sevenUnitsGUI/I18nTest.java @@ -28,68 +28,67 @@ import org.junit.jupiter.params.provider.MethodSource; /** * Tests for the internationalization system. - * + * * @since v1.0.0 */ class I18nTest { + private static final Stream<String> testLocaleSupported() { + return Stream.of("en", "fr"); + } + private static final Stream<Arguments> testLocalization() { - return Stream.of( - Arguments.of("tv.title", "en", "7Units [v]"), + return Stream.of(Arguments.of("tv.title", "en", "7Units [v]"), Arguments.of("tv.title", "fr", "7Unités [v]"), Arguments.of("tv.convert_units.title", "en", "Convert Units"), Arguments.of("tv.convert_units.title", "fr", "Convertir Unités")); } - - private static final Stream<String> testLocaleSupported() { - return Stream.of("en", "fr"); - } /** * Tests that the default locale is supported. - * + * * @since v1.0.0 * @see Presenter#DEFAULT_LOCALE */ @Test void testDefaultLocaleSupported() { - Presenter p = new Presenter(new ViewBot()); + final var p = new Presenter(new ViewBot()); assertNotNull(p.locales.get(Presenter.DEFAULT_LOCALE), "Default locale is not supported."); } - + /** * Ensures that the system supports the provided locale. - * + * * @param localeName locale to test for support - * + * * @since 2025-06-04 * @since v1.0.0 */ @ParameterizedTest @MethodSource void testLocaleSupported(String localeName) { - Presenter p = new Presenter(new ViewBot()); + final var p = new Presenter(new ViewBot()); assertNotNull(p.locales.get(localeName), "Locale \"" + localeName + "\" is not supported."); } /** - * Tests that the system can correctly localize text, - * using the default locales. - * + * Tests that the system can correctly localize text, using the default + * locales. + * * @param key key of text to localize * @param locale locale to use * @param expected expected value of output text - * + * * @since 2025-06-04 * @since v1.0.0 */ @ParameterizedTest @MethodSource void testLocalization(String key, String locale, String expected) { - Presenter p = new Presenter(new ViewBot()); + final var p = new Presenter(new ViewBot()); p.setUserLocale(locale); - String actual = p.getLocalizedText(key); + final var actual = p.getLocalizedText(key); assertEquals(expected, actual); } diff --git a/src/test/java/sevenUnitsGUI/PrefixRepetitionTest.java b/src/test/java/sevenUnitsGUI/PrefixRepetitionTest.java index 50b390b..ead5f4a 100644 --- a/src/test/java/sevenUnitsGUI/PrefixRepetitionTest.java +++ b/src/test/java/sevenUnitsGUI/PrefixRepetitionTest.java @@ -37,7 +37,7 @@ import sevenUnits.unit.Metric; class PrefixRepetitionTest { /** * Ensures that the complex repetition rule disallows invalid prefix lists. - * + * * @since 2022-07-17 * @since v0.4.0 */ @@ -57,7 +57,7 @@ class PrefixRepetitionTest { /** * Tests the {@code NO_REPETITION} rule. - * + * * @since 2022-07-17 * @since v0.4.0 */ @@ -71,7 +71,7 @@ class PrefixRepetitionTest { /** * Tests the {@code NO_RESTRICTION} rule. - * + * * @since 2022-07-17 * @since v0.4.0 */ @@ -85,7 +85,7 @@ class PrefixRepetitionTest { /** * Ensures that the complex repetition rule allows valid prefix lists. - * + * * @since 2022-07-17 * @since v0.4.0 */ diff --git a/src/test/java/sevenUnitsGUI/PrefixSearchTest.java b/src/test/java/sevenUnitsGUI/PrefixSearchTest.java index b605d05..00dd960 100644 --- a/src/test/java/sevenUnitsGUI/PrefixSearchTest.java +++ b/src/test/java/sevenUnitsGUI/PrefixSearchTest.java @@ -40,9 +40,7 @@ import sevenUnits.unit.Metric; * @since v0.4.0 */ class PrefixSearchTest { - /** - * A method that creates duplicate copies of the common prefix rule. - */ + /** A method that creates duplicate copies of the common prefix rule. */ private static final PrefixSearchRule getCommonRuleCopy() { return getCoherentOnlyRule(Set.of(Metric.KILO, Metric.MILLI)); } @@ -110,7 +108,7 @@ class PrefixSearchTest { /** * Tests prefix searching for a non-coherent unit and * {@link PrefixSearchRule#COMMON_PREFIXES}. - * + * * @since 2022-07-17 * @since v0.4.0 */ @@ -125,7 +123,7 @@ class PrefixSearchTest { /** * Tests that {@link PrefixSearchRule#NO_PREFIXES} returns the original unit. - * + * * @since 2022-07-17 * @since v0.4.0 */ @@ -151,10 +149,10 @@ class PrefixSearchTest { */ @Test final void testToString() { - final String toString = COMMON_PREFIXES.toString(); - final String valid1 = "Apply the following prefixes: [kilo (\u00D7 1000.0), milli (\u00D7 0.001)]"; - final String valid2 = "Apply the following prefixes: [milli (\u00D7 0.001), kilo (\u00D7 1000.0)]"; - + final var toString = COMMON_PREFIXES.toString(); + final var valid1 = "Apply the following prefixes: [kilo (\u00D7 1000.0), milli (\u00D7 0.001)]"; + final var valid2 = "Apply the following prefixes: [milli (\u00D7 0.001), kilo (\u00D7 1000.0)]"; + assertTrue(valid1.equals(toString) || valid2.equals(toString), "COMMON_PREFIXES.toString invalid (was \"" + toString + "\")."); } diff --git a/src/test/java/sevenUnitsGUI/RoundingTest.java b/src/test/java/sevenUnitsGUI/RoundingTest.java index e6453f2..589b8d0 100644 --- a/src/test/java/sevenUnitsGUI/RoundingTest.java +++ b/src/test/java/sevenUnitsGUI/RoundingTest.java @@ -137,7 +137,7 @@ class RoundingTest { /** * Tests that the rounding methods' equals() methods work. - * + * * @since 2022-07-17 * @since v0.4.0 */ @@ -161,7 +161,7 @@ class RoundingTest { // test that FixedDecimals is never equal to FixedPrecision // this unlikely argument is the test - the equals should return false! @SuppressWarnings("unlikely-arg-type") - final boolean differentRulesEqual = Objects.equals(fixedDecimals(4), + final var differentRulesEqual = Objects.equals(fixedDecimals(4), fixedPrecision(4)); assertFalse(differentRulesEqual, "fixedDecimals(4) == fixedPrecision(4)"); } @@ -226,7 +226,7 @@ class RoundingTest { /** * Tests that {@link StandardDisplayRules#getStandardRule} gets rounding * rules as intended. - * + * * @since 2022-07-17 * @since v0.4.0 */ @@ -244,7 +244,7 @@ class RoundingTest { /** * Tests that the rounding methods' equals() methods work. - * + * * @since 2022-07-17 * @since v0.4.0 */ @@ -258,7 +258,7 @@ class RoundingTest { /** * Tests that the {@code toString()} methods of the three rounding rule * classes work correctly. - * + * * @since 2022-07-17 * @since v0.4.0 */ diff --git a/src/test/java/sevenUnitsGUI/TabbedViewTest.java b/src/test/java/sevenUnitsGUI/TabbedViewTest.java index 3716673..b32579c 100644 --- a/src/test/java/sevenUnitsGUI/TabbedViewTest.java +++ b/src/test/java/sevenUnitsGUI/TabbedViewTest.java @@ -33,67 +33,67 @@ import org.junit.jupiter.api.Timeout; class TabbedViewTest { /** * @return a view with all settings set to standard values - * + * * @since 2022-07-17 * @since v0.4.0 */ private static final TabbedView setupView() { final var view = new TabbedView(); final var presenter = view.getPresenter(); - + presenter.setNumberDisplayRule(StandardDisplayRules.uncertaintyBased()); presenter.setPrefixRepetitionRule( DefaultPrefixRepetitionRule.NO_RESTRICTION); presenter.setSearchRule(PrefixSearchRule.COMMON_PREFIXES); presenter.setOneWayConversionEnabled(false); presenter.setShowDuplicates(true); - + return view; } - + /** * Simulates an expression conversion operation, and ensures it works * properly. - * + * * @since 2022-07-17 * @since v0.4.0 */ @Test void testExpressionConversion() { final var view = setupView(); - + // prepare for unit conversion view.masterPane.setSelectedIndex(1); view.fromEntry.setText("250.0 inch"); view.toEntry.setText("metre"); - + view.convertExpressionButton.doClick(); - + // check result of conversion assertEquals("250.0 inch = 6.350 metre", view.expressionOutput.getText()); } - + /** * Simulates a unit conversion operation, and ensures it works properly. - * + * * @since 2022-07-17 * @since v0.4.0 */ @Test void testUnitConversion() { final var view = setupView(); - + // prepare for unit conversion view.masterPane.setSelectedIndex(0); view.dimensionSelector.setSelectedItem("Length"); view.fromSearch.getSearchList().setSelectedValue("inch", true); view.toSearch.getSearchList().setSelectedValue("metre", true); view.valueInput.setText("250.0"); - + view.convertUnitButton.doClick(); - + // check result of conversion assertEquals("250.0 inch = 6.350 metre", view.unitOutput.getText()); } - + } |