View Javadoc

1   package com.atlassian.plugins.rest.module.expand.resolver;
2   
3   import com.atlassian.plugin.osgi.factory.OsgiPlugin;
4   import com.atlassian.plugins.rest.common.expand.EntityCrawler;
5   import com.atlassian.plugins.rest.common.expand.EntityExpander;
6   import com.atlassian.plugins.rest.common.expand.ExpandContext;
7   import com.atlassian.plugins.rest.common.expand.Expander;
8   import com.atlassian.plugins.rest.common.expand.resolver.EntityExpanderResolver;
9   
10  import static org.junit.Assert.*;
11  
12  import org.junit.Before;
13  import org.junit.Test;
14  
15  import static org.mockito.Mockito.mock;
16  import static org.mockito.Mockito.when;
17  
18  /**
19   * Testing {@link PluginEntityExpanderResolver}
20   */
21  public class OsgiPluginEntityExpanderResolverTest
22  {
23      private PluginEntityExpanderResolver resolver;
24      private EntityExpander entityExpander;
25  
26      @Before
27      public void setUp() throws Exception
28      {
29          entityExpander = mock(AnnotatedClassEntityExpander.class);
30          OsgiPlugin osgiPlugin = mock(OsgiPlugin.class);
31          when(osgiPlugin.autowire(AnnotatedClassEntityExpander.class)).thenReturn((AnnotatedClassEntityExpander) entityExpander);
32  
33          resolver = new PluginEntityExpanderResolver(osgiPlugin);
34      }
35  
36      @Test
37      public void testConstructorWithNullPlugin()
38      {
39          try
40          {
41              new PluginEntityExpanderResolver(null);
42              fail();
43          }
44          catch (NullPointerException e)
45          {
46              // expected
47          }
48      }
49  
50      @Test
51      public void testHasExpanderWithNullClass()
52      {
53          try
54          {
55              final Class clazz = null;
56              resolver.hasExpander(clazz);
57              fail();
58          }
59          catch (NullPointerException e)
60          {
61              // expected
62          }
63      }
64  
65      @Test
66      public void testHasExpanderWithAnnotatedClass()
67      {
68          assertTrue(resolver.hasExpander(AnnotatedClass.class));
69      }
70  
71      @Test
72      public void testHasExpanderWithNonAnnotatedClass()
73      {
74          assertFalse(resolver.hasExpander(Object.class));
75      }
76  
77      @Test
78      public void testGetExpanderWithAnnotatedClass()
79      {
80          assertEquals(entityExpander, resolver.getExpander(AnnotatedClass.class));
81      }
82  
83      @Test
84      public void testGetExpanderWithNonAnnotatedClass()
85      {
86          assertNull(resolver.getExpander(Object.class));
87      }
88  
89      @Expander(AnnotatedClassEntityExpander.class)
90      private static class AnnotatedClass
91      {
92      }
93  
94      private static class AnnotatedClassEntityExpander implements EntityExpander<AnnotatedClass>
95      {
96          public AnnotatedClass expand(ExpandContext expandContext, EntityExpanderResolver expanderResolver, EntityCrawler entityCrawler)
97          {
98              return null;
99          }
100     }
101 }