|
| 1 | +package com.optimizely.ab.config.audience.match; |
| 2 | + |
| 3 | +import org.junit.Test; |
| 4 | + |
| 5 | +import static com.optimizely.ab.config.audience.match.MatchRegistry.*; |
| 6 | +import static org.hamcrest.Matchers.instanceOf; |
| 7 | +import static org.junit.Assert.*; |
| 8 | + |
| 9 | +public class MatchRegistryTest { |
| 10 | + |
| 11 | + @Test |
| 12 | + public void testDefaultMatchers() throws UnknownMatchTypeException { |
| 13 | + assertThat(MatchRegistry.getMatch(EXISTS), instanceOf(ExistsMatch.class)); |
| 14 | + assertThat(MatchRegistry.getMatch(EXACT), instanceOf(ExactMatch.class)); |
| 15 | + assertThat(MatchRegistry.getMatch(GREATER_THAN), instanceOf(GTMatch.class)); |
| 16 | + assertThat(MatchRegistry.getMatch(LESS_THAN), instanceOf(LTMatch.class)); |
| 17 | + assertThat(MatchRegistry.getMatch(LESS_THAN_EQ), instanceOf(LEMatch.class)); |
| 18 | + assertThat(MatchRegistry.getMatch(GREATER_THAN_EQ), instanceOf(GEMatch.class)); |
| 19 | + assertThat(MatchRegistry.getMatch(SUBSTRING), instanceOf(SubstringMatch.class)); |
| 20 | + assertThat(MatchRegistry.getMatch(SEMVER_EQ), instanceOf(SemanticVersionEqualsMatch.class)); |
| 21 | + assertThat(MatchRegistry.getMatch(SEMVER_GE), instanceOf(SemanticVersionGEMatch.class)); |
| 22 | + assertThat(MatchRegistry.getMatch(SEMVER_GT), instanceOf(SemanticVersionGTMatch.class)); |
| 23 | + assertThat(MatchRegistry.getMatch(SEMVER_LE), instanceOf(SemanticVersionLEMatch.class)); |
| 24 | + assertThat(MatchRegistry.getMatch(SEMVER_LT), instanceOf(SemanticVersionLTMatch.class)); |
| 25 | + } |
| 26 | + |
| 27 | + @Test(expected = UnknownMatchTypeException.class) |
| 28 | + public void testUnknownMatcher() throws UnknownMatchTypeException { |
| 29 | + MatchRegistry.getMatch("UNKNOWN"); |
| 30 | + } |
| 31 | + |
| 32 | + @Test |
| 33 | + public void testRegister() throws UnknownMatchTypeException { |
| 34 | + class TestMatcher implements Match { |
| 35 | + @Override |
| 36 | + public Boolean eval(Object conditionValue, Object attributeValue) { |
| 37 | + return null; |
| 38 | + } |
| 39 | + } |
| 40 | + |
| 41 | + MatchRegistry.register("test-matcher", new TestMatcher()); |
| 42 | + assertThat(MatchRegistry.getMatch("test-matcher"), instanceOf(TestMatcher.class)); |
| 43 | + } |
| 44 | +} |
0 commit comments