|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2015 the original author or authors. |
| 2 | + * Copyright 2012-2016 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
16 | 16 |
|
17 | 17 | package org.springframework.boot.autoconfigure.mustache.web;
|
18 | 18 |
|
| 19 | +import java.io.InputStream; |
19 | 20 | import java.util.Locale;
|
20 | 21 |
|
| 22 | +import org.fusesource.hawtbuf.ByteArrayInputStream; |
21 | 23 | import org.junit.Before;
|
22 | 24 | import org.junit.Test;
|
23 | 25 |
|
| 26 | +import org.springframework.core.io.Resource; |
24 | 27 | import org.springframework.mock.web.MockServletContext;
|
25 | 28 | import org.springframework.web.context.support.StaticWebApplicationContext;
|
26 | 29 | import org.springframework.web.servlet.View;
|
|
29 | 32 | import static org.junit.Assert.assertNotNull;
|
30 | 33 | import static org.junit.Assert.assertNull;
|
31 | 34 | import static org.junit.Assert.assertThat;
|
| 35 | +import static org.mockito.BDDMockito.given; |
| 36 | +import static org.mockito.Mockito.mock; |
| 37 | +import static org.mockito.Mockito.spy; |
| 38 | +import static org.mockito.Mockito.verify; |
32 | 39 |
|
33 | 40 | /**
|
34 | 41 | * Tests for {@link MustacheViewResolver}.
|
35 | 42 | *
|
36 | 43 | * @author Dave Syer
|
| 44 | + * @author Andy Wilkinson |
37 | 45 | */
|
38 | 46 | public class MustacheViewResolverTests {
|
39 | 47 |
|
@@ -85,4 +93,24 @@ public void setsContentType() throws Exception {
|
85 | 93 |
|
86 | 94 | }
|
87 | 95 |
|
| 96 | + @Test |
| 97 | + public void templateResourceInputStreamIsClosed() throws Exception { |
| 98 | + final Resource resource = mock(Resource.class); |
| 99 | + given(resource.exists()).willReturn(true); |
| 100 | + InputStream inputStream = new ByteArrayInputStream(new byte[0]); |
| 101 | + InputStream spyInputStream = spy(inputStream); |
| 102 | + given(resource.getInputStream()).willReturn(spyInputStream); |
| 103 | + this.resolver = new MustacheViewResolver(); |
| 104 | + this.resolver.setApplicationContext(new StaticWebApplicationContext() { |
| 105 | + |
| 106 | + @Override |
| 107 | + public Resource getResource(String location) { |
| 108 | + return resource; |
| 109 | + } |
| 110 | + |
| 111 | + }); |
| 112 | + this.resolver.loadView("foo", null); |
| 113 | + verify(spyInputStream).close(); |
| 114 | + } |
| 115 | + |
88 | 116 | }
|
0 commit comments