]> git.mxchange.org Git - jcountry-core.git/blob - test/org/mxchange/jcountry/model/utils/CountryUtilsTest.java
8aae34f340984ff8df242ab4df451b69c35d9022
[jcountry-core.git] / test / org / mxchange / jcountry / model / utils / CountryUtilsTest.java
1 /*
2  * Copyright (C) 2022 Roland Häder<roland@mxchange.org>
3  *
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.
8  *
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.
13  *
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/>.
16  */
17 package org.mxchange.jcountry.model.utils;
18
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;
24
25 /**
26  * Test cases for CountryUtils class
27  * <p>
28  * @author Roland Häder<roland@mxchange.org>
29  */
30 public class CountryUtilsTest {
31
32         private static final String ABROAD_DIAL_PREFIX = "+"; //NOI18N
33
34         private static final String COUNTRY_CODE = "DE"; //NOI18N
35
36         private static final String COUNTRY_I18N_KEY = "COUNTRY_GERMANY"; //NOI18N
37
38         private static final Short COUNTRY_PHONE_CODE1 = 49;
39
40         private static final Short COUNTRY_PHONE_CODE2 = 1;
41
42         private static final String EXTERNAL_DIAL_PREFIX = "0"; //NOI18N
43
44         /**
45          * Default constructor
46          */
47         public CountryUtilsTest () {
48         }
49
50         @DataProvider (name = "different-country-provider")
51         public Object[][] createDifferentCountryObjectses () {
52                 return new Object[][]{
53                         {new CountryData(
54                                 ABROAD_DIAL_PREFIX,
55                                 "US", //NOI18N
56                                 EXTERNAL_DIAL_PREFIX,
57                                 "COUNTRY_USA", //NOI18N
58                                 Boolean.TRUE,
59                                 COUNTRY_PHONE_CODE2
60                                 ), new CountryData(
61                          ABROAD_DIAL_PREFIX,
62                          COUNTRY_CODE,
63                          EXTERNAL_DIAL_PREFIX,
64                          COUNTRY_I18N_KEY,
65                          Boolean.TRUE,
66                          COUNTRY_PHONE_CODE1
67                          )}
68                 };
69         }
70
71         @DataProvider (name = "left-null-country-provider")
72         public Object[][] createLeftNullCountryObjectses () {
73                 return new Object[][]{
74                         {null, new CountryData()},
75                         {null, new CountryData(
76                          ABROAD_DIAL_PREFIX,
77                          COUNTRY_CODE,
78                          EXTERNAL_DIAL_PREFIX,
79                          COUNTRY_I18N_KEY,
80                          Boolean.TRUE,
81                          COUNTRY_PHONE_CODE1
82                          )}
83                 };
84         }
85
86         @DataProvider (name = "right-null-country-provider")
87         public Object[][] createRightNullCountryObjectses () {
88                 return new Object[][]{
89                         {new CountryData(), null},
90                         {new CountryData(
91                                 ABROAD_DIAL_PREFIX,
92                                 COUNTRY_CODE,
93                                 EXTERNAL_DIAL_PREFIX,
94                                 COUNTRY_I18N_KEY,
95                                 Boolean.TRUE,
96                                 COUNTRY_PHONE_CODE1
97                                 ), null}
98                 };
99         }
100
101         @DataProvider (name = "same-country-provider")
102         public Object[][] createSameCountryObjectses () {
103                 return new Object[][]{
104                         {new CountryData(), new CountryData()},
105                         {new CountryData(
106                                 ABROAD_DIAL_PREFIX,
107                                 COUNTRY_CODE,
108                                 EXTERNAL_DIAL_PREFIX,
109                                 COUNTRY_I18N_KEY,
110                                 Boolean.TRUE,
111                                 COUNTRY_PHONE_CODE1
112                                 ), new CountryData(
113                          ABROAD_DIAL_PREFIX,
114                          COUNTRY_CODE,
115                          EXTERNAL_DIAL_PREFIX,
116                          COUNTRY_I18N_KEY,
117                          Boolean.TRUE,
118                          COUNTRY_PHONE_CODE1
119                          )}
120                 };
121         }
122
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);
127         }
128
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) {
131                 // Expect -1 always
132                 Assert.assertEquals(CountryUtils.compare(country1, country2), -1);
133         }
134
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) {
137                 // Expect 1 always
138                 Assert.assertEquals(CountryUtils.compare(country1, country2), 1);
139         }
140
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) {
143                 // Expect 0 always
144                 Assert.assertEquals(CountryUtils.compare(country1, country2), 0);
145         }
146
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);
150         }
151
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);
155         }
156
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);
160         }
161
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);
165         }
166
167 }