-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit-test for SolidExportedDocument
- Loading branch information
Showing
5 changed files
with
164 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
aat-android/src/test/kotlin/ch/bailu/aat/preferences/MockStorage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package ch.bailu.aat.preferences | ||
|
||
import ch.bailu.aat_lib.preferences.OnPreferencesChanged | ||
import ch.bailu.aat_lib.preferences.StorageInterface | ||
|
||
class MockStorage : StorageInterface { | ||
var mockIntValue: Int = 0 | ||
var mockStringValue = "" | ||
var mockLongValue: Long = 0L | ||
|
||
|
||
override fun readString(key: String): String { | ||
return mockStringValue | ||
} | ||
|
||
override fun writeString(key: String, value: String) { | ||
mockStringValue = value | ||
} | ||
|
||
override fun readInteger(key: String): Int { | ||
return mockIntValue | ||
} | ||
|
||
override fun writeInteger(key: String, value: Int) { | ||
mockIntValue = value | ||
} | ||
|
||
override fun writeIntegerForce(key: String, value: Int) { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun readLong(key: String): Long { | ||
return mockLongValue | ||
} | ||
|
||
override fun writeLong(key: String, value: Long) { | ||
mockLongValue = value | ||
} | ||
|
||
override fun register(onPreferencesChanged: OnPreferencesChanged) { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun unregister(onPreferencesChanged: OnPreferencesChanged) { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun isDefaultString(s: String): Boolean { | ||
return s.isEmpty() | ||
} | ||
|
||
override fun getDefaultString(): String { | ||
return "" | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
aat-android/src/test/kotlin/ch/bailu/aat/preferences/SolidExportedDocumentTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package ch.bailu.aat.preferences | ||
|
||
import ch.bailu.foc.FocFile | ||
import junit.framework.TestCase.assertEquals | ||
import junit.framework.TestCase.assertTrue | ||
import org.junit.Test | ||
|
||
|
||
class SolidExportedDocumentTest { | ||
|
||
@Test | ||
fun testSetValueFromString() { | ||
val mockStorage = MockStorage() | ||
|
||
val exportedDocument = SolidExportedDocument(mockStorage) | ||
|
||
assertEquals(false, exportedDocument.isExportAllowed(testFile1)) | ||
|
||
exportedDocument.setValueFromString(testFile1) | ||
|
||
assertEquals(true, exportedDocument.isExportAllowed(testFile1)) | ||
assertEquals(false, exportedDocument.isExportAllowed(testFileEmpty)) | ||
assertEquals(false, exportedDocument.isExportAllowed(testFile2)) | ||
|
||
assertTrue(mockStorage.mockLongValue > 0) | ||
mockStorage.mockLongValue -= LIMIT_MILLIS | ||
|
||
assertEquals(false, exportedDocument.isExportAllowed(testFile1)) | ||
} | ||
|
||
|
||
@Test | ||
fun testSetValue() { | ||
val mockStorage = MockStorage() | ||
|
||
val exportedDocument = SolidExportedDocument(mockStorage) | ||
|
||
assertEquals(false, exportedDocument.isExportAllowed(testFile1)) | ||
|
||
exportedDocument.setValue(testFile1) | ||
|
||
assertEquals(true, exportedDocument.isExportAllowed(testFile1)) | ||
assertEquals(false, exportedDocument.isExportAllowed(testFileEmpty)) | ||
assertEquals(false, exportedDocument.isExportAllowed(testFile2)) | ||
|
||
assertTrue(mockStorage.mockLongValue > 0) | ||
mockStorage.mockLongValue -= LIMIT_MILLIS | ||
|
||
assertEquals(false, exportedDocument.isExportAllowed(testFile1)) | ||
} | ||
|
||
@Test | ||
fun testSetDocument() { | ||
val mockStorage = MockStorage() | ||
|
||
val exportedDocument = SolidExportedDocument(mockStorage) | ||
|
||
assertEquals(false, exportedDocument.isExportAllowed(testFile1)) | ||
|
||
exportedDocument.setDocument(FocFile(testFile1)) | ||
|
||
assertEquals(true, exportedDocument.isExportAllowed(testFile1)) | ||
assertEquals(false, exportedDocument.isExportAllowed(testFileEmpty)) | ||
assertEquals(false, exportedDocument.isExportAllowed(testFile2)) | ||
|
||
assertTrue(mockStorage.mockLongValue > 0) | ||
mockStorage.mockLongValue -= LIMIT_MILLIS | ||
|
||
assertEquals(false, exportedDocument.isExportAllowed(testFile1)) | ||
} | ||
|
||
|
||
@Test | ||
fun testEmpty() { | ||
val mockStorage = MockStorage() | ||
|
||
val exportedDocument = SolidExportedDocument(mockStorage) | ||
|
||
mockStorage.mockLongValue = System.currentTimeMillis() + LIMIT_MILLIS | ||
|
||
assertEquals(false, exportedDocument.isExportAllowed(testFileEmpty)) | ||
|
||
exportedDocument.setValueFromString(testFileEmpty) | ||
|
||
assertEquals(true, exportedDocument.isExportAllowed(testFileEmpty)) | ||
assertEquals(false, exportedDocument.isExportAllowed(testFile1)) | ||
assertEquals(false, exportedDocument.isExportAllowed(testFile2)) | ||
|
||
assertTrue(mockStorage.mockLongValue > 0) | ||
mockStorage.mockLongValue -= LIMIT_MILLIS | ||
|
||
assertEquals(false, exportedDocument.isExportAllowed(testFileEmpty)) | ||
} | ||
|
||
companion object { | ||
const val testFile1 = "/storage/path/file.gpx" | ||
const val testFile2 = "/storage/path/file1.gpx" | ||
const val testFileEmpty = "" | ||
const val LIMIT_MILLIS = 30 * 1000 // 1/2 minute | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters