From 061a79d9236e9159a809c8b77d833699d71b9721 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Mon, 1 Oct 2018 18:19:50 +0100 Subject: Add JUnit for test concepts JUnit test for test concepts. Issue-ID: POLICY-1034 Change-Id: Ia2cd896272d4278d842d19d21237edcdca54a1f8 Signed-off-by: liamfallon --- .../context/test/concepts/TestContextDateItem.java | 34 +++++---------- .../test/concepts/TestContextDateLocaleItem.java | 51 ++++++++++------------ .../test/concepts/TestContextDateTzItem.java | 10 ++++- 3 files changed, 41 insertions(+), 54 deletions(-) (limited to 'context/context-test-utils/src/main/java/org') diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextDateItem.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextDateItem.java index 188b69c05..89d2a428f 100644 --- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextDateItem.java +++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextDateItem.java @@ -57,7 +57,12 @@ public class TestContextDateItem implements Serializable { * @param dateValue the date value */ public TestContextDateItem(final Date dateValue) { - setDateValue(dateValue.getTime()); + if (dateValue != null) { + setDateValue(dateValue.getTime()); + } + else { + new Date(0); + } } /** @@ -156,7 +161,9 @@ public class TestContextDateItem implements Serializable { * @param dateValue the date value */ public void setDateValue(final Date dateValue) { - setDateValue(dateValue.getTime()); + if (dateValue != null) { + setDateValue(dateValue.getTime()); + } } /** @@ -218,28 +225,7 @@ public class TestContextDateItem implements Serializable { return false; } final TestContextDateItem other = (TestContextDateItem) obj; - if (day != other.day) { - return false; - } - if (hour != other.hour) { - return false; - } - if (milliSecond != other.milliSecond) { - return false; - } - if (minute != other.minute) { - return false; - } - if (month != other.month) { - return false; - } - if (second != other.second) { - return false; - } - if (time != other.time) { - return false; - } - return year == other.year; + return time == other.time; } /* diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextDateLocaleItem.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextDateLocaleItem.java index 4712074a2..4914a1bc5 100644 --- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextDateLocaleItem.java +++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextDateLocaleItem.java @@ -38,13 +38,13 @@ public class TestContextDateLocaleItem implements Serializable { private String timeZoneString = TimeZone.getTimeZone("Europe/Dublin").getDisplayName(); private boolean dst = false; private int utcOffset = 0; - private String localeLanguage = Locale.ENGLISH.getLanguage(); - private String localeCountry = Locale.ENGLISH.getCountry(); + private Locale locale = Locale.ENGLISH; /** * The Constructor. */ - public TestContextDateLocaleItem() {} + public TestContextDateLocaleItem() { + } /** * The Constructor. @@ -57,15 +57,13 @@ public class TestContextDateLocaleItem implements Serializable { * @param country the country */ public TestContextDateLocaleItem(final TestContextDateItem dateValue, final String tzValue, final boolean dst, - final int utcOffset, final String language, final String country) { + final int utcOffset, final String language, final String country) { this.dateValue = dateValue; this.timeZoneString = TimeZone.getTimeZone(tzValue).getDisplayName(); this.dst = dst; this.utcOffset = utcOffset; - final Locale locale = new Locale(language, country); - this.localeLanguage = locale.getLanguage(); - this.localeCountry = locale.getCountry(); + this.locale = new Locale(language, country); } /** @@ -79,9 +77,7 @@ public class TestContextDateLocaleItem implements Serializable { this.dst = original.dst; this.utcOffset = original.utcOffset; - final Locale locale = new Locale(original.localeLanguage, original.localeCountry); - this.localeLanguage = locale.getLanguage(); - this.localeCountry = locale.getCountry(); + this.locale = new Locale(original.getLocale().getCountry(), original.getLocale().getLanguage()); } /** @@ -117,7 +113,11 @@ public class TestContextDateLocaleItem implements Serializable { * @param tzValue the TZ value */ public void setTzValue(final String tzValue) { - this.timeZoneString = TimeZone.getTimeZone(tzValue).getDisplayName(); + if (tzValue != null) { + this.timeZoneString = TimeZone.getTimeZone(tzValue).getDisplayName(); + } else { + this.timeZoneString = null; + } } /** @@ -162,7 +162,7 @@ public class TestContextDateLocaleItem implements Serializable { * @return the locale */ public Locale getLocale() { - return new Locale(localeLanguage, localeCountry); + return locale; } /** @@ -171,8 +171,12 @@ public class TestContextDateLocaleItem implements Serializable { * @param locale the locale */ public void setLocale(final Locale locale) { - this.localeLanguage = locale.getLanguage(); - this.localeCountry = locale.getCountry(); + if (locale != null) { + this.locale = locale; + } + else { + this.locale = null; + } } /* @@ -186,8 +190,7 @@ public class TestContextDateLocaleItem implements Serializable { int result = 1; result = prime * result + ((dateValue == null) ? 0 : dateValue.hashCode()); result = prime * result + (dst ? HASH_PRIME_2 : HASH_PRIME_3); - result = prime * result + ((localeCountry == null) ? 0 : localeCountry.hashCode()); - result = prime * result + ((localeLanguage == null) ? 0 : localeLanguage.hashCode()); + result = prime * result + ((locale == null) ? 0 : locale.hashCode()); result = prime * result + ((timeZoneString == null) ? 0 : timeZoneString.hashCode()); result = prime * result + utcOffset; return result; @@ -220,18 +223,11 @@ public class TestContextDateLocaleItem implements Serializable { if (dst != other.dst) { return false; } - if (localeCountry == null) { - if (other.localeCountry != null) { - return false; - } - } else if (!localeCountry.equals(other.localeCountry)) { - return false; - } - if (localeLanguage == null) { - if (other.localeLanguage != null) { + if (locale == null) { + if (other.locale != null) { return false; } - } else if (!localeLanguage.equals(other.localeLanguage)) { + } else if (!locale.equals(other.locale)) { return false; } if (timeZoneString == null) { @@ -252,7 +248,6 @@ public class TestContextDateLocaleItem implements Serializable { @Override public String toString() { return "TestContextItem00A [dateValue=" + dateValue + ", timeZoneString=" + timeZoneString + ", dst=" + dst - + ", utcOffset=" + utcOffset + ", localeLanguage=" + localeLanguage + ", localeCountry=" + localeCountry - + "]"; + + ", utcOffset=" + utcOffset + ", locale=" + locale + "]"; } } diff --git a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextDateTzItem.java b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextDateTzItem.java index 7e1e32924..15bd0232f 100644 --- a/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextDateTzItem.java +++ b/context/context-test-utils/src/main/java/org/onap/policy/apex/context/test/concepts/TestContextDateTzItem.java @@ -101,7 +101,12 @@ public class TestContextDateTzItem implements Serializable { * @param tzValue the TZ value */ public void setTzValue(final String tzValue) { - this.timeZoneString = TimeZone.getTimeZone(tzValue).getDisplayName(); + if (tzValue != null) { + this.timeZoneString = TimeZone.getTimeZone(tzValue).getDisplayName(); + } + else { + this.timeZoneString = null; + } } /** @@ -168,7 +173,8 @@ public class TestContextDateTzItem implements Serializable { if (other.timeZoneString != null) { return false; } - } else if (!timeZoneString.equals(other.timeZoneString)) { + } + else if (!timeZoneString.equals(other.timeZoneString)) { return false; } return true; -- cgit 1.2.3-korg