aboutsummaryrefslogtreecommitdiff
path: root/juick-server/src/test/java/com/juick/server
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-07-24 21:17:48 +0300
committerGravatar Vitaly Takmazov2018-07-24 21:17:48 +0300
commitee61f91b3e4541d405bd92c2ba2486ceb4c3b46f (patch)
tree1db72837cc9cc653033ed102acc989990ccd0541 /juick-server/src/test/java/com/juick/server
parent3fa18888d5ca53b59c778de3f829870614d05c27 (diff)
correctly cleanup temp files in tests
Diffstat (limited to 'juick-server/src/test/java/com/juick/server')
-rw-r--r--juick-server/src/test/java/com/juick/server/tests/ServerTests.java22
1 files changed, 13 insertions, 9 deletions
diff --git a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
index e4e5f298..824a10e5 100644
--- a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
@@ -1101,14 +1101,18 @@ public class ServerTests {
@Test
public void changeExtensionWhenReceiveFileWithWrongContentType() throws Exception {
Path pngOutput = Paths.get(tmpDir, "cmyk.png");
- Files.delete(pngOutput);
- Files.copy(getClass().getClassLoader().getResourceAsStream("cmyk.jpg"), pngOutput);
- assertThat(pngOutput.toFile().exists(), is(true));
- CommandResult postJpgCmyk = commandsManager.processCommand(ugnich, "YO", pngOutput.toUri());
- assertThat(postJpgCmyk.getNewMessage().isPresent(), is(true));
- assertThat(postJpgCmyk.getNewMessage().get().getAttachmentType(), is("jpg"));
- CommandResult replyJpgCmyk = commandsManager.processCommand(ugnich, String.format("#%d YO", postJpgCmyk.getNewMessage().get().getMid()), pngOutput.toUri());
- assertThat(replyJpgCmyk.getNewMessage().isPresent(), is(true));
- assertThat(replyJpgCmyk.getNewMessage().get().getAttachmentType(), is("jpg"));
+ Files.deleteIfExists(pngOutput);
+ try {
+ Files.copy(getClass().getClassLoader().getResourceAsStream("cmyk.jpg"), pngOutput);
+ assertThat(pngOutput.toFile().exists(), is(true));
+ CommandResult postJpgCmyk = commandsManager.processCommand(ugnich, "YO", pngOutput.toUri());
+ assertThat(postJpgCmyk.getNewMessage().isPresent(), is(true));
+ assertThat(postJpgCmyk.getNewMessage().get().getAttachmentType(), is("jpg"));
+ CommandResult replyJpgCmyk = commandsManager.processCommand(ugnich, String.format("#%d YO", postJpgCmyk.getNewMessage().get().getMid()), pngOutput.toUri());
+ assertThat(replyJpgCmyk.getNewMessage().isPresent(), is(true));
+ assertThat(replyJpgCmyk.getNewMessage().get().getAttachmentType(), is("jpg"));
+ } finally {
+ Files.deleteIfExists(pngOutput);
+ }
}
}