|
5 | 5 | */
|
6 | 6 | package com.github.jknack.handlebars.cache;
|
7 | 7 |
|
8 |
| -import static org.junit.Assert.assertEquals; |
| 8 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
9 | 9 | import static org.mockito.ArgumentMatchers.any;
|
10 | 10 | import static org.mockito.ArgumentMatchers.eq;
|
11 | 11 | import static org.mockito.ArgumentMatchers.same;
|
|
17 | 17 | import java.util.concurrent.Callable;
|
18 | 18 | import java.util.concurrent.ExecutionException;
|
19 | 19 |
|
20 |
| -import org.junit.Test; |
| 20 | +import org.junit.jupiter.api.Assertions; |
| 21 | +import org.junit.jupiter.api.Test; |
21 | 22 |
|
22 | 23 | import com.github.jknack.handlebars.HandlebarsException;
|
23 | 24 | import com.github.jknack.handlebars.Parser;
|
@@ -108,50 +109,63 @@ public void clear() throws IOException {
|
108 | 109 | }
|
109 | 110 |
|
110 | 111 | @SuppressWarnings("unchecked")
|
111 |
| - @Test(expected = IllegalStateException.class) |
| 112 | + @Test |
112 | 113 | public void executionExceptionWithRuntimeException() throws IOException, ExecutionException {
|
113 |
| - TemplateSource source = mock(TemplateSource.class); |
| 114 | + Assertions.assertThrows( |
| 115 | + IllegalStateException.class, |
| 116 | + () -> { |
| 117 | + TemplateSource source = mock(TemplateSource.class); |
114 | 118 |
|
115 |
| - Parser parser = mock(Parser.class); |
| 119 | + Parser parser = mock(Parser.class); |
116 | 120 |
|
117 |
| - Cache<TemplateSource, Template> cache = mock(Cache.class); |
118 |
| - when(cache.get(eq(source), any(Callable.class))) |
119 |
| - .thenThrow(new ExecutionException(new IllegalStateException())); |
| 121 | + Cache<TemplateSource, Template> cache = mock(Cache.class); |
| 122 | + when(cache.get(eq(source), any(Callable.class))) |
| 123 | + .thenThrow(new ExecutionException(new IllegalStateException())); |
120 | 124 |
|
121 |
| - new GuavaTemplateCache(cache).get(source, parser); |
| 125 | + new GuavaTemplateCache(cache).get(source, parser); |
122 | 126 |
|
123 |
| - verify(cache).get(eq(source), any(Callable.class)); |
| 127 | + verify(cache).get(eq(source), any(Callable.class)); |
| 128 | + }); |
124 | 129 | }
|
125 | 130 |
|
126 | 131 | @SuppressWarnings("unchecked")
|
127 |
| - @Test(expected = Error.class) |
| 132 | + @Test |
128 | 133 | public void executionExceptionWithError() throws IOException, ExecutionException {
|
129 |
| - TemplateSource source = mock(TemplateSource.class); |
| 134 | + Assertions.assertThrows( |
| 135 | + Error.class, |
| 136 | + () -> { |
| 137 | + TemplateSource source = mock(TemplateSource.class); |
130 | 138 |
|
131 |
| - Parser parser = mock(Parser.class); |
| 139 | + Parser parser = mock(Parser.class); |
132 | 140 |
|
133 |
| - Cache<TemplateSource, Template> cache = mock(Cache.class); |
134 |
| - when(cache.get(eq(source), any(Callable.class))).thenThrow(new ExecutionException(new Error())); |
| 141 | + Cache<TemplateSource, Template> cache = mock(Cache.class); |
| 142 | + when(cache.get(eq(source), any(Callable.class))) |
| 143 | + .thenThrow(new ExecutionException(new Error())); |
135 | 144 |
|
136 |
| - new GuavaTemplateCache(cache).get(source, parser); |
| 145 | + new GuavaTemplateCache(cache).get(source, parser); |
137 | 146 |
|
138 |
| - verify(cache).get(eq(source), any(Callable.class)); |
| 147 | + verify(cache).get(eq(source), any(Callable.class)); |
| 148 | + }); |
139 | 149 | }
|
140 | 150 |
|
141 | 151 | @SuppressWarnings("unchecked")
|
142 |
| - @Test(expected = HandlebarsException.class) |
| 152 | + @Test |
143 | 153 | public void executionExceptionWithCheckedException() throws IOException, ExecutionException {
|
144 |
| - TemplateSource source = mock(TemplateSource.class); |
| 154 | + Assertions.assertThrows( |
| 155 | + HandlebarsException.class, |
| 156 | + () -> { |
| 157 | + TemplateSource source = mock(TemplateSource.class); |
145 | 158 |
|
146 |
| - Parser parser = mock(Parser.class); |
| 159 | + Parser parser = mock(Parser.class); |
147 | 160 |
|
148 |
| - Cache<TemplateSource, Template> cache = mock(Cache.class); |
149 |
| - when(cache.get(eq(source), any(Callable.class))) |
150 |
| - .thenThrow(new ExecutionException(new IOException())); |
| 161 | + Cache<TemplateSource, Template> cache = mock(Cache.class); |
| 162 | + when(cache.get(eq(source), any(Callable.class))) |
| 163 | + .thenThrow(new ExecutionException(new IOException())); |
151 | 164 |
|
152 |
| - new GuavaTemplateCache(cache).get(source, parser); |
| 165 | + new GuavaTemplateCache(cache).get(source, parser); |
153 | 166 |
|
154 |
| - verify(cache).get(eq(source), any(Callable.class)); |
| 167 | + verify(cache).get(eq(source), any(Callable.class)); |
| 168 | + }); |
155 | 169 | }
|
156 | 170 |
|
157 | 171 | private TemplateSource source(final String filename) throws IOException {
|
|
0 commit comments