From 1f18b3a051e228a74ec404e8ec535e680a6dac0e Mon Sep 17 00:00:00 2001 From: Krzysiek Date: Sun, 15 Dec 2019 19:29:08 +0100 Subject: [PATCH] BAEL-3651: [Do Not Merge] Add diagnostic logging --- .../com/baeldung/file/FileClassUnitTest.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/core-java-modules/core-java-io-apis/src/test/java/com/baeldung/file/FileClassUnitTest.java b/core-java-modules/core-java-io-apis/src/test/java/com/baeldung/file/FileClassUnitTest.java index 57e12560bb..326d01b49c 100644 --- a/core-java-modules/core-java-io-apis/src/test/java/com/baeldung/file/FileClassUnitTest.java +++ b/core-java-modules/core-java-io-apis/src/test/java/com/baeldung/file/FileClassUnitTest.java @@ -1,15 +1,21 @@ package com.baeldung.file; + import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.io.*; import java.util.Arrays; import java.util.List; +import java.util.StringJoiner; import static org.junit.Assert.*; public class FileClassUnitTest { + private static final Logger log = LoggerFactory.getLogger("FileClassUnitTest"); + @Test public void givenDir_whenMkdir_thenDirIsDeleted() { File directory = new File("dir"); @@ -137,11 +143,17 @@ public class FileClassUnitTest { public void givenDataWritten_whenWrite_thenFreeSpaceReduces() { String home = System.getProperty("user.home"); + log.info("user.home: " + home); String sep = File.separator; File testDir = makeDir(home + sep + "test"); + log.info("testDir: " + testDir.toString()); File sample = new File(testDir, "sample.txt"); + log.info("sample: " + sample.toString()); long freeSpaceBefore = testDir.getFreeSpace(); + log.info("freeSpaceBefore: " + freeSpaceBefore); + + log.info("testDir list before: " + getListOfFiles(testDir)); try { writeSampleDataToFile(sample); } catch (IOException e) { @@ -149,11 +161,21 @@ public class FileClassUnitTest { } long freeSpaceAfter = testDir.getFreeSpace(); + log.info("freeSpaceAfter: " + freeSpaceAfter); + log.info("testDir list after: " + getListOfFiles(testDir)); assertTrue(freeSpaceAfter < freeSpaceBefore); removeDir(testDir); } + private String getListOfFiles(File dir){ + String list = ""; + for(String l : dir.list()){ + list += " _ " + l; + } + return list; + } + private static File makeDir(String name) { File directory = new File(name); directory.mkdir();