aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-plugin-api/src/test/java/org/sonar/api/utils/DateUtilsTest.java
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@gmail.com>2012-03-20 22:40:25 +0100
committerSimon Brandhof <simon.brandhof@gmail.com>2012-03-20 22:47:41 +0100
commit69515943c83b24c8dbefefe7420bab6d5de4c81f (patch)
treeaf547e76ce2d6be77785719ce1de165b1e5f2239 /sonar-plugin-api/src/test/java/org/sonar/api/utils/DateUtilsTest.java
parent4a2f5c9956e1711c88a360bcdb0bfc23dd4386d2 (diff)
downloadsonarqube-69515943c83b24c8dbefefe7420bab6d5de4c81f.tar.gz
sonarqube-69515943c83b24c8dbefefe7420bab6d5de4c81f.zip
API: add the methods DateUtils#parseDateQuietly(String) and parseDateTimeQuietly(String)
Diffstat (limited to 'sonar-plugin-api/src/test/java/org/sonar/api/utils/DateUtilsTest.java')
-rw-r--r--sonar-plugin-api/src/test/java/org/sonar/api/utils/DateUtilsTest.java46
1 files changed, 34 insertions, 12 deletions
diff --git a/sonar-plugin-api/src/test/java/org/sonar/api/utils/DateUtilsTest.java b/sonar-plugin-api/src/test/java/org/sonar/api/utils/DateUtilsTest.java
index 4d2025fdfe7..72978a55d1d 100644
--- a/sonar-plugin-api/src/test/java/org/sonar/api/utils/DateUtilsTest.java
+++ b/sonar-plugin-api/src/test/java/org/sonar/api/utils/DateUtilsTest.java
@@ -20,7 +20,9 @@
package org.sonar.api.utils;
import com.google.common.collect.Lists;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
import java.util.Date;
import java.util.List;
@@ -33,39 +35,60 @@ import static org.junit.Assert.*;
public class DateUtilsTest {
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
@Test
- public void shouldParseDate() {
+ public void parseDate_valid_format() {
Date date = DateUtils.parseDate("2010-05-18");
assertThat(date.getDate(), is(18));
}
- @Test(expected = SonarException.class)
- public void shouldNotParseDate() {
+ @Test
+ public void parseDate_not_valid_format() {
+ thrown.expect(SonarException.class);
DateUtils.parseDate("2010/05/18");
}
- @Test(expected = SonarException.class)
- public void shouldNotParseDateIfAdditionnalCharacters() {
+ @Test
+ public void parseDateQuietly() {
+ assertNull(DateUtils.parseDateQuietly("2010/05/18"));
+ Date date = DateUtils.parseDateQuietly("2010-05-18");
+ assertThat(date.getDate(), is(18));
+ }
+
+ @Test
+ public void parseDate_fail_if_additional_characters() {
+ thrown.expect(SonarException.class);
DateUtils.parseDate("1986-12-04foo");
}
@Test
- public void shouldParseDateTime() {
+ public void parseDateTime_valid_format() {
Date date = DateUtils.parseDateTime("2010-05-18T15:50:45+0100");
assertThat(date.getMinutes(), is(50));
}
- @Test(expected = SonarException.class)
- public void shouldNotParseDateTime() {
+ @Test
+ public void parseDateTime_not_valid_format() {
+ thrown.expect(SonarException.class);
DateUtils.parseDate("2010/05/18 10:55");
}
- @Test(expected = SonarException.class)
- public void shouldNotParseIfAdditionnalCharacters() {
+ @Test
+ public void parseDateTime_fail_if_additional_characters() {
+ thrown.expect(SonarException.class);
DateUtils.parseDateTime("1986-12-04T01:02:03+0300foo");
}
@Test
+ public void parseDateTimeQuietly() {
+ assertNull(DateUtils.parseDateTimeQuietly("2010/05/18 10:55"));
+ Date date = DateUtils.parseDateTimeQuietly("2010-05-18T15:50:45+0100");
+ assertThat(date.getMinutes(), is(50));
+ }
+
+ @Test
public void shouldFormatDate() {
assertThat(DateUtils.formatDate(new Date()), startsWith("20"));
assertThat(DateUtils.formatDate(new Date()).length(), is(10));
@@ -82,8 +105,7 @@ public class DateUtilsTest {
* See http://koders.com/java/fid8A231D75F2C6E6909FB26BCA11C12D08AD05FB50.aspx?s=ThreadSafeDateFormatTest
*/
@Test
- public void shouldBeThreadSafe() throws InterruptedException {
-
+ public void shouldBeThreadSafe() throws Exception {
final DateUtils.ThreadSafeDateFormat format = new DateUtils.ThreadSafeDateFormat("yyyy-MM-dd'T'HH:mm:ss,S z");
final Date now = new Date();
final List<Throwable> throwables = Lists.newArrayList();