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.jcountry.model.utils;
19 import org.mxchange.jcountry.model.data.Country;
20 import org.mxchange.jcountry.model.data.CountryData;
21 import org.testng.Assert;
22 import org.testng.annotations.DataProvider;
23 import org.testng.annotations.Test;
26 * Test cases for CountryUtils class
28 * @author Roland Häder<roland@mxchange.org>
30 public class CountryUtilsTest {
32 private static final String ABROAD_DIAL_PREFIX = "+"; //NOI18N
34 private static final String COUNTRY_CODE = "DE"; //NOI18N
36 private static final String COUNTRY_I18N_KEY = "COUNTRY_GERMANY"; //NOI18N
38 private static final Short COUNTRY_PHONE_CODE1 = 49;
40 private static final Short COUNTRY_PHONE_CODE2 = 1;
42 private static final String EXTERNAL_DIAL_PREFIX = "0"; //NOI18N
47 public CountryUtilsTest () {
50 @DataProvider (name = "different-country-provider")
51 public Object[][] createDifferentCountryObjectses () {
52 return new Object[][]{
57 "COUNTRY_USA", //NOI18N
71 @DataProvider (name = "left-null-country-provider")
72 public Object[][] createLeftNullCountryObjectses () {
73 return new Object[][]{
74 {null, new CountryData()},
75 {null, new CountryData(
86 @DataProvider (name = "right-null-country-provider")
87 public Object[][] createRightNullCountryObjectses () {
88 return new Object[][]{
89 {new CountryData(), null},
101 @DataProvider (name = "same-country-provider")
102 public Object[][] createSameCountryObjectses () {
103 return new Object[][]{
104 {new CountryData(), new CountryData()},
108 EXTERNAL_DIAL_PREFIX,
115 EXTERNAL_DIAL_PREFIX,
123 @Test (description = "Tests the CountryUtils.compare() method with different country data", dataProvider = "different-country-provider")
124 public void testCompareDifferent (final Country country1, final Country country2) {
125 // Expect 1 always, as right side is higher
126 Assert.assertEquals(CountryUtils.compare(country1, country2), 1);
129 @Test (description = "Tests the CountryUtils.compare() method with left-side being null and other country data", dataProvider = "left-null-country-provider")
130 public void testCompareLeftNull (final Country country1, final Country country2) {
132 Assert.assertEquals(CountryUtils.compare(country1, country2), -1);
135 @Test (description = "Tests the CountryUtils.compare() method with right-side being null and other country data", dataProvider = "right-null-country-provider")
136 public void testCompareRightNull (final Country country1, final Country country2) {
138 Assert.assertEquals(CountryUtils.compare(country1, country2), 1);
141 @Test (description = "Tests the CountryUtils.compare() method with same country data", dataProvider = "same-country-provider")
142 public void testCompareSame (final Country country1, final Country country2) {
144 Assert.assertEquals(CountryUtils.compare(country1, country2), 0);
147 @Test (description = "Tests the CountryUtils.copyCountryData() method with different instances", dataProvider = "different-country-provider")
148 public void testCopyCountryDifferentInstances (final Country country1, final Country country2) {
149 CountryUtils.copyCountryData(country1, country2);
152 @Test (description = "Tests the CountryUtils.copyCountryData() method with same instances", dataProvider = "same-country-provider", expectedExceptions = IllegalArgumentException.class)
153 public void testCopyCountrySameInstances (final Country country1, final Country country2) {
154 CountryUtils.copyCountryData(country1, country2);
157 @Test (description = "Tests the CountryUtils.copyCountryData() method with source null reference", dataProvider = "left-null-country-provider", expectedExceptions = NullPointerException.class)
158 public void testCopyCountrySourceNull (final Country country1, final Country country2) {
159 CountryUtils.copyCountryData(country1, country2);
162 @Test (description = "Tests the CountryUtils.copyCountryData() method with target null reference", dataProvider = "right-null-country-provider", expectedExceptions = NullPointerException.class)
163 public void testCopyCountryTargetNull (final Country country1, final Country country2) {
164 CountryUtils.copyCountryData(country1, country2);