Skip to content

Commit

Permalink
Codacy issues in test
Browse files Browse the repository at this point in the history
Codacy did not like my test in several points:
- The function name may not have an underscore (`_`).
- Magic number (`123`) should be replaced with a named constant.
- File should end with a new line.

Signed-off-by: Elv1zz <elv1zz.git@gmail.com>
  • Loading branch information
Elv1zz authored and tobiasKaminsky committed Jan 23, 2024
1 parent fbb0bdc commit c9b913b
Showing 1 changed file with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,48 @@ import com.owncloud.android.lib.common.network.AdvancedX509KeyManager.AKMAlias
import org.junit.Assert
import org.junit.Test

private const val PORT_SAME = 123
private const val PORT_OTHER = 1234

private const val ALIAS_SAME = "alias"
private const val ALIAS_OTHER = "alias1"

private const val HOST_SAME = "hostname"
private const val HOST_OTHER = "hostname1"

class AdvancedX509KeyManagerTests {

@Test
fun testAKMAlias_matches() {
val akmAlias1 = AKMAlias(AKMAlias.Type.KEYCHAIN, "alias", "hostname", 123)
val akmAlias2 = AKMAlias(AKMAlias.Type.KEYCHAIN, "alias", "hostname", 123)
fun testAKMAliasMatches() {
val akmAlias1 = AKMAlias(AKMAlias.Type.KEYCHAIN, ALIAS_SAME, HOST_SAME, PORT_SAME)
val akmAlias2 = AKMAlias(AKMAlias.Type.KEYCHAIN, ALIAS_SAME, HOST_SAME, PORT_SAME)

Assert.assertTrue(akmAlias1.matches(akmAlias1))
Assert.assertTrue(akmAlias1.matches(akmAlias2))

val akmAlias3 = AKMAlias(AKMAlias.Type.KEYSTORE, "alias", "hostname", 123)
val akmAlias3 = AKMAlias(AKMAlias.Type.KEYSTORE, ALIAS_SAME, HOST_SAME, PORT_SAME)
Assert.assertFalse(akmAlias1.matches(akmAlias3))

val akmAlias4 = AKMAlias(AKMAlias.Type.KEYCHAIN, "alias1", "hostname", 123)
val akmAlias4 = AKMAlias(AKMAlias.Type.KEYCHAIN, ALIAS_OTHER, HOST_SAME, PORT_SAME)
Assert.assertFalse(akmAlias1.matches(akmAlias4))

val akmAlias5 = AKMAlias(AKMAlias.Type.KEYCHAIN, "alias", "hostname1", 123)
val akmAlias5 = AKMAlias(AKMAlias.Type.KEYCHAIN, ALIAS_SAME, HOST_OTHER, PORT_SAME)
Assert.assertFalse(akmAlias1.matches(akmAlias5))

val akmAlias6 = AKMAlias(AKMAlias.Type.KEYCHAIN, "alias", "hostname", 1234)
val akmAlias6 = AKMAlias(AKMAlias.Type.KEYCHAIN, ALIAS_SAME, HOST_SAME, PORT_OTHER)
Assert.assertFalse(akmAlias1.matches(akmAlias6))

// parameters being null are considered "do-not-care"
val akmAlias7 = AKMAlias(null, "alias", "hostname", 123)
val akmAlias7 = AKMAlias(null, ALIAS_SAME, HOST_SAME, PORT_SAME)
Assert.assertTrue(akmAlias1.matches(akmAlias7))

val akmAlias8 = AKMAlias(AKMAlias.Type.KEYCHAIN, null, "hostname", 123)
val akmAlias8 = AKMAlias(AKMAlias.Type.KEYCHAIN, null, HOST_SAME, PORT_SAME)
Assert.assertTrue(akmAlias1.matches(akmAlias8))

val akmAlias9 = AKMAlias(AKMAlias.Type.KEYCHAIN, "alias", null, 123)
val akmAlias9 = AKMAlias(AKMAlias.Type.KEYCHAIN, ALIAS_SAME, null, PORT_SAME)
Assert.assertTrue(akmAlias1.matches(akmAlias9))

val akmAlias10 = AKMAlias(null, null, null, 123)
val akmAlias10 = AKMAlias(null, null, null, PORT_SAME)
Assert.assertTrue(akmAlias1.matches(akmAlias10))

}

}
}

0 comments on commit c9b913b

Please sign in to comment.