View Javadoc
1   package de.juplo.httpresources;
2   
3   import mockit.Expectations;
4   import mockit.Injectable;
5   import mockit.Mocked;
6   import mockit.Verifications;
7   import static org.junit.Assert.assertEquals;
8   import static org.junit.Assert.assertNull;
9   import org.junit.Before;
10  import org.junit.Test;
11  import org.springframework.core.io.Resource;
12  import org.springframework.core.io.ResourceLoader;
13  
14  
15  /**
16   *
17   * @author kai
18   */
19  public class HttpResourceProtocolResolverTest
20  {
21    @Injectable
22    HttpResources resources;
23  
24    HttpResourceProtocolResolver reslover;
25  
26    @Before
27    public void setUp()
28    {
29      reslover = new HttpResourceProtocolResolver(resources);
30    }
31  
32  
33    @Test
34    public void testHttpResource(
35        @Mocked ResourceLoader loader,
36        @Mocked HttpResource resource
37        )
38    {
39      String location = "http://remote/";
40  
41      new Expectations() {{
42        resources.getResource(location); result = resource;
43      }};
44  
45      Resource result = reslover.resolve(location, loader);
46  
47      assertEquals(resource, result);
48      new Verifications() {{
49        resources.getResource(location); times = 1;
50      }};
51    }
52  
53    @Test
54    public void testHttpsResource(
55        @Mocked ResourceLoader loader,
56        @Mocked HttpResource resource
57        )
58    {
59      String location = "https://remote/";
60  
61      new Expectations() {{
62        resources.getResource(location); result = resource;
63      }};
64  
65      Resource result = reslover.resolve(location, loader);
66  
67      assertEquals(resource, result);
68      new Verifications() {{
69        resources.getResource(location); times = 1;
70      }};
71    }
72  
73    @Test
74    public void testClasspathResource(@Mocked ResourceLoader loader)
75    {
76      String location = "classpath:/static/";
77  
78      Resource result = reslover.resolve(location, loader);
79  
80      assertNull(result);
81      new Verifications() {{
82        resources.getResource(location); times = 0;
83      }};
84    }
85  }