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.data;
19 import java.util.Date;
20 import org.testng.Assert;
21 import org.testng.annotations.DataProvider;
22 import org.testng.annotations.Test;
25 * Test cases for CountryData class as an object (no entity-related tests)
27 * @author Roland Häder<roland@mxchange.org>
29 public class CountryDataObjectTest {
31 private static final String ABROAD_DIAL_PREFIX = "+"; //NOI18N
33 private static final String COUNTRY_CODE = "DE"; //NOI18N
35 private static final String COUNTRY_I18N_KEY = "COUNTRY_GERMANY"; //NOI18N
37 private static final Short COUNTRY_PHONE_CODE0 = 0;
39 private static final Short COUNTRY_PHONE_CODE1 = 49;
41 private static final String EXTERNAL_DIAL_PREFIX = "0"; //NOI18N
46 public CountryDataObjectTest () {
49 @DataProvider (name = "same-country-provider")
50 public Object[][] createSameCountryObjectses () {
51 return new Object[][]{
52 {new CountryData(), new CountryData()},
71 @Test (description = "Tests method Country.compareTo() responding to a null reference", expectedExceptions = NullPointerException.class)
72 public void testCompareToNullReference () {
74 final Country country = new CountryData();
76 // This should cause a NPE with a non-empty message
77 country.compareTo(null);
80 @Test (description = "Tests method Country.compareTo() responding to same country data", dataProvider = "same-country-provider")
81 public void testCompareToSameCountryData (final Country country1, final Country country2) {
83 Assert.assertEquals(country1.compareTo(country2), 0);
86 @Test (description = "Tests method Country.compareTo() responding to same instance ")
87 public void testCompareToSameInstance () {
88 final Country country1 = new CountryData();
89 Assert.assertEquals(country1.compareTo(country1), 0);
92 @Test (description = "Tests constructor with abroadDialPrefix being empty", expectedExceptions = IllegalArgumentException.class)
93 public void testConstructorEmptyAbroadDialPrefix () {
95 final Country country = new CountryData(
105 Assert.fail("The required parameter must never be empty and if so must cause an IAE being thrown: country=" + country); //NOI18N
108 @Test (description = "Tests constructor with countryCodde being empty", expectedExceptions = IllegalArgumentException.class)
109 public void testConstructorEmptyCountryCode () {
110 // Should throw a NPE
111 final Country country = new CountryData(
114 EXTERNAL_DIAL_PREFIX,
121 Assert.fail("The required parameter must never be empty and if so must cause an IAE being thrown: country=" + country); //NOI18N
124 @Test (description = "Tests constructor with countryI18nKey being empty", expectedExceptions = IllegalArgumentException.class)
125 public void testConstructorEmptyCountryI18nKey () {
126 // Should throw a NPE
127 final Country country = new CountryData(
130 EXTERNAL_DIAL_PREFIX,
137 Assert.fail("The required parameter must never be empty and if so must cause an IAE being thrown: country=" + country); //NOI18N
140 @Test (description = "Tests constructor with countryExternalDialPrefix being empty", expectedExceptions = IllegalArgumentException.class)
141 public void testConstructorEmptyExternalDialPrefix () {
142 // Should throw a NPE
143 final Country country = new CountryData(
153 Assert.fail("The required parameter must never be invalid and if so must cause an IAE being thrown: country=" + country); //NOI18N
156 @Test (description = "Tests constructor with invalid countryPhoneCode", expectedExceptions = IllegalArgumentException.class)
157 public void testConstructorInvalidCountryPhoneCode () {
158 // Should throw a NPE
159 final Country country = new CountryData(
162 EXTERNAL_DIAL_PREFIX,
163 COUNTRY_I18N_KEY, //NOI18N
169 Assert.fail("The required parameter must never be invalid or else an E being thrown: country=" + country); //NOI18N
172 @Test (description = "Tests constructor with abroadDialPrefix being null", expectedExceptions = NullPointerException.class)
173 public void testConstructorNullAbroadDialPrefix () {
174 // Should throw a NPE
175 final Country country = new CountryData(
178 EXTERNAL_DIAL_PREFIX,
185 Assert.fail("The required parameter must never be null and if so must cause a NPE being thrown: country=" + country); //NOI18N
188 @Test (description = "Tests constructor with countryCodde being null", expectedExceptions = NullPointerException.class)
189 public void testConstructorNullCountryCode () {
190 // Should throw a NPE
191 final Country country = new CountryData(
194 EXTERNAL_DIAL_PREFIX,
201 Assert.fail("The required parameter must never be null and if so must cause a NPE being thrown: country=" + country); //NOI18N
204 @Test (description = "Tests constructor with countryI18nKey being null", expectedExceptions = NullPointerException.class)
205 public void testConstructorNullCountryI18nKey () {
206 // Should throw a NPE
207 final Country country = new CountryData(
210 EXTERNAL_DIAL_PREFIX,
217 Assert.fail("The required parameter must never be null and if so must cause a NPE being thrown: country=" + country); //NOI18N
220 @Test (description = "Tests constructor with countryIsLocalPrefixRequired being null", expectedExceptions = NullPointerException.class)
221 public void testConstructorNullCountryIsLocalPrefixRequired () {
222 // Should throw a NPE
223 final Country country = new CountryData(
226 EXTERNAL_DIAL_PREFIX,
233 Assert.fail("The required parameter must never be null and if so must cause a NPE being thrown: country=" + country); //NOI18N
236 @Test (description = "Tests constructor with countryPhoneCode being null", expectedExceptions = NullPointerException.class)
237 public void testConstructorNullCountryPhoneCode () {
238 // Should throw a NPE
239 final Country country = new CountryData(
242 EXTERNAL_DIAL_PREFIX,
249 Assert.fail("The required parameter must never be null and if so must cause a NPE being thrown: country=" + country); //NOI18N
252 @Test (description = "Tests constructor with countryExternalDialPrefix being null", expectedExceptions = NullPointerException.class)
253 public void testConstructorNullExternalDialPrefix () {
254 // Should throw a NPE
255 final Country country = new CountryData(
265 Assert.fail("The required parameter must never be null and if so must cause a NPE being thrown: country=" + country); //NOI18N
268 @Test (description = "Tests Country.countryEntryCreated getter/setter")
269 public void testCountryEntryCreated () {
271 final Country country = new CountryData();
272 final Date date = new Date();
275 country.setCountryEntryCreated(date);
277 // Should be the same!
278 Assert.assertEquals(country.getCountryEntryCreated(), date);
281 @Test (description = "Tests Country.countryEntryUpdated getter/setter")
282 public void testCountryEntryUpdated () {
284 final Country country = new CountryData();
285 final Date date = new Date();
288 country.setCountryEntryUpdated(date);
290 // Should be the same!
291 Assert.assertEquals(country.getCountryEntryUpdated(), date);
294 @Test (description = "Tests if Country.equals() returns false when a field has been changed to an other value", dataProvider = "same-country-provider")
295 public void testEqualsDifferentAbroadDialPrefix (final Country country1, final Country country2) {
296 // First change countryAbroadDialPrefix to something else
297 country1.setCountryAbroadDialPrefix("++"); //NOI18N
298 Assert.assertFalse(country1.equals(country2));
299 country1.setCountryAbroadDialPrefix(ABROAD_DIAL_PREFIX);
302 @Test (description = "Tests if Country.equals() returns false when a field has been changed to an other value", dataProvider = "same-country-provider")
303 public void testEqualsDifferentCountryCode (final Country country1, final Country country2) {
304 // Next is countryCode
305 country1.setCountryCode("XX"); //NOI18N
306 Assert.assertFalse(country1.equals(country2));
307 country1.setCountryCode(COUNTRY_CODE);
310 @Test (description = "Tests if Country.equals() returns false when a field has been changed to an other value", dataProvider = "same-country-provider")
311 public void testEqualsDifferentCountryId (final Country country1, final Country country2) {
313 country1.setCountryId(1l); //NOI18N
314 Assert.assertFalse(country1.equals(country2));
315 country1.setCountryId(null);
318 @Test (description = "Tests if Country.equals() returns false when a field has been changed to an other value", dataProvider = "same-country-provider")
319 public void testEqualsDifferentExternalDialPrefix (final Country country1, final Country country2) {
320 // Next is countryExternalDialPrefix
321 country1.setCountryExternalDialPrefix("00"); //NOI18N
322 Assert.assertFalse(country1.equals(country2));
323 country1.setCountryCode(EXTERNAL_DIAL_PREFIX);
326 @Test (description = "Tests if Country.equals() returns false when a field has been changed to an other value", dataProvider = "same-country-provider")
327 public void testEqualsDifferentI18nKey (final Country country1, final Country country2) {
328 // Next is countryI18nKey
329 country1.setCountryI18nKey("COUNTRY_XX"); //NOI18N
330 Assert.assertFalse(country1.equals(country2));
331 country1.setCountryI18nKey(COUNTRY_I18N_KEY);
334 @Test (description = "Tests if Country.equals() returns false when a field has been changed to an other value", dataProvider = "same-country-provider")
335 public void testEqualsDifferentIsLocalDialPrefixRequired (final Country country1, final Country country2) {
337 country1.setCountryIsLocalPrefixRequired(Boolean.FALSE);
338 Assert.assertFalse(country1.equals(country2));
339 country1.setCountryIsLocalPrefixRequired(Boolean.TRUE);
342 @Test (description = "Tests if Country.equals() returns false when a field has been changed to an other value", dataProvider = "same-country-provider")
343 public void testEqualsDifferentPhoneCode (final Country country1, final Country country2) {
345 country1.setCountryPhoneCode(COUNTRY_PHONE_CODE0);
346 Assert.assertFalse(country1.equals(country2));
347 country1.setCountryPhoneCode(COUNTRY_PHONE_CODE1);
350 @Test (description = "Tests if Country.equals() returns false when a null reference is provided")
351 @SuppressWarnings ("ObjectEqualsNull")
352 public void testEqualsNullReference () {
353 final Country country = new CountryData();
354 Assert.assertFalse(country.equals(null));
357 @Test (description = "Tests if Country.equals() returns false when an other object is provided")
358 public void testEqualsOtherObject () {
359 final Country country = new CountryData();
360 Assert.assertFalse(country.equals(new Object()));
363 @Test (description = "Tests if Country.equals() returns true when same instance is provided")
364 public void testEqualsSameInstance () {
365 final Country country = new CountryData();
366 Assert.assertTrue(country.equals(country));