1 package com.atlassian.plugins.rest.common.expand.resolver;
2
3 import com.atlassian.plugins.rest.common.expand.EntityCrawler;
4 import com.atlassian.plugins.rest.common.expand.EntityExpander;
5 import com.atlassian.plugins.rest.common.expand.ExpandContext;
6 import com.atlassian.plugins.rest.common.expand.Expander;
7 import static org.junit.Assert.*;
8 import org.junit.Before;
9 import org.junit.Test;
10 import static org.mockito.Mockito.mock;
11
12
13
14
15 public class AbstractAnnotationEntityExpanderResolverTest
16 {
17 private AbstractAnnotationEntityExpanderResolver resolver;
18 private EntityExpander entityExpander;
19
20 @Before
21 public void setUp() throws Exception
22 {
23 entityExpander = mock(EntityExpander.class);
24
25 resolver = new AbstractAnnotationEntityExpanderResolver()
26 {
27 protected EntityExpander<?> getEntityExpander(Expander e)
28 {
29 if (e.value().equals(AnnotatedClassEntityExpander.class))
30 {
31 return entityExpander;
32 }
33 fail("Should not have been called with a different expander");
34 return null;
35 }
36 };
37 }
38
39 @Test
40 public void testHasExpanderWithNullClass()
41 {
42 try
43 {
44 final Class clazz = null;
45 resolver.hasExpander(clazz);
46 fail();
47 }
48 catch (NullPointerException e)
49 {
50
51 }
52 }
53
54 @Test
55 public void testHasExpanderWithAnnotatedClass()
56 {
57 assertTrue(resolver.hasExpander(AnnotatedClass.class));
58 }
59
60 @Test
61 public void testHasExpanderWithNonAnnotatedClass()
62 {
63 assertFalse(resolver.hasExpander(Object.class));
64 }
65
66 @Test
67 public void testGetExpanderWithAnnotatedClass()
68 {
69 assertEquals(entityExpander, resolver.getExpander(AnnotatedClass.class));
70 }
71
72 @Test
73 public void testGetExpanderWithNonAnnotatedClass()
74 {
75 assertNull(resolver.getExpander(Object.class));
76 }
77
78 @Expander(AnnotatedClassEntityExpander.class)
79 private static class AnnotatedClass
80 {
81 }
82
83 private static class AnnotatedClassEntityExpander implements EntityExpander<AnnotatedClass>
84 {
85 public AnnotatedClass expand(ExpandContext expandContext, EntityExpanderResolver expanderResolver, EntityCrawler entityCrawler)
86 {
87 return null;
88 }
89 }
90 }