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