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.data;
19 import java.util.Date;
20 import org.mxchange.jcountry.model.data.Country;
21 import org.mxchange.jcountry.model.data.CountryData;
22 import org.testng.Assert;
23 import org.testng.annotations.DataProvider;
24 import org.testng.annotations.Test;
27 * Test cases for CountryData class as an object (no entity-related tests)
29 * @author Roland Häder<roland@mxchange.org>
31 public class CountryDataObjectTest {
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_CODE0 = 0;
41 private static final Short COUNTRY_PHONE_CODE1 = 49;
43 private static final String EXTERNAL_DIAL_PREFIX = "0"; //NOI18N
48 public CountryDataObjectTest () {
51 @DataProvider (name = "same-country-provider")
52 public Object[][] createSameCountryObjectses () {
53 return new Object[][]{
54 {new CountryData(), new CountryData()},
73 @Test (description = "Tests method Country.compareTo() responding to a null reference", expectedExceptions = NullPointerException.class)
74 public void testCompareToNullReference () {
76 final Country country = new CountryData();
78 // This should cause a NPE with a non-empty message
79 country.compareTo(null);
82 @Test (description = "Tests method Country.compareTo() responding to same country data", dataProvider = "same-country-provider")
83 public void testCompareToSameCountryData (final Country country1, final Country country2) {
85 Assert.assertEquals(country1.compareTo(country2), 0);
88 @Test (description = "Tests method Country.compareTo() responding to same instance ")
89 public void testCompareToSameInstance () {
90 final Country country1 = new CountryData();
91 Assert.assertEquals(country1.compareTo(country1), 0);
94 @Test (description = "Tests constructor with abroadDialPrefix being empty", expectedExceptions = IllegalArgumentException.class)
95 public void testConstructorEmptyAbroadDialPrefix () {
97 final Country country = new CountryData(
100 EXTERNAL_DIAL_PREFIX,
107 Assert.fail("The required parameter must never be empty and if so must cause an IAE being thrown: country=" + country); //NOI18N
110 @Test (description = "Tests constructor with countryCodde being empty", expectedExceptions = IllegalArgumentException.class)
111 public void testConstructorEmptyCountryCode () {
112 // Should throw a NPE
113 final Country country = new CountryData(
116 EXTERNAL_DIAL_PREFIX,
123 Assert.fail("The required parameter must never be empty and if so must cause an IAE being thrown: country=" + country); //NOI18N
126 @Test (description = "Tests constructor with countryI18nKey being empty", expectedExceptions = IllegalArgumentException.class)
127 public void testConstructorEmptyCountryI18nKey () {
128 // Should throw a NPE
129 final Country country = new CountryData(
132 EXTERNAL_DIAL_PREFIX,
139 Assert.fail("The required parameter must never be empty and if so must cause an IAE being thrown: country=" + country); //NOI18N
142 @Test (description = "Tests constructor with countryExternalDialPrefix being empty", expectedExceptions = IllegalArgumentException.class)
143 public void testConstructorEmptyExternalDialPrefix () {
144 // Should throw a NPE
145 final Country country = new CountryData(
155 Assert.fail("The required parameter must never be invalid and if so must cause an IAE being thrown: country=" + country); //NOI18N
158 @Test (description = "Tests constructor with invalid countryPhoneCode", expectedExceptions = IllegalArgumentException.class)
159 public void testConstructorInvalidCountryPhoneCode () {
160 // Should throw a NPE
161 final Country country = new CountryData(
164 EXTERNAL_DIAL_PREFIX,
165 COUNTRY_I18N_KEY, //NOI18N
171 Assert.fail("The required parameter must never be invalid or else an E being thrown: country=" + country); //NOI18N
174 @Test (description = "Tests constructor with abroadDialPrefix being null", expectedExceptions = NullPointerException.class)
175 public void testConstructorNullAbroadDialPrefix () {
176 // Should throw a NPE
177 final Country country = new CountryData(
180 EXTERNAL_DIAL_PREFIX,
187 Assert.fail("The required parameter must never be null and if so must cause a NPE being thrown: country=" + country); //NOI18N
190 @Test (description = "Tests constructor with countryCodde being null", expectedExceptions = NullPointerException.class)
191 public void testConstructorNullCountryCode () {
192 // Should throw a NPE
193 final Country country = new CountryData(
196 EXTERNAL_DIAL_PREFIX,
203 Assert.fail("The required parameter must never be null and if so must cause a NPE being thrown: country=" + country); //NOI18N
206 @Test (description = "Tests constructor with countryI18nKey being null", expectedExceptions = NullPointerException.class)
207 public void testConstructorNullCountryI18nKey () {
208 // Should throw a NPE
209 final Country country = new CountryData(
212 EXTERNAL_DIAL_PREFIX,
219 Assert.fail("The required parameter must never be null and if so must cause a NPE being thrown: country=" + country); //NOI18N
222 @Test (description = "Tests constructor with countryIsLocalPrefixRequired being null", expectedExceptions = NullPointerException.class)
223 public void testConstructorNullCountryIsLocalPrefixRequired () {
224 // Should throw a NPE
225 final Country country = new CountryData(
228 EXTERNAL_DIAL_PREFIX,
235 Assert.fail("The required parameter must never be null and if so must cause a NPE being thrown: country=" + country); //NOI18N
238 @Test (description = "Tests constructor with countryPhoneCode being null", expectedExceptions = NullPointerException.class)
239 public void testConstructorNullCountryPhoneCode () {
240 // Should throw a NPE
241 final Country country = new CountryData(
244 EXTERNAL_DIAL_PREFIX,
251 Assert.fail("The required parameter must never be null and if so must cause a NPE being thrown: country=" + country); //NOI18N
254 @Test (description = "Tests constructor with countryExternalDialPrefix being null", expectedExceptions = NullPointerException.class)
255 public void testConstructorNullExternalDialPrefix () {
256 // Should throw a NPE
257 final Country country = new CountryData(
267 Assert.fail("The required parameter must never be null and if so must cause a NPE being thrown: country=" + country); //NOI18N
270 @Test (description = "Tests if Country.equals() returns false when a null reference is provided")
271 @SuppressWarnings ("ObjectEqualsNull")
272 public void testEqualsNullReference () {
273 final Country country = new CountryData();
274 Assert.assertFalse(country.equals(null));
277 @Test (description = "Tests if Country.equals() returns false when an other object is provided")
278 public void testEqualsOtherObject () {
279 final Country country = new CountryData();
280 Assert.assertFalse(country.equals(new Object()));
283 @Test (description = "Tests if Country.equals() returns true when same instance is provided")
284 public void testEqualsSameInstance () {
285 final Country country = new CountryData();
286 Assert.assertTrue(country.equals(country));
289 @Test (description = "Tests if Country.equals() returns false when a field has been changed to an other value", dataProvider = "same-country-provider")
290 public void testEqualsDifferentAbroadDialPrefix (final Country country1, final Country country2) {
291 // First change countryAbroadDialPrefix to something else
292 country1.setCountryAbroadDialPrefix("++"); //NOI18N
293 Assert.assertFalse(country1.equals(country2));
294 country1.setCountryAbroadDialPrefix(ABROAD_DIAL_PREFIX);
297 @Test (description = "Tests if Country.equals() returns false when a field has been changed to an other value", dataProvider = "same-country-provider")
298 public void testEqualsDifferentCountryCode (final Country country1, final Country country2) {
299 // Next is countryCode
300 country1.setCountryCode("XX"); //NOI18N
301 Assert.assertFalse(country1.equals(country2));
302 country1.setCountryCode(COUNTRY_CODE);
305 @Test (description = "Tests if Country.equals() returns false when a field has been changed to an other value", dataProvider = "same-country-provider")
306 public void testEqualsDifferentExternalDialPrefix (final Country country1, final Country country2) {
307 // Next is countryExternalDialPrefix
308 country1.setCountryExternalDialPrefix("00"); //NOI18N
309 Assert.assertFalse(country1.equals(country2));
310 country1.setCountryCode(EXTERNAL_DIAL_PREFIX);
313 @Test (description = "Tests if Country.equals() returns false when a field has been changed to an other value", dataProvider = "same-country-provider")
314 public void testEqualsDifferentI18nKey (final Country country1, final Country country2) {
315 // Next is countryI18nKey
316 country1.setCountryI18nKey("COUNTRY_XX"); //NOI18N
317 Assert.assertFalse(country1.equals(country2));
318 country1.setCountryI18nKey(COUNTRY_I18N_KEY);
321 @Test (description = "Tests if Country.equals() returns false when a field has been changed to an other value", dataProvider = "same-country-provider")
322 public void testEqualsDifferentCountryId (final Country country1, final Country country2) {
324 country1.setCountryId(1l); //NOI18N
325 Assert.assertFalse(country1.equals(country2));
326 country1.setCountryId(null);
329 @Test (description = "Tests if Country.equals() returns false when a field has been changed to an other value", dataProvider = "same-country-provider")
330 public void testEqualsDifferentIsLocalDialPrefixRequired (final Country country1, final Country country2) {
332 country1.setCountryIsLocalPrefixRequired(Boolean.FALSE);
333 Assert.assertFalse(country1.equals(country2));
334 country1.setCountryIsLocalPrefixRequired(Boolean.TRUE);
337 @Test (description = "Tests if Country.equals() returns false when a field has been changed to an other value", dataProvider = "same-country-provider")
338 public void testEqualsDifferentPhoneCode (final Country country1, final Country country2) {
340 country1.setCountryPhoneCode(COUNTRY_PHONE_CODE0);
341 Assert.assertFalse(country1.equals(country2));
342 country1.setCountryPhoneCode(COUNTRY_PHONE_CODE1);
345 @Test (description = "Tests Country.countryEntryCreated getter/setter")
346 public void testCountryEntryCreated () {
348 final Country country = new CountryData();
349 final Date date = new Date();
352 country.setCountryEntryCreated(date);
354 // Should be the same!
355 Assert.assertEquals(country.getCountryEntryCreated(), date);
358 @Test (description = "Tests Country.countryEntryUpdated getter/setter")
359 public void testCountryEntryUpdated () {
361 final Country country = new CountryData();
362 final Date date = new Date();
365 country.setCountryEntryUpdated(date);
367 // Should be the same!
368 Assert.assertEquals(country.getCountryEntryUpdated(), date);