--- /dev/null
+/*
+ * Copyright (C) 2022 Roland Häder<roland@mxchange.org>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+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
+ * <p>
+ * @author Roland Häder<roland@mxchange.org>
+ */
+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);
+ }
+
+}