Skip to content

Commit

Permalink
fix(quietperiods): case insensitive trigger type compare (#379)
Browse files Browse the repository at this point in the history
* fix(quietperiods): case insensitive trigger type compare

* chore(imports): clean up
  • Loading branch information
skandragon authored Oct 26, 2018
1 parent 8467913 commit f38642e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.time.Instant;
Expand Down Expand Up @@ -88,8 +85,17 @@ public boolean inQuietPeriod(long now) {
return result;
}

private boolean shouldSuppressType(String triggerType) {
for (String trigger: suppressedTriggerTypes) {
if (trigger.equalsIgnoreCase(triggerType)) {
return true;
}
}
return false;
}

public boolean inQuietPeriod(long now, String triggerType) {
return inQuietPeriod(now) && suppressedTriggerTypes.contains(triggerType);
return inQuietPeriod(now) && shouldSuppressType(triggerType);
}

private long parseIso(String iso) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,15 @@ class QuietPeriodIndicatorSpec extends Specification {
!quietPeriodIndicator.inQuietPeriod(parseIso(inRangeDate), "notInTheList")
quietPeriodIndicator.inQuietPeriod(parseIso(inRangeDate), "inTheList")
}

def "trigger type list is case insensitive"() {
given:
ArrayList<String> triggerTypes = new ArrayList<>();
triggerTypes.add("inTheList")
QuietPeriodIndicatorConfigurationProperties config = new QuietPeriodIndicatorConfigurationProperties(true, goodStartDate, goodEndDate, triggerTypes);
QuietPeriodIndicator quietPeriodIndicator = new QuietPeriodIndicator(registry, config)

expect:
quietPeriodIndicator.inQuietPeriod(parseIso(inRangeDate), "inthelist")
}
}

0 comments on commit f38642e

Please sign in to comment.