View Javadoc
1   package com.atlassian.plugin.predicate;
2   
3   import com.atlassian.plugin.Plugin;
4   import org.junit.Test;
5   
6   import java.util.Arrays;
7   import java.util.List;
8   import java.util.function.Predicate;
9   
10  import static org.hamcrest.MatcherAssert.assertThat;
11  import static org.hamcrest.core.Is.is;
12  import static org.mockito.Mockito.mock;
13  import static org.mockito.Mockito.when;
14  
15  public class TestPluginKeyPatternsPredicate {
16      private final List<String> parts = Arrays.asList("com\\.atlassian\\.end", "com\\.atlassian\\.part\\..*");
17  
18      @Test
19      public void naiveIncludeExamples() {
20          final Predicate<Plugin> predicate = new PluginKeyPatternsPredicate(PluginKeyPatternsPredicate.MatchType.MATCHES_ANY, parts);
21          assertThat(predicate.test(pluginWithKey("com.atlassian.end")), is(true));
22          assertThat(predicate.test(pluginWithKey("com.atlassian.ene")), is(false));
23          assertThat(predicate.test(pluginWithKey("com.atlassian.enda")), is(false));
24          assertThat(predicate.test(pluginWithKey("com.atlassian.part")), is(false));
25          assertThat(predicate.test(pluginWithKey("com.atlassian.part.a")), is(true));
26          assertThat(predicate.test(pluginWithKey("com.atlassian.part.b")), is(true));
27      }
28  
29      @Test
30      public void naiveExcludeExamples() {
31          final Predicate<Plugin> predicate = new PluginKeyPatternsPredicate(PluginKeyPatternsPredicate.MatchType.MATCHES_NONE, parts);
32          assertThat(predicate.test(pluginWithKey("com.atlassian.end")), is(false));
33          assertThat(predicate.test(pluginWithKey("com.atlassian.ene")), is(true));
34          assertThat(predicate.test(pluginWithKey("com.atlassian.enda")), is(true));
35          assertThat(predicate.test(pluginWithKey("com.atlassian.part")), is(true));
36          assertThat(predicate.test(pluginWithKey("com.atlassian.part.a")), is(false));
37          assertThat(predicate.test(pluginWithKey("com.atlassian.part.b")), is(false));
38      }
39  
40      private Plugin pluginWithKey(final String key) {
41          final Plugin plugin = mock(Plugin.class);
42          when(plugin.getKey()).thenReturn(key);
43          return plugin;
44      }
45  }