Skip to content

Commit

Permalink
test(accesspoints, core, testsupport): issue164 - Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
isuPatches committed Jan 14, 2023
1 parent 0e31ca0 commit b3369fc
Show file tree
Hide file tree
Showing 36 changed files with 3,152 additions and 89 deletions.
17 changes: 17 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ jobs:
name: android/android-machine
steps:
- checkout
- restore_cache:
key: jars-{{ checksum "build.gradle.kts" }}-{{ checksum "app/build.gradle.kts" }}-{{ checksum "wisefy/build.gradle.kts" }}
- run:
name: Download Dependencies
command: ./gradlew androidDependencies
- write-keystore-files
- import-gpg-key
- publish-to-maven-local
Expand All @@ -83,6 +88,18 @@ jobs:
- run:
name: Assemble release build
command: ./gradlew assembleRelease
- run:
name: Run unit tests with coverage
command: ./gradlew jacocoDebugUnitTest
- store_test_results:
path: wisefy/accesspoints/build/test-results/testDebugUnitTest
- store_artifacts:
path: wisefy/accesspoints/build/reports/jacoco/jacocoDebugUnitTest/html
destination: wisefy/accesspoints/unitTestCoverageReport
- save_cache:
paths:
- ~/.gradle
key: jars-{{ checksum "build.gradle.kts" }}-{{ checksum "app/build.gradle.kts" }}-{{ checksum "wisefy/build.gradle.kts" }}

