Add a test to FlatFileDatabaseManagerTest (more to come)

This commit is contained in:
nossr50 2021-04-08 13:31:07 -07:00
parent 483d23c04d
commit ccf5f30011

View File

@ -6,6 +6,7 @@ import com.google.common.io.Files;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.junit.After; import org.junit.After;
import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
@ -16,7 +17,6 @@ import java.io.*;
import java.util.logging.Logger; import java.util.logging.Logger;
@PrepareForTest({GeneralConfig.class})
@RunWith(PowerMockRunner.class) @RunWith(PowerMockRunner.class)
public class FlatFileDatabaseManagerTest { public class FlatFileDatabaseManagerTest {
@ -28,14 +28,12 @@ public class FlatFileDatabaseManagerTest {
@Before @Before
public void init() { public void init() {
logger.info("Preparing new test...");
tempDir = Files.createTempDir(); tempDir = Files.createTempDir();
flatFileDatabaseManager = new FlatFileDatabaseManager(tempDir.getPath() + File.separator + TEST_FILE_NAME, logger, PURGE_TIME, 0); flatFileDatabaseManager = new FlatFileDatabaseManager(tempDir.getPath() + File.separator + TEST_FILE_NAME, logger, PURGE_TIME, 0);
} }
@After @After
public void tearDown() { public void tearDown() {
logger.info("Tearing down after test...");
TestUtil.recursiveDelete(tempDir); TestUtil.recursiveDelete(tempDir);
flatFileDatabaseManager = null; flatFileDatabaseManager = null;
} }
@ -55,11 +53,10 @@ public class FlatFileDatabaseManagerTest {
@Test @Test
public void testPurgePowerlessUsers() { public void testPurgePowerlessUsers() {
// logger.info("testPurgePowerlessUsers"); Assert.assertNotNull(flatFileDatabaseManager);
// Assert.assertNotNull(flatFileDatabaseManager); addDataToFile(flatFileDatabaseManager, normalDatabaseData);
// addDataToFile(flatFileDatabaseManager, normalDatabaseData); int purgeCount = flatFileDatabaseManager.purgePowerlessUsers();
// int purgeCount = flatFileDatabaseManager.purgePowerlessUsers(); Assert.assertEquals(purgeCount, 1); //1 User should have been purged
// Assert.assertEquals(purgeCount, 1); //1 User should have been purged
} }
private void addDataToFile(@NotNull FlatFileDatabaseManager flatFileDatabaseManager, @NotNull String[] dataEntries) { private void addDataToFile(@NotNull FlatFileDatabaseManager flatFileDatabaseManager, @NotNull String[] dataEntries) {
@ -68,7 +65,6 @@ public class FlatFileDatabaseManagerTest {
FileWriter out = null; FileWriter out = null;
try { try {
StringBuilder writer = new StringBuilder(); StringBuilder writer = new StringBuilder();
for(String data : dataEntries) { for(String data : dataEntries) {
@ -79,7 +75,7 @@ public class FlatFileDatabaseManagerTest {
out.write(writer.toString()); out.write(writer.toString());
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
e.printStackTrace(); e.printStackTrace();
logger.severe("File not found"); System.out.println("File not found");
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} finally { } finally {
@ -94,12 +90,12 @@ public class FlatFileDatabaseManagerTest {
} }
try { try {
logger.info("Added the following lines to the FlatFileDatabase for the purposes of the test..."); System.out.println("Added the following lines to the FlatFileDatabase for the purposes of the test...");
// Open the file // Open the file
in = new BufferedReader(new FileReader(filePath)); in = new BufferedReader(new FileReader(filePath));
String line; String line;
while ((line = in.readLine()) != null) { while ((line = in.readLine()) != null) {
logger.info(line); System.out.println(line);
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();