View Javadoc
1   package com.atlassian.plugin;
2   
3   import com.atlassian.plugin.PluginDependencies.Type;
4   import com.google.common.collect.ImmutableMultimap;
5   import com.google.common.collect.ImmutableSet;
6   import com.google.common.collect.Multimap;
7   import org.junit.Before;
8   import org.junit.Test;
9   
10  import java.util.Set;
11  
12  import static com.atlassian.plugin.PluginDependencies.Type.DYNAMIC;
13  import static com.atlassian.plugin.PluginDependencies.Type.MANDATORY;
14  import static com.atlassian.plugin.PluginDependencies.Type.OPTIONAL;
15  import static org.hamcrest.MatcherAssert.assertThat;
16  import static org.hamcrest.Matchers.containsInAnyOrder;
17  import static org.hamcrest.Matchers.equalTo;
18  import static org.hamcrest.Matchers.is;
19  
20  public class TestPluginDependencies {
21      private PluginDependencies deps;
22  
23      @Before
24      public void setUp() throws Exception {
25          deps = PluginDependencies.builder()
26                  .withDynamic("A")
27                  .withDynamic("B")
28                  .withDynamic("C", "D")
29                  .withOptional("E")
30                  .withOptional("F")
31                  .withOptional("G", "H")
32                  .withMandatory("I")
33                  .withMandatory("J")
34                  .withMandatory("K", "L")
35                  .withDynamic("X")
36                  .withMandatory("X")
37                  .withOptional("X")
38                  .build();
39      }
40  
41      @Test
42      public void testGetMandatory() throws Exception {
43          assertThat(deps.getMandatory(), is(equalTo((Set) ImmutableSet.of("I", "J", "K", "L", "X"))));
44      }
45  
46      @Test
47      public void testGetOptional() throws Exception {
48          assertThat(deps.getOptional(), is(equalTo((Set) ImmutableSet.of("E", "F", "G", "H", "X"))));
49      }
50  
51      @Test
52      public void testGetDynamic() throws Exception {
53          assertThat(deps.getDynamic(), is(equalTo((Set) ImmutableSet.of("A", "B", "C", "D", "X"))));
54      }
55  
56      @Test
57      public void testGetAll() throws Exception {
58          assertThat(deps.getAll(), is(equalTo((Set) ImmutableSet.of(
59                  "A", "B", "C", "D",
60                  "E", "F", "G", "H",
61                  "I", "J", "K", "L", "X"
62          ))));
63      }
64  
65      @Test
66      public void testGetByPluginKey() throws Exception {
67          Multimap<String, Type> actual = deps.getByPluginKey();
68          Multimap<String, Type> expected = ImmutableMultimap.<String, Type>builder()
69                  .put("A", DYNAMIC)
70                  .put("B", DYNAMIC)
71                  .put("C", DYNAMIC)
72                  .put("D", DYNAMIC)
73                  .put("X", DYNAMIC)
74                  .put("E", OPTIONAL)
75                  .put("F", OPTIONAL)
76                  .put("G", OPTIONAL)
77                  .put("H", OPTIONAL)
78                  .put("X", OPTIONAL)
79                  .put("I", MANDATORY)
80                  .put("J", MANDATORY)
81                  .put("K", MANDATORY)
82                  .put("L", MANDATORY)
83                  .put("X", MANDATORY)
84                  .build();
85  
86          assertThat(actual.entries(), containsInAnyOrder(expected.entries().toArray()));
87      }
88  }