From 355d84fd818a48c6232172eda0d646fa12480bf5 Mon Sep 17 00:00:00 2001 From: Elv1zz Date: Fri, 7 Jul 2023 21:50:59 +0200 Subject: [PATCH] Codacy issues in test 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 --- .../network/AdvancedX509KeyManagerTests.kt | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/library/src/test/java/com/owncloud/android/lib/common/network/AdvancedX509KeyManagerTests.kt b/library/src/test/java/com/owncloud/android/lib/common/network/AdvancedX509KeyManagerTests.kt index 56150c2401..ad37403025 100644 --- a/library/src/test/java/com/owncloud/android/lib/common/network/AdvancedX509KeyManagerTests.kt +++ b/library/src/test/java/com/owncloud/android/lib/common/network/AdvancedX509KeyManagerTests.kt @@ -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)) - } - -} \ No newline at end of file +}