View Javadoc

1   package com.atlassian.plugin.predicate;
2   
3   import java.util.Arrays;
4   import java.util.List;
5   
6   import com.atlassian.plugin.Plugin;
7   
8   import org.junit.Test;
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  {
17      private final List<String> parts = Arrays.asList("com\\.atlassian\\.end", "com\\.atlassian\\.part\\..*");
18  
19      @Test
20      public void naiveIncludeExamples()
21      {
22          final PluginPredicate predicate = new PluginKeyPatternsPredicate(PluginKeyPatternsPredicate.MatchType.MATCHES_ANY, parts);
23          assertThat(predicate.matches(pluginWithKey("com.atlassian.end")), is(true));
24          assertThat(predicate.matches(pluginWithKey("com.atlassian.ene")), is(false));
25          assertThat(predicate.matches(pluginWithKey("com.atlassian.enda")), is(false));
26          assertThat(predicate.matches(pluginWithKey("com.atlassian.part")), is(false));
27          assertThat(predicate.matches(pluginWithKey("com.atlassian.part.a")), is(true));
28          assertThat(predicate.matches(pluginWithKey("com.atlassian.part.b")), is(true));
29      }
30  
31      @Test
32      public void naiveExcludeExamples()
33      {
34          final PluginPredicate predicate = new PluginKeyPatternsPredicate(PluginKeyPatternsPredicate.MatchType.MATCHES_NONE, parts);
35          assertThat(predicate.matches(pluginWithKey("com.atlassian.end")), is(false));
36          assertThat(predicate.matches(pluginWithKey("com.atlassian.ene")), is(true));
37          assertThat(predicate.matches(pluginWithKey("com.atlassian.enda")), is(true));
38          assertThat(predicate.matches(pluginWithKey("com.atlassian.part")), is(true));
39          assertThat(predicate.matches(pluginWithKey("com.atlassian.part.a")), is(false));
40          assertThat(predicate.matches(pluginWithKey("com.atlassian.part.b")), is(false));
41      }
42  
43      private Plugin pluginWithKey(final String key)
44      {
45          final Plugin plugin = mock(Plugin.class);
46          when(plugin.getKey()).thenReturn(key);
47          return plugin;
48      }
49  }