X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=test%2Forg%2Fmxchange%2Fjcountry%2Fmodel%2Futils%2FCountryUtilsTest.java;fp=test%2Forg%2Fmxchange%2Fjcountry%2Fmodel%2Futils%2FCountryUtilsTest.java;h=8aae34f340984ff8df242ab4df451b69c35d9022;hb=baa3398dcba50e564a68bd16239590ff4b7db050;hp=0000000000000000000000000000000000000000;hpb=5668fd7b67dd28e2b5638a29bd677c581a505dd7;p=jcountry-core.git diff --git a/test/org/mxchange/jcountry/model/utils/CountryUtilsTest.java b/test/org/mxchange/jcountry/model/utils/CountryUtilsTest.java new file mode 100644 index 0000000..8aae34f --- /dev/null +++ b/test/org/mxchange/jcountry/model/utils/CountryUtilsTest.java @@ -0,0 +1,167 @@ +/* + * Copyright (C) 2022 Roland Häder + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package org.mxchange.jcountry.model.utils; + +import org.mxchange.jcountry.model.data.Country; +import org.mxchange.jcountry.model.data.CountryData; +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +/** + * Test cases for CountryUtils class + *

+ * @author Roland Häder + */ +public class CountryUtilsTest { + + private static final String ABROAD_DIAL_PREFIX = "+"; //NOI18N + + private static final String COUNTRY_CODE = "DE"; //NOI18N + + private static final String COUNTRY_I18N_KEY = "COUNTRY_GERMANY"; //NOI18N + + private static final Short COUNTRY_PHONE_CODE1 = 49; + + private static final Short COUNTRY_PHONE_CODE2 = 1; + + private static final String EXTERNAL_DIAL_PREFIX = "0"; //NOI18N + + /** + * Default constructor + */ + public CountryUtilsTest () { + } + + @DataProvider (name = "different-country-provider") + public Object[][] createDifferentCountryObjectses () { + return new Object[][]{ + {new CountryData( + ABROAD_DIAL_PREFIX, + "US", //NOI18N + EXTERNAL_DIAL_PREFIX, + "COUNTRY_USA", //NOI18N + Boolean.TRUE, + COUNTRY_PHONE_CODE2 + ), new CountryData( + ABROAD_DIAL_PREFIX, + COUNTRY_CODE, + EXTERNAL_DIAL_PREFIX, + COUNTRY_I18N_KEY, + Boolean.TRUE, + COUNTRY_PHONE_CODE1 + )} + }; + } + + @DataProvider (name = "left-null-country-provider") + public Object[][] createLeftNullCountryObjectses () { + return new Object[][]{ + {null, new CountryData()}, + {null, new CountryData( + ABROAD_DIAL_PREFIX, + COUNTRY_CODE, + EXTERNAL_DIAL_PREFIX, + COUNTRY_I18N_KEY, + Boolean.TRUE, + COUNTRY_PHONE_CODE1 + )} + }; + } + + @DataProvider (name = "right-null-country-provider") + public Object[][] createRightNullCountryObjectses () { + return new Object[][]{ + {new CountryData(), null}, + {new CountryData( + ABROAD_DIAL_PREFIX, + COUNTRY_CODE, + EXTERNAL_DIAL_PREFIX, + COUNTRY_I18N_KEY, + Boolean.TRUE, + COUNTRY_PHONE_CODE1 + ), null} + }; + } + + @DataProvider (name = "same-country-provider") + public Object[][] createSameCountryObjectses () { + return new Object[][]{ + {new CountryData(), new CountryData()}, + {new CountryData( + ABROAD_DIAL_PREFIX, + COUNTRY_CODE, + EXTERNAL_DIAL_PREFIX, + COUNTRY_I18N_KEY, + Boolean.TRUE, + COUNTRY_PHONE_CODE1 + ), new CountryData( + ABROAD_DIAL_PREFIX, + COUNTRY_CODE, + EXTERNAL_DIAL_PREFIX, + COUNTRY_I18N_KEY, + Boolean.TRUE, + COUNTRY_PHONE_CODE1 + )} + }; + } + + @Test (description = "Tests the CountryUtils.compare() method with different country data", dataProvider = "different-country-provider") + public void testCompareDifferent (final Country country1, final Country country2) { + // Expect 1 always, as right side is higher + Assert.assertEquals(CountryUtils.compare(country1, country2), 1); + } + + @Test (description = "Tests the CountryUtils.compare() method with left-side being null and other country data", dataProvider = "left-null-country-provider") + public void testCompareLeftNull (final Country country1, final Country country2) { + // Expect -1 always + Assert.assertEquals(CountryUtils.compare(country1, country2), -1); + } + + @Test (description = "Tests the CountryUtils.compare() method with right-side being null and other country data", dataProvider = "right-null-country-provider") + public void testCompareRightNull (final Country country1, final Country country2) { + // Expect 1 always + Assert.assertEquals(CountryUtils.compare(country1, country2), 1); + } + + @Test (description = "Tests the CountryUtils.compare() method with same country data", dataProvider = "same-country-provider") + public void testCompareSame (final Country country1, final Country country2) { + // Expect 0 always + Assert.assertEquals(CountryUtils.compare(country1, country2), 0); + } + + @Test (description = "Tests the CountryUtils.copyCountryData() method with different instances", dataProvider = "different-country-provider") + public void testCopyCountryDifferentInstances (final Country country1, final Country country2) { + CountryUtils.copyCountryData(country1, country2); + } + + @Test (description = "Tests the CountryUtils.copyCountryData() method with same instances", dataProvider = "same-country-provider", expectedExceptions = IllegalArgumentException.class) + public void testCopyCountrySameInstances (final Country country1, final Country country2) { + CountryUtils.copyCountryData(country1, country2); + } + + @Test (description = "Tests the CountryUtils.copyCountryData() method with source null reference", dataProvider = "left-null-country-provider", expectedExceptions = NullPointerException.class) + public void testCopyCountrySourceNull (final Country country1, final Country country2) { + CountryUtils.copyCountryData(country1, country2); + } + + @Test (description = "Tests the CountryUtils.copyCountryData() method with target null reference", dataProvider = "right-null-country-provider", expectedExceptions = NullPointerException.class) + public void testCopyCountryTargetNull (final Country country1, final Country country2) { + CountryUtils.copyCountryData(country1, country2); + } + +}