Skip to content

Commit

Permalink
test(addnetwork): issue164 - Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
isuPatches committed Jan 22, 2023
1 parent b3369fc commit e55bf47
Show file tree
Hide file tree
Showing 20 changed files with 1,605 additions and 122 deletions.
99 changes: 64 additions & 35 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ orbs:
android: circleci/[email protected]

commands:
setup-dependencies:
steps:
- 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:
steps:
- run:
Expand Down Expand Up @@ -55,51 +62,73 @@ commands:
- run:
name: Pulblish wisefy:ktx to Maven Local
command: ./gradlew wisefy:ktx:publishToMavenLocal
run-static-analysis:
steps:
- run:
name: Run lint
command: ./gradlew lintDebug
- run:
name: Run Kotlinter
command: ./gradlew lintKotlin
- run:
name: Run detekt
command: ./gradlew detekt
- run:
name: Run CPD
command: ./gradlew cpdCheck
build-debug-build:
steps:
- run:
name: Assemble debug build
command: ./gradlew assembleDebug
build-release-build:
steps:
- run:
name: Assemble release build
command: ./gradlew assembleRelease
run-unit-tests:
steps:
- run:
name: Run unit tests with coverage
command: ./gradlew jacocoDebugUnitTest
store-unit-test-results:
steps:
- store_test_results:
path: wisefy/accesspoints/build/test-results/testDebugUnitTest
- store_test_results:
path: wisefy/addnetwork/build/test-results/testDebugUnitTest
store-code-coverage-reports:
steps:
- store_artifacts:
path: wisefy/accesspoints/build/reports/jacoco/jacocoDebugUnitTest/html
destination: wisefy/accesspoints/unitTestCoverageReport
- store_artifacts:
path: wisefy/addnetwork/build/reports/jacoco/jacocoDebugUnitTest/html
destination: wisefy/addnetwork/unitTestCoverageReport
cache-dependencies:
steps:
- save_cache:
paths:
- ~/.gradle
key: jars-{{ checksum "build.gradle.kts" }}-{{ checksum "app/build.gradle.kts" }}-{{ checksum "wisefy/build.gradle.kts" }}

jobs:
build-and-test:
executor:
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
- setup-dependencies
- write-keystore-files
- import-gpg-key
- publish-to-maven-local
- run:
name: Run lint
command: ./gradlew lintDebug
- run:
name: Run Kotlinter
command: ./gradlew lintKotlin
- run:
name: Run detekt
command: ./gradlew detekt
- run:
name: Run CPD
command: ./gradlew cpdCheck
- run:
name: Assemble debug build
command: ./gradlew assembleDebug
- 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" }}
- run-static-analysis
- build-debug-build
- build-release-build
- run-unit-tests
- store-unit-test-results
- store-code-coverage-reports
- cache-dependencies

workflows:
wisefy-ci-cd:
Expand Down
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

I'd love to have your help, but please don't skimp on greatness!

