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