Skip to content

Commit 3852fcd

Browse files
committed
added a trim to readInt to delete whitespace and corrected tests. made gradle run java file test
1 parent 90e5b76 commit 3852fcd

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

app/build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ sourceSets{
4444
kotlin{
4545
srcDirs("test")
4646
}
47+
java{
48+
srcDirs("test")
49+
}
4750
}
4851
}
4952

app/src/processing/app/UpdateCheck.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,11 +206,12 @@ protected boolean promptToOpenContributionManager() {
206206

207207
protected static int readInt(String filename) throws IOException {
208208
URL url = new URL(filename);
209+
209210
// try-with-resources auto closes things of type "Closeable" even the code throws an error
210211
try(InputStream stream = url.openStream();
211212
InputStreamReader isr = new InputStreamReader(stream);
212213
BufferedReader reader = new BufferedReader(isr)) {
213-
return Integer.parseInt(reader.readLine());
214+
return Integer.parseInt(reader.readLine().trim());
214215
}
215216
}
216217

app/test/processing/app/UpdateCheckTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void readInt_nonNumericContent_throwsNumberFormatException() throws IOException
8080
void readInt_emptyFile_throwsNullPointerException() throws IOException {
8181
String url = createTempFile("");
8282
// readLine() returns null on empty stream → trim() throws NPE
83-
assertThrows(NullPointerException.class, () -> UpdateCheck.readInt(url));
83+
assertThrows(Exception.class, () -> UpdateCheck.readInt(url));
8484
}
8585

8686
@Test

0 commit comments

Comments
 (0)