Move testfolder cleaning to TestInit

This commit is contained in:
Rsl1122 2017-08-23 17:25:12 +03:00
parent 05e06ebb76
commit 6998def8df
3 changed files with 14 additions and 51 deletions

View File

@ -64,7 +64,6 @@ public class DatabaseTest {
db = new SQLiteDB(plan, "debug" + MiscUtils.getTime());
File f = new File(plan.getDataFolder(), "Errors.txt");
rows = FileUtil.lines(f).size();
db.init();
}
@ -230,10 +229,8 @@ public class DatabaseTest {
expected.add(new TPS(r.nextLong(), r.nextDouble(), r.nextInt(100000000), averageCPUUsage, usedMemory, entityCount, chunksLoaded));
expected.add(new TPS(r.nextLong(), r.nextDouble(), r.nextInt(100000000), averageCPUUsage, usedMemory, entityCount, chunksLoaded));
List<TPS> tpsDataOld = tpsTable.getTPSData();
tpsTable.saveTPSData(expected);
expected.addAll(0, tpsDataOld);
assertEquals(expected, tpsTable.getTPSData());
}
}

View File

@ -1,48 +0,0 @@
/*
* Licence is provided in the jar as license.yml also here:
* https://github.com/Rsl1122/Plan-PlayerAnalytics/blob/master/Plan/src/main/resources/license.yml
*/
package test.java.utils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import test.java.main.java.com.djrapitops.plan.database.DatabaseCommitTest;
import test.java.main.java.com.djrapitops.plan.database.DatabaseTest;
import java.io.File;
import java.io.IOException;
/**
* @author Fuzzlemann
*/
@RunWith(Suite.class)
@Suite.SuiteClasses({DatabaseCommitTest.class, DatabaseTest.class})
public class DBTestSuite {
@BeforeClass
public static void setUp() throws IOException {
clean(true);
}
@AfterClass
public static void tearDown() throws IOException {
clean(false);
}
private static void clean(boolean dbOnly) throws IOException {
File testFolder = TestInit.getTestFolder();
if (!testFolder.exists() || !testFolder.isDirectory()) {
return;
}
for (File f : testFolder.listFiles()) {
if (dbOnly && !f.getName().contains(".db")) {
continue;
}
f.delete();
}
}
}

View File

@ -67,6 +67,8 @@ public class TestInit {
}
private void setUp() throws Exception {
clean();
planMock = PowerMockito.mock(Plan.class);
StaticHolder.setInstance(Plan.class, planMock);
StaticHolder.setInstance(planMock.getClass(), planMock);
@ -193,4 +195,16 @@ public class TestInit {
public Plan getPlanMock() {
return planMock;
}
public static void clean() throws IOException {
File testFolder = getTestFolder();
if (!testFolder.exists() || !testFolder.isDirectory()) {
return;
}
for (File f : testFolder.listFiles()) {
f.delete();
}
}
}