-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add key handle helper methods to android api
- Loading branch information
Showing
7 changed files
with
130 additions
and
57 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
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
21 changes: 18 additions & 3 deletions
21
android/trifle/src/androidTest/java/app/cash/trifle/KeyHandleTest.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 |
---|---|---|
@@ -1,12 +1,27 @@ | ||
package app.cash.trifle | ||
|
||
import com.google.common.truth.Truth.assertThat | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Assert.assertThrows | ||
import org.junit.Before | ||
import org.junit.Test | ||
|
||
|
||
class KeyHandleTest { | ||
private lateinit var keyHandle: KeyHandle | ||
@Before fun setUp() { | ||
keyHandle = TrifleApi.generateKeyHandle("test-alias") | ||
} | ||
|
||
@Test fun serializeDeserialize() { | ||
val keyHandle = KeyHandle.generateKeyHandle("test-alias") | ||
val serializedBytes = keyHandle.serialize() | ||
assertThat(KeyHandle.deserialize(serializedBytes)).isEqualTo(keyHandle) | ||
assertEquals(KeyHandle.deserialize(serializedBytes), keyHandle) | ||
} | ||
|
||
@Test fun failsDeserializationDueToDeletedKeyHandle() { | ||
val serializedBytes = keyHandle.serialize() | ||
KeyHandle.deleteAlias(keyHandle.alias) | ||
assertThrows(IllegalStateException::class.java) { | ||
KeyHandle.deserialize(serializedBytes) | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
android/trifle/src/androidTest/java/app/cash/trifle/TrifleApiTest.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,38 @@ | ||
package app.cash.trifle | ||
|
||
import org.junit.Assert.assertFalse | ||
import org.junit.Assert.assertNotNull | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.rules.ExpectedException | ||
|
||
|
||
class TrifleApiTest { | ||
@JvmField | ||
@Rule | ||
val thrown: ExpectedException = ExpectedException.none() | ||
|
||
private lateinit var keyHandle: KeyHandle | ||
@Before fun setUp() { | ||
keyHandle = TrifleApi.generateKeyHandle("test-alias") | ||
} | ||
|
||
@Test fun testGenerateKeyHandle() { | ||
assertNotNull(keyHandle) | ||
} | ||
|
||
@Test fun testIsValid_forCreatedKeyHandle_returnsTrue() { | ||
assertTrue(TrifleApi.isValid(keyHandle)) | ||
} | ||
|
||
@Test fun testIsValid_forDeletedKeyHandle_returnsFalse() { | ||
TrifleApi.delete(keyHandle) | ||
assertFalse(TrifleApi.isValid(keyHandle)) | ||
} | ||
|
||
@Test fun testDeleteKeyHandle() { | ||
TrifleApi.delete(keyHandle) | ||
} | ||
} |
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