Skip to content

Commit 42ae388

Browse files
committed
[code review] mark path parameter as non-nullable
1 parent daf881a commit 42ae388

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

src/main/java/net/datafaker/service/FakeValuesService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,9 @@ private FakeValuesInterface getCachedFakeValue(SingletonLocale locale) {
106106
* @param path path to a file with YAML structure
107107
* @throws IllegalArgumentException in case of invalid path
108108
*/
109-
public void addPath(Locale locale, @Nullable Path path) {
109+
public void addPath(Locale locale, Path path) {
110110
requireNonNull(locale);
111+
//noinspection ConstantValue
111112
if (path == null || Files.notExists(path) || Files.isDirectory(path) || !Files.isReadable(path)) {
112113
throw new IllegalArgumentException("Path should be an existing readable file: \"%s\"".formatted(path));
113114
}

src/test/java/net/datafaker/providers/base/CustomFakerTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,18 @@ public String bee() {
7070
}
7171

7272
@Test
73+
@SuppressWarnings("DataFlowIssue")
7374
void addNullExistingPath() {
7475
assertThatThrownBy(() -> new BaseFaker().addPath(Locale.ENGLISH, null))
75-
.isInstanceOf(IllegalArgumentException.class);
76+
.isInstanceOf(IllegalArgumentException.class)
77+
.hasMessage("Path should be an existing readable file: \"null\"");
7678
}
7779

7880
@Test
7981
void addNonExistingPath() {
8082
assertThatThrownBy(() -> new BaseFaker().addPath(Locale.ENGLISH, Paths.get("non-existing-file")))
81-
.isInstanceOf(IllegalArgumentException.class);
83+
.isInstanceOf(IllegalArgumentException.class)
84+
.hasMessage("Path should be an existing readable file: \"non-existing-file\"");
8285
}
8386

8487
@RepeatedTest(10)

0 commit comments

Comments
 (0)