Skip to content

Commit 0f571b3

Browse files
author
Vincent Potucek
committed
Pull apache#2292: Modernize codebase with Java improvements - functionalize DefaultModelProcessor#read
1 parent ebe1e37 commit 0f571b3

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

impl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public Model read(XmlReaderRequest request) throws IOException {
114114
}
115115
try {
116116
return doRead(request);
117-
} catch (IOException e) {
117+
} catch (Exception e) {
118118
exceptions.forEach(e::addSuppressed);
119119
throw e;
120120
}
@@ -134,7 +134,7 @@ else if (Files.isDirectory(project)) {
134134
return project;
135135
}
136136

137-
private Model doRead(XmlReaderRequest request) throws IOException {
137+
private Model doRead(XmlReaderRequest request) {
138138
return modelXmlFactory.read(request);
139139
}
140140
}

impl/maven-impl/src/test/java/org/apache/maven/impl/model/DefaultModelProcessorTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,27 @@ void readNullPomPathShouldUseFactoryDirectly() throws Exception {
8383
assertEquals(model, result);
8484
}
8585

86+
@Test
87+
void readNullPomPathShouldUseFactoryDirectly22() throws Exception {
88+
ModelXmlFactory factory = mock(ModelXmlFactory.class);
89+
ModelParser parser1 = mock(ModelParser.class);
90+
ModelParser parser2 = mock(ModelParser.class);
91+
XmlReaderRequest request = mock(XmlReaderRequest.class);
92+
Path pomPath = Path.of("project/pom.xml");
93+
when(request.getPath()).thenReturn(pomPath);
94+
when(request.isStrict()).thenReturn(true);
95+
96+
Model expectedModel = mock(Model.class);
97+
98+
// Both parsers return empty
99+
when(parser1.locateAndParse(any(), any())).thenReturn(Optional.empty());
100+
when(parser2.locateAndParse(any(), any())).thenReturn(Optional.empty());
101+
// Factory returns model
102+
when(factory.read(request)).thenThrow(new IllegalStateException(new IOException()));
103+
assertThrows(
104+
IllegalStateException.class, () -> new DefaultModelProcessor(factory, List.of()).read(request));
105+
}
106+
86107
@Test
87108
void locateExistingPomWithParsersShouldReturnFirstValid() {
88109
Path expectedPom = Path.of("project/pom.xml");

0 commit comments

Comments
 (0)