workflows:
wisefy-ci-cd:
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ dependencies {
// implementation(project(":wisefy:ktx"))

/*
* This should be uncommented to run sample app directly against release versions of wisefy / wisefy-ktx
* This should be uncommented to run sample app directly against release versions of wisefy-ktx
*/
implementation("com.isupatches.android.wisefy:ktx:${BuildVersions.WISEFY_KTX_VERSION}")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.isupatches.android.wisefy.accesspoints.entities.AccessPointData
import com.isupatches.android.wisefy.accesspoints.entities.SecurityCapability
import com.isupatches.android.wisefy.core.constants.MAX_FREQUENCY_5_GHZ
import com.isupatches.android.wisefy.core.entities.AuthenticationAlgorithm
import com.isupatches.android.wisefy.core.entities.KeyManagementAlgorithm
import com.isupatches.android.wisefy.core.entities.PairwiseCipher
import com.isupatches.android.wisefy.sample.R
import com.isupatches.android.wisefy.sample.ui.components.WisefySampleBodyLabel
import com.isupatches.android.wisefy.sample.ui.components.WisefySampleSubHeaderLabel
Expand Down Expand Up @@ -110,9 +113,23 @@ private fun AccessPointRow(accessPoint: AccessPointUIData) {
}
Row {
WisefySampleBodyLabel(
stringResId = R.string.access_point_security_capabilities_args,
stringResId = R.string.access_point_authentication_algorithms_args,
modifier = Modifier.padding(top = WisefySampleSizes.Medium),
accessPoint.securityCapabilities
accessPoint.authenticationAlgorithms
)
}
Row {
WisefySampleBodyLabel(
stringResId = R.string.access_point_key_management_algorithms_args,
modifier = Modifier.padding(top = WisefySampleSizes.Medium),
accessPoint.keyManagementAlgorithms
)
}
Row {
WisefySampleBodyLabel(
stringResId = R.string.access_point_pairwise_ciphers_args,
modifier = Modifier.padding(top = WisefySampleSizes.Medium),
accessPoint.pairwiseCiphers
)
}
Row {
Expand Down Expand Up @@ -145,9 +162,13 @@ private fun NearbyAccessPointsScreenContentLightPreview() {
),
isSavedBySSID = false,
isSavedByBSSID = false,
securityCapabilities = SecurityCapability.ALL.associateWith {
authenticationAlgorithms = AuthenticationAlgorithm.ALL.associateWith {
false
}
},
keyManagementAlgorithms = KeyManagementAlgorithm.ALL.associateWith {
false
},
pairwiseCiphers = PairwiseCipher.ALL.associateWith { false }
)
)
}
Expand All @@ -169,13 +190,17 @@ private fun NearbyAccessPointsScreenContentDarkPreview() {
},
ssid = "",
bssid = "",
frequency = 4900
frequency = MAX_FREQUENCY_5_GHZ
),
isSavedBySSID = false,
isSavedByBSSID = false,
securityCapabilities = SecurityCapability.ALL.associateWith {
authenticationAlgorithms = AuthenticationAlgorithm.ALL.associateWith {
false
}
},
keyManagementAlgorithms = KeyManagementAlgorithm.ALL.associateWith {
false
},
pairwiseCiphers = PairwiseCipher.ALL.associateWith { false }
)
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ import com.isupatches.android.wisefy.WisefyApi
import com.isupatches.android.wisefy.accesspoints.entities.AccessPointData
import com.isupatches.android.wisefy.accesspoints.entities.GetAccessPointsQuery
import com.isupatches.android.wisefy.accesspoints.entities.GetAccessPointsResult
import com.isupatches.android.wisefy.accesspoints.entities.SecurityCapability
import com.isupatches.android.wisefy.accesspoints.entities.containSecurityCapability
import com.isupatches.android.wisefy.accesspoints.entities.supportsAuthenticationAlgorithm
import com.isupatches.android.wisefy.accesspoints.entities.supportsKeyManagementAlgorithm
import com.isupatches.android.wisefy.accesspoints.entities.supportsPairwiseCipher
import com.isupatches.android.wisefy.core.entities.AuthenticationAlgorithm
import com.isupatches.android.wisefy.core.entities.KeyManagementAlgorithm
import com.isupatches.android.wisefy.core.entities.PairwiseCipher
import com.isupatches.android.wisefy.core.exceptions.WisefyException
import com.isupatches.android.wisefy.ktx.isNetworkSavedAsync
import com.isupatches.android.wisefy.sample.scaffolding.BaseViewModel
Expand Down Expand Up @@ -90,16 +94,28 @@ internal class DefaultNearbyAccessPointsViewModel(
IsNetworkSavedResult.True -> true
IsNetworkSavedResult.False -> false
}
val securityCapabilityMap = mutableMapOf<SecurityCapability, Boolean>()
SecurityCapability.ALL.forEach { securityCapability ->
securityCapabilityMap[securityCapability] =
accessPoint.containSecurityCapability(securityCapability)
val authenticationAlgorithmMap = mutableMapOf<AuthenticationAlgorithm, Boolean>()
AuthenticationAlgorithm.ALL.forEach { authenticationAlgorithm ->
authenticationAlgorithmMap[authenticationAlgorithm] =
accessPoint.supportsAuthenticationAlgorithm(authenticationAlgorithm)
}
val keyManagementAlgorithmMap = mutableMapOf<KeyManagementAlgorithm, Boolean>()
KeyManagementAlgorithm.ALL.forEach { keyManagementAlgorithm ->
keyManagementAlgorithmMap[keyManagementAlgorithm] =
accessPoint.supportsKeyManagementAlgorithm(keyManagementAlgorithm)
}
val pairwiseCipherMap = mutableMapOf<PairwiseCipher, Boolean>()
PairwiseCipher.ALL.forEach { pairwiseCipher ->
pairwiseCipherMap[pairwiseCipher] =
accessPoint.supportsPairwiseCipher(pairwiseCipher)
}
AccessPointUIData(
accessPoint = accessPoint,
isSavedBySSID = isSavedBySSID,
isSavedByBSSID = isSavedByBSSID,
securityCapabilities = securityCapabilityMap
authenticationAlgorithms = authenticationAlgorithmMap,
keyManagementAlgorithms = keyManagementAlgorithmMap,
pairwiseCiphers = pairwiseCipherMap
)
}
_uiState.value = NearbyAccessPointsUIState(
Expand Down Expand Up @@ -144,5 +160,7 @@ internal data class AccessPointUIData(
val accessPoint: AccessPointData,
val isSavedBySSID: Boolean,
val isSavedByBSSID: Boolean,
val securityCapabilities: Map<SecurityCapability, Boolean>
val authenticationAlgorithms: Map<AuthenticationAlgorithm, Boolean>,
val keyManagementAlgorithms: Map<KeyManagementAlgorithm, Boolean>,
val pairwiseCiphers: Map<PairwiseCipher, Boolean>
)
4 changes: 3 additions & 1 deletion app/src/main/res/values/misc.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@
<string name="access_point_raw_value_args">%s</string>
<string name="access_point_is_saved_by_ssid_args">Saved by SSID: %b</string>
<string name="access_point_is_saved_by_bssid_args">Saved by BSSID: %b</string>
<string name="access_point_security_capabilities_args">Security capabilities: %s</string>
<string name="access_point_authentication_algorithms_args">Authentication Algorithms: %s</string>
<string name="access_point_key_management_algorithms_args">Key Management Algorithms: %s</string>
<string name="access_point_pairwise_ciphers_args">Pairwise Ciphers: %s</string>

<!-- Permissions -->
<string name="permission_error_disable_wifi">Permissions for disabling wifi are denied</string>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2022 Patches Barrett
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.isupatches.android.wisefy.build

object TestDependencies {
const val JUNIT: String = "junit:junit:${Versions.JUNIT}"

object Mockito {
const val CORE: String = "org.mockito:mockito-core:${Versions.MOCKITO}"
const val ANDROID: String = "org.mockito:mockito-android:${Versions.MOCKITO}"
}

object Kotlin {
object Coroutines {
const val TEST: String = "org.jetbrains.kotlinx:kotlinx-coroutines-test:" +
Versions.KOTLIN_TEST
}
}

object AndroidX {
const val TEST_RUNNER: String = "androidx.test:runner:${Versions.ANDROIDX_TEST_RUNNER}"
const val TEST_RULES: String = "androidx.test:rules:${Versions.ANDROIDX_TEST_RULES}"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,13 @@ object Versions {

// Code Coverage
const val JACOCO: String = "0.8.8"

// Unit Tests
const val KOTLIN_TEST: String = "1.6.4"
const val JUNIT: String = "4.13.2"
const val MOCKITO: String = "4.11.0"

// Instrumentation Tests
const val ANDROIDX_TEST_RULES: String = "1.5.0"
const val ANDROIDX_TEST_RUNNER: String = "1.5.1"
}
2 changes: 2 additions & 0 deletions config/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ exceptions:
- 'NumberFormatException'
- 'ParseException'
allowedExceptionNameRegex: '_|(ignore|expected).*'
excludes: [ '**/test/**', '**/androidTest/**']
ThrowingExceptionFromFinally:
active: true
ThrowingExceptionInMain:
Expand Down Expand Up @@ -316,6 +317,7 @@ naming:
FunctionMaxLength:
active: true
maximumFunctionNameLength: 50
excludes: [ '**/test/**', '**/androidTest/**']
FunctionMinLength:
active: true
minimumFunctionNameLength: 1
Expand Down
8 changes: 4 additions & 4 deletions gradle/jacoco.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ afterEvaluate {
classDirectories.setFrom(getClassDirectoriesTree(excludes))
sourceDirectories.setFrom(getSourceDirectoriesTree())
executionData.setFrom(
fileTree("${project.buildDir}/jacoco") {
fileTree("${project.buildDir}/outputs/unit_test_code_coverage") {
include("**/*.exec")
}
)
Expand All @@ -57,7 +57,7 @@ afterEvaluate {
classDirectories.setFrom(getClassDirectoriesTree(excludes))
sourceDirectories.setFrom(getSourceDirectoriesTree())
executionData.setFrom(
fileTree("${project.buildDir}/jacoco") {
fileTree("${project.buildDir}/outputs/unit_test_code_coverage") {
include("**/*.exec")
}
)
Expand Down Expand Up @@ -112,7 +112,7 @@ afterEvaluate {
classDirectories.setFrom(getClassDirectoriesTree(excludes))
sourceDirectories.setFrom(getSourceDirectoriesTree())
executionData.setFrom(
fileTree("${project.buildDir}/jacoco") {
fileTree("${project.buildDir}/outputs/unit_test_code_coverage") {
include("**/*.exec")
},
fileTree("${project.buildDir}/outputs/code_coverage/") {
Expand All @@ -132,7 +132,7 @@ afterEvaluate {
classDirectories.setFrom(getClassDirectoriesTree(excludes))
sourceDirectories.setFrom(getSourceDirectoriesTree())
executionData.setFrom(
fileTree("${project.buildDir}/jacoco") {
fileTree("${project.buildDir}/outputs/unit_test_code_coverage") {
include("**/*.exec")
},
fileTree("${project.buildDir}/outputs/code_coverage/") {
Expand Down
3 changes: 2 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ include(
":wisefy:savednetworks",
":wisefy:removenetwork",
":wisefy:signal",
":wisefy:wifi"
":wisefy:wifi",
":testsupport"
)
1 change: 1 addition & 0 deletions testsupport/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
18 changes: 18 additions & 0 deletions testsupport/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import com.isupatches.android.wisefy.build.TestDependencies

plugins {
id("com.android.library")
id("com.isupatches.android.wisefy.build.plugins.BaseGradleModulePlugin")
id("kotlin-android")
}

android {
namespace = "com.isupatches.android.wisefy.testsupport"
}

dependencies {
implementation(project(":wisefy:core"))

implementation(TestDependencies.Mockito.CORE)
implementation(TestDependencies.Kotlin.Coroutines.TEST)
}
55 changes: 55 additions & 0 deletions testsupport/gradle.lockfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# This is a Gradle generated file for dependency locking.
# Manual edits can break the build and are not advised.
# This file is expected to be part of source control.
androidx.activity:activity:1.5.1=debugRuntimeClasspath,releaseRuntimeClasspath
androidx.annotation:annotation-experimental:1.1.0=debugRuntimeClasspath,releaseRuntimeClasspath
androidx.annotation:annotation:1.5.0=debugRuntimeClasspath,releaseRuntimeClasspath
androidx.appcompat:appcompat-resources:1.5.1=debugRuntimeClasspath,releaseRuntimeClasspath
androidx.appcompat:appcompat:1.5.1=debugRuntimeClasspath,releaseRuntimeClasspath
androidx.arch.core:core-common:2.1.0=debugRuntimeClasspath,releaseRuntimeClasspath
androidx.arch.core:core-runtime:2.1.0=debugRuntimeClasspath,releaseRuntimeClasspath
androidx.collection:collection:1.1.0=debugRuntimeClasspath,releaseRuntimeClasspath
androidx.concurrent:concurrent-futures:1.0.0=debugRuntimeClasspath,releaseRuntimeClasspath
androidx.core:core-ktx:1.8.0=debugRuntimeClasspath,releaseRuntimeClasspath
androidx.core:core:1.8.0=debugRuntimeClasspath,releaseRuntimeClasspath
androidx.cursoradapter:cursoradapter:1.0.0=debugRuntimeClasspath,releaseRuntimeClasspath
androidx.customview:customview:1.0.0=debugRuntimeClasspath,releaseRuntimeClasspath
androidx.drawerlayout:drawerlayout:1.0.0=debugRuntimeClasspath,releaseRuntimeClasspath
androidx.emoji2:emoji2-views-helper:1.2.0=debugRuntimeClasspath,releaseRuntimeClasspath
androidx.emoji2:emoji2:1.2.0=debugRuntimeClasspath,releaseRuntimeClasspath
androidx.fragment:fragment:1.3.6=debugRuntimeClasspath,releaseRuntimeClasspath
androidx.interpolator:interpolator:1.0.0=debugRuntimeClasspath,releaseRuntimeClasspath
androidx.lifecycle:lifecycle-common:2.5.1=debugRuntimeClasspath,releaseRuntimeClasspath
androidx.lifecycle:lifecycle-livedata-core:2.5.1=debugRuntimeClasspath,releaseRuntimeClasspath
androidx.lifecycle:lifecycle-livedata:2.0.0=debugRuntimeClasspath,releaseRuntimeClasspath
androidx.lifecycle:lifecycle-process:2.4.1=debugRuntimeClasspath,releaseRuntimeClasspath
androidx.lifecycle:lifecycle-runtime:2.5.1=debugRuntimeClasspath,releaseRuntimeClasspath
androidx.lifecycle:lifecycle-viewmodel-savedstate:2.5.1=debugRuntimeClasspath,releaseRuntimeClasspath
androidx.lifecycle:lifecycle-viewmodel:2.5.1=debugRuntimeClasspath,releaseRuntimeClasspath
androidx.loader:loader:1.0.0=debugRuntimeClasspath,releaseRuntimeClasspath
androidx.resourceinspection:resourceinspection-annotation:1.0.1=debugRuntimeClasspath,releaseRuntimeClasspath
androidx.savedstate:savedstate:1.2.0=debugRuntimeClasspath,releaseRuntimeClasspath
androidx.startup:startup-runtime:1.1.1=debugRuntimeClasspath,releaseRuntimeClasspath
androidx.tracing:tracing:1.0.0=debugRuntimeClasspath,releaseRuntimeClasspath
androidx.vectordrawable:vectordrawable-animated:1.1.0=debugRuntimeClasspath,releaseRuntimeClasspath
androidx.vectordrawable:vectordrawable:1.1.0=debugRuntimeClasspath,releaseRuntimeClasspath
androidx.versionedparcelable:versionedparcelable:1.1.1=debugRuntimeClasspath,releaseRuntimeClasspath
androidx.viewpager:viewpager:1.0.0=debugRuntimeClasspath,releaseRuntimeClasspath
com.google.guava:listenablefuture:1.0=debugRuntimeClasspath,releaseRuntimeClasspath
net.bytebuddy:byte-buddy-agent:1.12.19=debugRuntimeClasspath,releaseRuntimeClasspath
net.bytebuddy:byte-buddy:1.12.19=debugRuntimeClasspath,releaseRuntimeClasspath
org.jacoco:org.jacoco.agent:0.8.8=debugRuntimeClasspath
org.jetbrains.kotlin:kotlin-stdlib-common:1.7.20=debugRuntimeClasspath,releaseRuntimeClasspath
org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.6.21=debugRuntimeClasspath,releaseRuntimeClasspath
org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.6.21=debugRuntimeClasspath,releaseRuntimeClasspath
org.jetbrains.kotlin:kotlin-stdlib:1.7.20=debugRuntimeClasspath,releaseRuntimeClasspath
org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4=debugRuntimeClasspath,releaseRuntimeClasspath
org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.6.4=debugRuntimeClasspath,releaseRuntimeClasspath
org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm:1.6.4=debugRuntimeClasspath,releaseRuntimeClasspath
org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4=debugRuntimeClasspath,releaseRuntimeClasspath
org.jetbrains.kotlinx:kotlinx-coroutines-test-jvm:1.6.4=debugRuntimeClasspath,releaseRuntimeClasspath
org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4=debugRuntimeClasspath,releaseRuntimeClasspath
org.jetbrains:annotations:13.0=debugRuntimeClasspath,releaseRuntimeClasspath
org.mockito:mockito-core:4.11.0=debugRuntimeClasspath,releaseRuntimeClasspath
org.objenesis:objenesis:3.3=debugRuntimeClasspath,releaseRuntimeClasspath
empty=
2 changes: 2 additions & 0 deletions testsupport/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest />
Loading

0 comments on commit b3369fc

Please sign in to comment.