From 12e2da99fa3d9e4af411bd10b635604ec7557efd Mon Sep 17 00:00:00 2001 From: Devin Bileck <603793+devinbileck@users.noreply.github.com> Date: Mon, 10 Feb 2020 13:25:00 -0800 Subject: [PATCH 1/3] Close stream writer prior to deleting temp file On Windows, instantiating the stream writer appears to lock the file, preventing the file from being deleted. This was causing the assertion that the file is deleted to fail. --- .../src/test/java/bisq/common/config/ConfigFileEditorTests.java | 2 ++ .../src/test/java/bisq/common/config/ConfigFileReaderTests.java | 1 + 2 files changed, 3 insertions(+) diff --git a/common/src/test/java/bisq/common/config/ConfigFileEditorTests.java b/common/src/test/java/bisq/common/config/ConfigFileEditorTests.java index d1b0ed4f057..4819c1bd840 100644 --- a/common/src/test/java/bisq/common/config/ConfigFileEditorTests.java +++ b/common/src/test/java/bisq/common/config/ConfigFileEditorTests.java @@ -29,6 +29,7 @@ public void setUp() throws IOException { @Test public void whenFileDoesNotExist_thenSetOptionCreatesItAndAppendsOneLine() { + writer.close(); assertTrue(file.delete()); editor.setOption("opt1", "val1"); @@ -111,6 +112,7 @@ public void whenFileDoesNotContainOptionBeingCleared_thenClearOptionIsNoOp() { @Test public void whenFileDoesNotExist_thenClearOptionIsNoOp() { + writer.close(); assertTrue(file.delete()); editor.clearOption("opt1"); assertFalse(file.exists()); diff --git a/common/src/test/java/bisq/common/config/ConfigFileReaderTests.java b/common/src/test/java/bisq/common/config/ConfigFileReaderTests.java index ceffb6acae5..e0076bc822b 100644 --- a/common/src/test/java/bisq/common/config/ConfigFileReaderTests.java +++ b/common/src/test/java/bisq/common/config/ConfigFileReaderTests.java @@ -32,6 +32,7 @@ public void setUp() throws IOException { @Test public void whenFileDoesNotExist_thenGetLinesThrows() { + writer.close(); assertTrue(file.delete()); exception.expect(ConfigException.class); From d0eb759065506cbc72a56f81ff66aa3b15a25f3d Mon Sep 17 00:00:00 2001 From: Devin Bileck <603793+devinbileck@users.noreply.github.com> Date: Mon, 10 Feb 2020 13:34:55 -0800 Subject: [PATCH 2/3] Use proper file path on Windows On Windows, the exception message contained backwards slashes causing the test to fail. --- .../java/bisq/common/config/ConfigTests.java | 16 ++++++++++++---- .../bisq/common/util/PreconditionsTests.java | 8 ++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/common/src/test/java/bisq/common/config/ConfigTests.java b/common/src/test/java/bisq/common/config/ConfigTests.java index 91554893881..6b2577645fd 100644 --- a/common/src/test/java/bisq/common/config/ConfigTests.java +++ b/common/src/test/java/bisq/common/config/ConfigTests.java @@ -115,16 +115,24 @@ public void whenUnrecognizedOptionIsSet_thenConfigExceptionIsThrown() { @Test public void whenOptionFileArgumentDoesNotExist_thenConfigExceptionIsThrown() { + String filepath = "/does/not/exist"; + if (System.getProperty("os.name").startsWith("Windows")) { + filepath = "C:\\does\\not\\exist"; + } exceptionRule.expect(ConfigException.class); - exceptionRule.expectMessage("problem parsing option 'torrcFile': File [/does/not/exist] does not exist"); - configWithOpts(opt(TORRC_FILE, "/does/not/exist")); + exceptionRule.expectMessage(String.format("problem parsing option 'torrcFile': File [%s] does not exist", filepath)); + configWithOpts(opt(TORRC_FILE, filepath)); } @Test public void whenConfigFileOptionIsSetToNonExistentFile_thenConfigExceptionIsThrown() { + String filepath = "/no/such/bisq.properties"; + if (System.getProperty("os.name").startsWith("Windows")) { + filepath = "C:\\no\\such\\bisq.properties"; + } exceptionRule.expect(ConfigException.class); - exceptionRule.expectMessage("The specified config file '/no/such/bisq.properties' does not exist"); - configWithOpts(opt(CONFIG_FILE, "/no/such/bisq.properties")); + exceptionRule.expectMessage(String.format("The specified config file '%s' does not exist", filepath)); + configWithOpts(opt(CONFIG_FILE, filepath)); } @Test diff --git a/common/src/test/java/bisq/common/util/PreconditionsTests.java b/common/src/test/java/bisq/common/util/PreconditionsTests.java index cd590fba8cb..23616faf47c 100644 --- a/common/src/test/java/bisq/common/util/PreconditionsTests.java +++ b/common/src/test/java/bisq/common/util/PreconditionsTests.java @@ -27,8 +27,12 @@ public void whenDirIsValid_thenDirIsReturned() throws IOException { @Test public void whenDirDoesNotExist_thenThrow() { + String filepath = "/does/not/exist"; + if (System.getProperty("os.name").startsWith("Windows")) { + filepath = "C:\\does\\not\\exist"; + } exceptionRule.expect(IllegalArgumentException.class); - exceptionRule.expectMessage(equalTo("Directory '/does/not/exist' does not exist")); - checkDir(new File("/does/not/exist")); + exceptionRule.expectMessage(equalTo(String.format("Directory '%s' does not exist", filepath))); + checkDir(new File(filepath)); } } From cb9cb659d6ef987aa749112d646af69d2b6e08a7 Mon Sep 17 00:00:00 2001 From: Devin Bileck <603793+devinbileck@users.noreply.github.com> Date: Mon, 10 Feb 2020 13:47:58 -0800 Subject: [PATCH 3/3] Resolve codacy issues --- common/src/test/java/bisq/common/config/ConfigTests.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/src/test/java/bisq/common/config/ConfigTests.java b/common/src/test/java/bisq/common/config/ConfigTests.java index 6b2577645fd..017fe6c9bd1 100644 --- a/common/src/test/java/bisq/common/config/ConfigTests.java +++ b/common/src/test/java/bisq/common/config/ConfigTests.java @@ -120,7 +120,7 @@ public void whenOptionFileArgumentDoesNotExist_thenConfigExceptionIsThrown() { filepath = "C:\\does\\not\\exist"; } exceptionRule.expect(ConfigException.class); - exceptionRule.expectMessage(String.format("problem parsing option 'torrcFile': File [%s] does not exist", filepath)); + exceptionRule.expectMessage(format("problem parsing option 'torrcFile': File [%s] does not exist", filepath)); configWithOpts(opt(TORRC_FILE, filepath)); } @@ -131,7 +131,7 @@ public void whenConfigFileOptionIsSetToNonExistentFile_thenConfigExceptionIsThro filepath = "C:\\no\\such\\bisq.properties"; } exceptionRule.expect(ConfigException.class); - exceptionRule.expectMessage(String.format("The specified config file '%s' does not exist", filepath)); + exceptionRule.expectMessage(format("The specified config file '%s' does not exist", filepath)); configWithOpts(opt(CONFIG_FILE, filepath)); }