import org.sonar.api.rule.RuleKey;
import org.sonar.api.rules.RuleType;
import org.sonar.api.server.ServerSide;
+import org.sonar.api.utils.log.Logger;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.core.util.stream.MoreCollectors;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
@ServerSide
public class IssueQueryFactory {
+ private static final Logger LOGGER = Loggers.get(IssueQueryFactory.class);
+
public static final String UNKNOWN = "<UNKNOWN>";
public static final List<String> ISSUE_STATUSES = STATUSES.stream()
.filter(s -> !s.equals(STATUS_TO_REVIEW))
try {
return Optional.of(ZoneId.of(timeZone));
} catch (DateTimeException e) {
- throw new IllegalArgumentException("TimeZone '" + timeZone + "' cannot be parsed as a valid zone ID");
+ LOGGER.warn("TimeZone '" + timeZone + "' cannot be parsed as a valid zone ID");
+ return Optional.empty();
}
}
import org.junit.Test;
import org.sonar.api.resources.Qualifiers;
import org.sonar.api.rule.RuleKey;
+import org.sonar.api.utils.log.LogTester;
import org.sonar.db.DbTester;
import org.sonar.db.component.ComponentDto;
import org.sonar.db.component.SnapshotDto;
public UserSessionRule userSession = UserSessionRule.standalone();
@Rule
public DbTester db = DbTester.create();
+ @Rule
+ public LogTester logTester = new LogTester();
private final RuleDbTester ruleDbTester = new RuleDbTester(db);
private final Clock clock = mock(Clock.class);
}
@Test
- public void fail_if_invalid_timezone() {
- SearchRequest request = new SearchRequest()
- .setTimeZone("Poitou-Charentes");
+ public void timeZone_ifZoneFromQueryIsUnknown_fallbacksToClockZone() {
+ SearchRequest request = new SearchRequest().setTimeZone("Poitou-Charentes");
+ when(clock.getZone()).thenReturn(ZoneId.systemDefault());
- assertThatThrownBy(() -> underTest.create(request))
- .isInstanceOf(IllegalArgumentException.class)
- .hasMessageContaining("TimeZone 'Poitou-Charentes' cannot be parsed as a valid zone ID");
+ IssueQuery issueQuery = underTest.create(request);
+ assertThat(issueQuery.timeZone()).isEqualTo(clock.getZone());
+ assertThat(logTester.logs()).containsOnly("TimeZone 'Poitou-Charentes' cannot be parsed as a valid zone ID");
}
@Test