|
35 | 35 | import org.junit.jupiter.api.io.TempDir; |
36 | 36 |
|
37 | 37 | import static org.assertj.core.api.AssertionsForClassTypes.assertThat; |
38 | | -import static org.junit.jupiter.api.Assertions.assertEquals; |
39 | | -import static org.junit.jupiter.api.Assertions.assertInstanceOf; |
40 | | -import static org.junit.jupiter.api.Assertions.assertNotNull; |
41 | | -import static org.junit.jupiter.api.Assertions.assertNull; |
42 | | -import static org.junit.jupiter.api.Assertions.assertThrows; |
43 | | -import static org.junit.jupiter.api.Assertions.assertTrue; |
| 38 | +import static org.junit.jupiter.api.Assertions.*; |
44 | 39 | import static org.mockito.Mockito.any; |
45 | 40 | import static org.mockito.Mockito.mock; |
46 | 41 | import static org.mockito.Mockito.when; |
@@ -233,7 +228,28 @@ void locateExistingPomShouldRejectPomInDifferentDirectory() { |
233 | 228 |
|
234 | 229 |
|
235 | 230 |
|
| 231 | + @Test |
| 232 | + void readWithParserThrowingModelParserExceptionShouldAddAsSuppressed() throws Exception { |
| 233 | + ModelXmlFactory factory = mock(ModelXmlFactory.class); |
| 234 | + ModelParser parser = mock(ModelParser.class); |
| 235 | + XmlReaderRequest request = mock(XmlReaderRequest.class); |
| 236 | + Path pomPath = Path.of("project/pom.xml"); |
| 237 | + when(request.getPath()).thenReturn(pomPath); |
| 238 | + when(request.isStrict()).thenReturn(true); |
| 239 | + |
| 240 | + ModelParserException parserException = new ModelParserException("Parser error"); |
| 241 | + when(parser.locateAndParse(any(), any())).thenThrow(parserException); |
| 242 | + |
| 243 | + Model expectedModel = mock(Model.class); |
| 244 | + when(factory.read(request)).thenReturn(expectedModel); |
| 245 | + |
| 246 | + Model result = new DefaultModelProcessor(factory, List.of(parser)).read(request); |
| 247 | + |
| 248 | + assertSame(expectedModel, result); |
| 249 | + // In this case, since factory succeeds, no exception is thrown |
| 250 | + } |
236 | 251 |
|
237 | 252 |
|
238 | 253 |
|
| 254 | + |
239 | 255 | } |
0 commit comments