|
|
@ -34,6 +34,7 @@ import java.util.zip.ZipFile
|
|
|
|
|
|
|
|
|
|
|
|
class HabitsCSVExporterTest : BaseUnitTest() {
|
|
|
|
class HabitsCSVExporterTest : BaseUnitTest() {
|
|
|
|
private lateinit var baseDir: File
|
|
|
|
private lateinit var baseDir: File
|
|
|
|
|
|
|
|
|
|
|
|
@Before
|
|
|
|
@Before
|
|
|
|
@Throws(Exception::class)
|
|
|
|
@Throws(Exception::class)
|
|
|
|
override fun setUp() {
|
|
|
|
override fun setUp() {
|
|
|
@ -41,12 +42,7 @@ class HabitsCSVExporterTest : BaseUnitTest() {
|
|
|
|
habitList.add(fixtures.createShortHabit())
|
|
|
|
habitList.add(fixtures.createShortHabit())
|
|
|
|
habitList.add(fixtures.createEmptyHabit())
|
|
|
|
habitList.add(fixtures.createEmptyHabit())
|
|
|
|
baseDir = Files.createTempDirectory("csv").toFile()
|
|
|
|
baseDir = Files.createTempDirectory("csv").toFile()
|
|
|
|
}
|
|
|
|
baseDir.deleteOnExit()
|
|
|
|
|
|
|
|
|
|
|
|
@Throws(Exception::class)
|
|
|
|
|
|
|
|
override fun tearDown() {
|
|
|
|
|
|
|
|
FileUtils.deleteDirectory(baseDir)
|
|
|
|
|
|
|
|
super.tearDown()
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -63,14 +59,20 @@ class HabitsCSVExporterTest : BaseUnitTest() {
|
|
|
|
assertAbsolutePathExists(filename)
|
|
|
|
assertAbsolutePathExists(filename)
|
|
|
|
val archive = File(filename)
|
|
|
|
val archive = File(filename)
|
|
|
|
unzip(archive)
|
|
|
|
unzip(archive)
|
|
|
|
assertPathExists("Habits.csv")
|
|
|
|
val filesToCheck = arrayOf(
|
|
|
|
assertPathExists("001 Meditate/Checkmarks.csv")
|
|
|
|
"001 Meditate/Checkmarks.csv",
|
|
|
|
assertPathExists("001 Meditate/Scores.csv")
|
|
|
|
"001 Meditate/Scores.csv",
|
|
|
|
assertPathExists("002 Wake up early")
|
|
|
|
"002 Wake up early/Checkmarks.csv",
|
|
|
|
assertPathExists("002 Wake up early/Checkmarks.csv")
|
|
|
|
"002 Wake up early/Scores.csv",
|
|
|
|
assertPathExists("002 Wake up early/Scores.csv")
|
|
|
|
"Checkmarks.csv",
|
|
|
|
assertPathExists("Checkmarks.csv")
|
|
|
|
"Habits.csv",
|
|
|
|
assertPathExists("Scores.csv")
|
|
|
|
"Scores.csv"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (file in filesToCheck) {
|
|
|
|
|
|
|
|
assertPathExists(file)
|
|
|
|
|
|
|
|
assertFileAndReferenceAreEqual(file)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Throws(IOException::class)
|
|
|
|
@Throws(IOException::class)
|
|
|
@ -104,4 +106,18 @@ class HabitsCSVExporterTest : BaseUnitTest() {
|
|
|
|
file.exists()
|
|
|
|
file.exists()
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun assertFileAndReferenceAreEqual(s: String) {
|
|
|
|
|
|
|
|
val assetFilename = String.format("csv_export/%s", s)
|
|
|
|
|
|
|
|
val file = File.createTempFile("asset", "")
|
|
|
|
|
|
|
|
file.deleteOnExit()
|
|
|
|
|
|
|
|
copyAssetToFile(assetFilename, file)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertTrue(
|
|
|
|
|
|
|
|
FileUtils.contentEquals(
|
|
|
|
|
|
|
|
file,
|
|
|
|
|
|
|
|
File(String.format("%s/%s", baseDir.absolutePath, s))
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|