Skip to content

Commit 8ebb075

Browse files
committed
FileClassPathEntry does not exist throws IllegalStateException
Closes gh-84
1 parent 802b7a7 commit 8ebb075

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

spring-boot-testjars/src/main/java/org/springframework/experimental/boot/server/exec/FileClasspathEntry.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ public FileClasspathEntry(File file) {
3333
}
3434

3535
public List<String> resolve() {
36-
return Arrays.asList(this.file.getAbsolutePath());
36+
String absolutePath = this.file.getAbsolutePath();
37+
if (!this.file.exists()) {
38+
throw new IllegalStateException("Could not find file to add to the classpath '" + absolutePath + "'");
39+
}
40+
return Arrays.asList(absolutePath);
3741
}
3842

3943
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2012-2023 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.experimental.boot.server.exec;
18+
19+
import java.io.File;
20+
21+
import org.junit.jupiter.api.Test;
22+
23+
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
24+
25+
class FileClasspathEntryTests {
26+
27+
@Test
28+
void resolveWhenDoesNotExist() {
29+
File doesNotExist = new File("does-not-exist");
30+
FileClasspathEntry notFoundEntry = new FileClasspathEntry(doesNotExist);
31+
assertThatIllegalStateException().isThrownBy(notFoundEntry::resolve)
32+
.withMessageContaining("Could not find file to add to the classpath");
33+
}
34+
35+
}

0 commit comments

Comments
 (0)