Please check the [Issues](https://github.com/isupatches/android-wisefy/issues) and the [Main Board](https://github.com/isuPatches/android-wisefy/projects/1) to make sure what you want is not already being worked on.
Please check the [Issues](https://github.com/isupatches/android-wisefy/issues) to make sure what you want is not already being worked on.

* Please create an issue and use the [Main Board](https://github.com/isuPatches/android-wisefy/projects/1) to denote its status
* Please create an issue
- Please tag the issue with the appropriate labels as well (i.e. status, bug, TODO, etc.)
- Each issue should have clear details (i.e. steps to reproduce if it's a bug or acceptance criteria if a new feature)

Expand Down Expand Up @@ -43,7 +43,7 @@ This project strives to follow [conventional commits](https://www.conventionalco
The basic format of a commit message is: (type)(optional scope)(breaking change indicator if needed): issue# - description

Examples:
- `feat(addnetowrk): issue25 - Add netowrk connection wizard`
- `feat(addnetowrk): issue25 - Add network connection wizard`
- `fix(core, removenetwork): issue54 - Foobared`
- `feat(wisefy)!: issue999 - Breaking change of doom`

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ A Wifi configuration and util library built in Kotlin for Android.
There is a new package for 5.0. Please use:

```kotlin
implementation("com.isupatches.android:wisefy:5.0.0-RC3")
implementation("com.isupatches.android.wisefy:wisefy:5.0.0-RC3")
```

This will include all of the Wisefy sub-artifacts through `api` dependencies.
Expand Down Expand Up @@ -69,7 +69,7 @@ Here are the descriptions of what functionality each artifact provides:
There is a new artifact for 5.0 that provides Kotlin extension functions. Please use:

```kotlin
implementation("com.isupatches.android:wisefy-ktx:<LATEST VERSION>")
implementation("com.isupatches.android.wisefy:ktx:<LATEST VERSION>")
```

if you want to try it out. All functions in this package have the suffix `Async` and are `suspend` functions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ internal fun MainScreenLayout(wisefy: WisefyApi, sdkUtil: SdkUtil) {
},
bottomBar = {
val showBottomNav = when (currentRoute(navController = navController)) {
WisefySampleNavGraph.Main.Add.route -> true
WisefySampleNavGraph.Main.Remove.route -> true
WisefySampleNavGraph.Main.Home.route -> true
WisefySampleNavGraph.Main.Misc.route -> true
WisefySampleNavGraph.Main.Add.route,
WisefySampleNavGraph.Main.Remove.route,
WisefySampleNavGraph.Main.Home.route,
WisefySampleNavGraph.Main.Misc.route,
WisefySampleNavGraph.Main.Search.route -> true
else -> false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package com.isupatches.android.wisefy.sample.main
import android.content.Context
import com.isupatches.android.wisefy.sample.util.DefaultSdkUtil
import com.isupatches.android.wisefy.sample.util.SdkUtil
import com.isupatches.android.wisefy.sample.util.createWisefy
import com.isupatches.android.wisefy.sample.util.WisefyFactory
import dagger.Binds
import dagger.Module
import dagger.Provides
Expand All @@ -36,6 +36,6 @@ internal abstract class MainActivityModule {

companion object {
@Provides
fun provideWiseFy(@ApplicationContext app: Context) = createWisefy(app)
fun provideWiseFy(@ApplicationContext app: Context) = WisefyFactory.getInstance(context = app)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,17 @@ import com.isupatches.android.wisefy.Wisefy
import com.isupatches.android.wisefy.WisefyApi
import com.isupatches.android.wisefy.sample.logging.WisefySampleLogger

internal fun createWisefy(context: Context): WisefyApi {
return Wisefy.Brains(
context = context,
throwOnAssertions = BuildConfig.DEBUG,
logger = WisefySampleLogger
).getSmarts()
internal object WisefyFactory {

private var wisefy: WisefyApi? = null

private fun createWisefy(context: Context): WisefyApi {
return Wisefy.Brains(
context = context,
throwOnAssertions = BuildConfig.DEBUG,
logger = WisefySampleLogger
).getSmarts()
}

fun getInstance(context: Context) = wisefy ?: createWisefy(context)
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ import org.junit.Test

internal class AccessPointDataTest {

companion object {
private const val TEST_SSID = "Test SSID"
private const val TEST_BSSID = "Test:BSSID"
private const val TEST_FREQUENCY = 24500
private const val TEST_RSSI = -65
}

@Test
fun assignsSSID_fromRawValue() {
// Given
Expand Down Expand Up @@ -178,4 +171,11 @@ internal class AccessPointDataTest {
// Expect
assertTrue(accessPoint.isSecure)
}

companion object {
private const val TEST_SSID: String = "Test SSID"
private const val TEST_BSSID: String = "Test:BSSID"
private const val TEST_FREQUENCY: Int = 24500
private const val TEST_RSSI: Int = -65
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ internal class DefaultAccessPointsApiImplGetNearbyAccessPointsTest(

private lateinit var apiImpl: DefaultAccessPointsApiImpl

private var annotationsClosable: AutoCloseable? = null
private var closable: AutoCloseable? = null

@Before
fun setUp() {
MockitoAnnotations.openMocks(this)
closable = MockitoAnnotations.openMocks(this)
apiImpl = DefaultAccessPointsApiImpl(wifiManager = mockWifiManager, logger = DefaultWisefyLogger())
}

@After
fun tearDown() {
annotationsClosable?.close()
closable?.close()
}

@Test
Expand Down Expand Up @@ -180,33 +180,33 @@ internal class DefaultAccessPointsApiImplGetNearbyAccessPointsTest(
val expectedResultList: List<AccessPointData>
)

private const val TEST_SSID_1 = "Test SSID 1"
private const val TEST_SSID_2 = "Test SSID 2"
private const val TEST_RSSI_1 = -5
private const val TEST_RSSI_2 = -25
private const val TEST_RSSI_LOWER = -15
private const val TEST_RSSI_HIGHER = 15
private val TEST_SCAN_RESULT_1 = ScanResult().apply {
private const val TEST_SSID_1: String = "Test SSID 1"
private const val TEST_SSID_2: String = "Test SSID 2"
private const val TEST_RSSI_1: Int = -5
private const val TEST_RSSI_2: Int = -25
private const val TEST_RSSI_LOWER: Int = -15
private const val TEST_RSSI_HIGHER: Int = 15
private val TEST_SCAN_RESULT_1: ScanResult = ScanResult().apply {
@Suppress("Deprecation")
SSID = TEST_SSID_1
level = TEST_RSSI_1
}
private val TEST_SCAN_RESULT_2 = ScanResult().apply {
private val TEST_SCAN_RESULT_2: ScanResult = ScanResult().apply {
@Suppress("Deprecation")
SSID = TEST_SSID_2
level = TEST_RSSI_2
}
private val TEST_SCAN_RESULT_SAME_SSID_LOWER_RSSI = ScanResult().apply {
private val TEST_SCAN_RESULT_SAME_SSID_LOWER_RSSI: ScanResult = ScanResult().apply {
@Suppress("Deprecation")
SSID = TEST_SSID_1
level = TEST_RSSI_LOWER
}
private val TEST_SCAN_RESULT_SAME_SSID_SAME_RSSI = ScanResult().apply {
private val TEST_SCAN_RESULT_SAME_SSID_SAME_RSSI: ScanResult = ScanResult().apply {
@Suppress("Deprecation")
SSID = TEST_SSID_1
level = TEST_RSSI_1
}
private val TEST_SCAN_RESULT_SAME_SSID_HIGHER_RSSI = ScanResult().apply {
private val TEST_SCAN_RESULT_SAME_SSID_HIGHER_RSSI: ScanResult = ScanResult().apply {
@Suppress("Deprecation")
SSID = TEST_SSID_1
level = TEST_RSSI_HIGHER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ internal class DefaultAccessPointsApiImplSearchForAccessPointsByBSSIDTest(

private lateinit var apiImpl: DefaultAccessPointsApiImpl

private var annotationsClosable: AutoCloseable? = null
private var closable: AutoCloseable? = null

@Before
fun setUp() {
MockitoAnnotations.openMocks(this)
closable = MockitoAnnotations.openMocks(this)
apiImpl = DefaultAccessPointsApiImpl(wifiManager = mockWifiManager, logger = DefaultWisefyLogger())
}

@After
fun tearDown() {
annotationsClosable?.close()
closable?.close()
}

@Test
Expand Down Expand Up @@ -462,40 +462,40 @@ internal class DefaultAccessPointsApiImplSearchForAccessPointsByBSSIDTest(
val expectedResultList: List<AccessPointData>
)

private const val TEST_SSID_1 = "Test SSID 1"
private const val TEST_SSID_2 = "Test SSID 2"
private const val TEST_BSSID_1 = "Test:BSSID:1"
private const val TEST_BSSID_2 = "Test:BSSID:2"
private const val TEST_REGEX = "Test:BSSID:.*"
private const val TEST_RSSI_1 = -5
private const val TEST_RSSI_2 = -25
private const val TEST_RSSI_LOWER = -15
private const val TEST_RSSI_HIGHER = 15
private val TEST_SCAN_RESULT_1 = ScanResult().apply {
private const val TEST_SSID_1: String = "Test SSID 1"
private const val TEST_SSID_2: String = "Test SSID 2"
private const val TEST_BSSID_1: String = "Test:BSSID:1"
private const val TEST_BSSID_2: String = "Test:BSSID:2"
private const val TEST_REGEX: String = "Test:BSSID:.*"
private const val TEST_RSSI_1: Int = -5
private const val TEST_RSSI_2: Int = -25
private const val TEST_RSSI_LOWER: Int = -15
private const val TEST_RSSI_HIGHER: Int = 15
private val TEST_SCAN_RESULT_1: ScanResult = ScanResult().apply {
@Suppress("Deprecation")
SSID = TEST_SSID_1
BSSID = TEST_BSSID_1
level = TEST_RSSI_1
}
private val TEST_SCAN_RESULT_2 = ScanResult().apply {
private val TEST_SCAN_RESULT_2: ScanResult = ScanResult().apply {
@Suppress("Deprecation")
SSID = TEST_SSID_2
BSSID = TEST_BSSID_2
level = TEST_RSSI_2
}
private val TEST_SCAN_RESULT_SAME_SSID_LOWER_RSSI = ScanResult().apply {
private val TEST_SCAN_RESULT_SAME_SSID_LOWER_RSSI: ScanResult = ScanResult().apply {
@Suppress("Deprecation")
SSID = TEST_SSID_1
BSSID = TEST_BSSID_1
level = TEST_RSSI_LOWER
}
private val TEST_SCAN_RESULT_SAME_SSID_SAME_RSSI = ScanResult().apply {
private val TEST_SCAN_RESULT_SAME_SSID_SAME_RSSI: ScanResult = ScanResult().apply {
@Suppress("Deprecation")
SSID = TEST_SSID_1
BSSID = TEST_BSSID_1
level = TEST_RSSI_1
}
private val TEST_SCAN_RESULT_SAME_SSID_HIGHER_RSSI = ScanResult().apply {
private val TEST_SCAN_RESULT_SAME_SSID_HIGHER_RSSI: ScanResult = ScanResult().apply {
@Suppress("Deprecation")
SSID = TEST_SSID_1
BSSID = TEST_BSSID_1
Expand Down
Loading

0 comments on commit e55bf47

Please sign in to comment.