diff options
author | Julien HENRY <julien.henry@sonarsource.com> | 2015-02-17 15:57:38 +0100 |
---|---|---|
committer | Julien HENRY <julien.henry@sonarsource.com> | 2015-02-17 15:58:12 +0100 |
commit | e9ea3c3488259b00831404de2415ffe58fcbaacf (patch) | |
tree | c8d3c8a028981671d5b009f3ed6401e392216190 /sonar-plugin-api/src | |
parent | f0d1fa77e8eb0b782c1664b1271e3b0823d6f1a4 (diff) | |
download | sonarqube-e9ea3c3488259b00831404de2415ffe58fcbaacf.tar.gz sonarqube-e9ea3c3488259b00831404de2415ffe58fcbaacf.zip |
SONAR-6079 A license might be displayed as expired even though it's not the case
Diffstat (limited to 'sonar-plugin-api/src')
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/config/License.java | 10 | ||||
-rw-r--r-- | sonar-plugin-api/src/test/java/org/sonar/api/config/LicenseTest.java | 19 |
2 files changed, 25 insertions, 4 deletions
diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/config/License.java b/sonar-plugin-api/src/main/java/org/sonar/api/config/License.java index 0e0f316d532..d0f53d44024 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/config/License.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/config/License.java @@ -102,7 +102,15 @@ public final class License { @VisibleForTesting boolean isExpired(Date now) { Date date = getExpirationDate(); - return date != null && !date.after(org.apache.commons.lang.time.DateUtils.truncate(now, Calendar.DATE)); + if (date == null) { + return false; + } + // SONAR-6079 include last day + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + cal.add(Calendar.DAY_OF_MONTH, 1); + cal.add(Calendar.SECOND, -1); + return now.after(cal.getTime()); } @Nullable diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/config/LicenseTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/config/LicenseTest.java index 305132e5251..ed490dd9ee7 100644 --- a/sonar-plugin-api/src/test/java/org/sonar/api/config/LicenseTest.java +++ b/sonar-plugin-api/src/test/java/org/sonar/api/config/LicenseTest.java @@ -23,6 +23,9 @@ import org.apache.commons.codec.binary.Base64; import org.junit.Test; import org.sonar.api.utils.DateUtils; +import java.util.Calendar; +import java.util.TimeZone; + import static org.assertj.core.api.Assertions.assertThat; public class LicenseTest { @@ -131,10 +134,20 @@ public class LicenseTest { public void isExpired() { License license = License.readPlainText(V2_FORMAT); - assertThat(license.isExpired(DateUtils.parseDate("2013-06-23"))).isTrue(); - assertThat(license.isExpired(DateUtils.parseDate("2012-05-18"))).isTrue(); - assertThat(license.isExpired(DateUtils.parseDateTime("2012-05-18T15:50:45+0100"))).isTrue(); assertThat(license.isExpired(DateUtils.parseDate("2011-01-01"))).isFalse(); + Calendar sameDay = Calendar.getInstance(TimeZone.getDefault()); + sameDay.setTime(DateUtils.parseDate("2012-05-18")); + assertThat(license.isExpired(sameDay.getTime())).isFalse(); + sameDay.set(Calendar.HOUR_OF_DAY, 15); + assertThat(license.isExpired(sameDay.getTime())).isFalse(); + sameDay.set(Calendar.HOUR_OF_DAY, 23); + sameDay.set(Calendar.MINUTE, 59); + sameDay.set(Calendar.SECOND, 59); + assertThat(license.isExpired(sameDay.getTime())).isFalse(); + // The day after + sameDay.add(Calendar.SECOND, 1); + assertThat(license.isExpired(sameDay.getTime())).isTrue(); + assertThat(license.isExpired(DateUtils.parseDate("2013-06-23"))).isTrue(); } @Test |