2 * Copyright (C) 2022 Roland Häder<roland@mxchange.org>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.jcountrycore.test.model.utils;
19 import org.mxchange.jcountry.model.data.Country;
20 import org.mxchange.jcountry.model.data.CountryData;
21 import org.mxchange.jcountry.model.utils.CountryUtils;
22 import org.testng.Assert;
23 import org.testng.annotations.DataProvider;
24 import org.testng.annotations.Test;
27 * Test cases for CountryUtils class
29 * @author Roland Häder<roland@mxchange.org>
31 public class CountryUtilsTest {
33 private static final String ABROAD_DIAL_PREFIX = "+"; //NOI18N
35 private static final String COUNTRY_CODE = "DE"; //NOI18N
37 private static final String COUNTRY_I18N_KEY = "COUNTRY_GERMANY"; //NOI18N
39 private static final Short COUNTRY_PHONE_CODE1 = 49;
41 private static final Short COUNTRY_PHONE_CODE2 = 1;
43 private static final String EXTERNAL_DIAL_PREFIX = "0"; //NOI18N
48 public CountryUtilsTest () {
51 @DataProvider (name = "different-country-provider")
52 public Object[][] createDifferentCountryObjectses () {
53 return new Object[][]{
58 "COUNTRY_USA", //NOI18N
72 @DataProvider (name = "left-null-country-provider")
73 public Object[][] createLeftNullCountryObjectses () {
74 return new Object[][]{
75 {null, new CountryData()},
76 {null, new CountryData(
87 @DataProvider (name = "right-null-country-provider")
88 public Object[][] createRightNullCountryObjectses () {
89 return new Object[][]{
90 {new CountryData(), null},
102 @DataProvider (name = "same-country-provider")
103 public Object[][] createSameCountryObjectses () {
104 return new Object[][]{
105 {new CountryData(), new CountryData()},
109 EXTERNAL_DIAL_PREFIX,
116 EXTERNAL_DIAL_PREFIX,
124 @Test (description = "Tests the CountryUtils.compare() method with different country data", dataProvider = "different-country-provider")
125 public void testCompareDifferent (final Country country1, final Country country2) {
126 // Expect 1 always, as right side is higher
127 Assert.assertEquals(CountryUtils.compare(country1, country2), 1);
130 @Test (description = "Tests the CountryUtils.compare() method with left-side being null and other country data", dataProvider = "left-null-country-provider")
131 public void testCompareLeftNull (final Country country1, final Country country2) {
133 Assert.assertEquals(CountryUtils.compare(country1, country2), -1);
136 @Test (description = "Tests the CountryUtils.compare() method with right-side being null and other country data", dataProvider = "right-null-country-provider")
137 public void testCompareRightNull (final Country country1, final Country country2) {
139 Assert.assertEquals(CountryUtils.compare(country1, country2), 1);
142 @Test (description = "Tests the CountryUtils.compare() method with same country data", dataProvider = "same-country-provider")
143 public void testCompareSame (final Country country1, final Country country2) {
145 Assert.assertEquals(CountryUtils.compare(country1, country2), 0);
148 @Test (description = "Tests the CountryUtils.copyCountryData() method with different instances", dataProvider = "different-country-provider")
149 public void testCopyCountryDifferentInstances (final Country country1, final Country country2) {
150 CountryUtils.copyCountryData(country1, country2);
153 @Test (description = "Tests the CountryUtils.copyCountryData() method with same instances", dataProvider = "same-country-provider", expectedExceptions = IllegalArgumentException.class)
154 public void testCopyCountrySameInstances (final Country country1, final Country country2) {
155 CountryUtils.copyCountryData(country1, country2);
158 @Test (description = "Tests the CountryUtils.copyCountryData() method with source null reference", dataProvider = "left-null-country-provider", expectedExceptions = NullPointerException.class)
159 public void testCopyCountrySourceNull (final Country country1, final Country country2) {
160 CountryUtils.copyCountryData(country1, country2);
163 @Test (description = "Tests the CountryUtils.copyCountryData() method with target null reference", dataProvider = "right-null-country-provider", expectedExceptions = NullPointerException.class)
164 public void testCopyCountryTargetNull (final Country country1, final Country country2) {
165 CountryUtils.copyCountryData(country1, country2);