Search in sources :

Example 6 with BaseDoc

use of org.sonar.server.es.BaseDoc in project sonarqube by SonarSource.

the class BaseDocTest method getNullableFieldAsDate.

@Test
public void getNullableFieldAsDate() {
    BaseDoc doc = new BaseDoc(someType, new HashMap<>()) {

        @Override
        public String getId() {
            return null;
        }
    };
    Date now = new Date();
    doc.setField("javaDate", now);
    assertThat(doc.getNullableFieldAsDate("javaDate")).isEqualToIgnoringMillis(now);
    doc.setField("stringDate", EsUtils.formatDateTime(now));
    assertThat(doc.getNullableFieldAsDate("stringDate")).isEqualToIgnoringMillis(now);
    doc.setField("noValue", null);
    assertThat(doc.getNullableFieldAsDate("noValue")).isNull();
}
Also used : BaseDoc(org.sonar.server.es.BaseDoc) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 BaseDoc (org.sonar.server.es.BaseDoc)6 Date (java.util.Date)2 HashMap (java.util.HashMap)2 IndexType (org.sonar.server.es.IndexType)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Map (java.util.Map)1 Index (org.sonar.server.es.Index)1