|
| 1 | +package com.hubspot.jinjava; |
| 2 | + |
| 3 | +import static org.assertj.core.api.Assertions.assertThat; |
| 4 | + |
| 5 | +import com.hubspot.jinjava.features.DateTimeFeatureActivationStrategy; |
| 6 | +import com.hubspot.jinjava.features.DelegatingFeatureActivationStrategy; |
| 7 | +import com.hubspot.jinjava.features.FeatureConfig; |
| 8 | +import com.hubspot.jinjava.features.Features; |
| 9 | +import com.hubspot.jinjava.features.StaticFeatureActivationStrategy; |
| 10 | +import java.time.LocalDateTime; |
| 11 | +import org.junit.Before; |
| 12 | +import org.junit.Test; |
| 13 | + |
| 14 | +public class FeaturesTest { |
| 15 | + private static final String ALWAYS_OFF = "alwaysOff"; |
| 16 | + private static final String ALWAYS_ON = "alwaysOn"; |
| 17 | + private static final String DATE_PAST = "datePast"; |
| 18 | + private static final String DATE_FUTURE = "dateFuture"; |
| 19 | + private static final String DELEGATING = "delegating"; |
| 20 | + |
| 21 | + private Features features; |
| 22 | + |
| 23 | + private boolean delegateActive = false; |
| 24 | + |
| 25 | + @Before |
| 26 | + public void setUp() throws Exception { |
| 27 | + features = |
| 28 | + new Features( |
| 29 | + FeatureConfig |
| 30 | + .newBuilder() |
| 31 | + .add(ALWAYS_OFF, StaticFeatureActivationStrategy.of(false)) |
| 32 | + .add(ALWAYS_ON, StaticFeatureActivationStrategy.of(true)) |
| 33 | + .add(DATE_PAST, DateTimeFeatureActivationStrategy.of(LocalDateTime.MIN)) |
| 34 | + .add(DATE_FUTURE, DateTimeFeatureActivationStrategy.of(LocalDateTime.MAX)) |
| 35 | + .add(DELEGATING, DelegatingFeatureActivationStrategy.of(() -> delegateActive)) |
| 36 | + .build() |
| 37 | + ); |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + public void itHasEnabledFeature() { |
| 42 | + assertThat(features.isActive(ALWAYS_ON)).isTrue(); |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + public void itHasDisabledFeature() { |
| 47 | + assertThat(features.isActive(ALWAYS_OFF)).isFalse(); |
| 48 | + } |
| 49 | + |
| 50 | + @Test |
| 51 | + public void itHasPastEnabledFeature() { |
| 52 | + assertThat(features.isActive(DATE_PAST)).isTrue(); |
| 53 | + } |
| 54 | + |
| 55 | + @Test |
| 56 | + public void itHasFutureEnabledFeature() { |
| 57 | + assertThat(features.isActive(DATE_FUTURE)).isFalse(); |
| 58 | + } |
| 59 | + |
| 60 | + @Test |
| 61 | + public void itUsesDelegate() { |
| 62 | + delegateActive = false; |
| 63 | + assertThat(features.isActive(DELEGATING)).isEqualTo(delegateActive); |
| 64 | + delegateActive = true; |
| 65 | + assertThat(features.isActive(DELEGATING)).isEqualTo(delegateActive); |
| 66 | + } |
| 67 | + |
| 68 | + @Test |
| 69 | + public void itDefaultsToFalse() { |
| 70 | + assertThat(features.isActive("unknown")).isFalse(); |
| 71 | + } |
| 72 | +} |
0 commit comments