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  
22      private PluginDependencies deps;
23  
24      @Before
25      public void setUp() throws Exception {
26          deps = PluginDependencies.builder()
27                  .withDynamic("A")
28                  .withDynamic("B")
29                  .withDynamic("C", "D")
30                  .withOptional("E")
31                  .withOptional("F")
32                  .withOptional("G", "H")
33                  .withMandatory("I")
34                  .withMandatory("J")
35                  .withMandatory("K", "L")
36                  .withDynamic("X")
37                  .withMandatory("X")
38                  .withOptional("X")
39                  .build();
40      }
41  
42      @Test
43      public void testGetMandatory() {
44          assertThat(deps.getMandatory(), is(equalTo((Set) ImmutableSet.of("I", "J", "K", "L", "X"))));
45      }
46  
47      @Test
48      public void testGetOptional() {
49          assertThat(deps.getOptional(), is(equalTo((Set) ImmutableSet.of("E", "F", "G", "H", "X"))));
50      }
51  
52      @Test
53      public void testGetDynamic() {
54          assertThat(deps.getDynamic(), is(equalTo((Set) ImmutableSet.of("A", "B", "C", "D", "X"))));
55      }
56  
57      @Test
58      public void testGetAll() {
59          assertThat(deps.getAll(), is(equalTo((Set) ImmutableSet.of(
60                  "A", "B", "C", "D",
61                  "E", "F", "G", "H",
62                  "I", "J", "K", "L", "X"
63          ))));
64      }
65  
66      @Test
67      public void testGetByPluginKey() {
68          Multimap<String, Type> actual = deps.getByPluginKey();
69          Multimap<String, Type> expected = ImmutableMultimap.<String, Type>builder()
70                  .put("A", DYNAMIC)
71                  .put("B", DYNAMIC)
72                  .put("C", DYNAMIC)
73                  .put("D", DYNAMIC)
74                  .put("X", DYNAMIC)
75                  .put("E", OPTIONAL)
76                  .put("F", OPTIONAL)
77                  .put("G", OPTIONAL)
78                  .put("H", OPTIONAL)
79                  .put("X", OPTIONAL)
80                  .put("I", MANDATORY)
81                  .put("J", MANDATORY)
82                  .put("K", MANDATORY)
83                  .put("L", MANDATORY)
84                  .put("X", MANDATORY)
85                  .build();
86  
87          assertThat(actual.entries(), containsInAnyOrder(expected.entries().toArray()));
88      }
89  }