Skip to content

Commit

Permalink
#319: interface wrapper around Android Wifi state
Browse files Browse the repository at this point in the history
Not quite finished. We should edit the unit tests in PatternDataManager, move it to PatternDataManagerTestKt, then rename this to patternDataManagerTest.kt
  • Loading branch information
epicstar committed Aug 14, 2017
1 parent dbf9ce2 commit 57fedd6
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 2 deletions.
7 changes: 6 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'com.github.ben-manes.versions'

Expand All @@ -19,7 +20,7 @@ android {
applicationId "rectangledbmi.com.pittsburghrealtimetracker"
minSdkVersion versions.android.minSdk
targetSdkVersion versions.android.targetSdk
versionCode 160080001
versionCode 160080002
versionName "8.0.1-beta"
}
lintOptions {
Expand All @@ -40,6 +41,9 @@ android {
sourceCompatibility versions.java.target
targetCompatibility versions.java.target
}
sourceSets {
main.java.srcDirs += "src/main/kotlin"
}

}

Expand Down Expand Up @@ -83,6 +87,7 @@ dependencies {

testCompile "junit:junit:${versions.test.junit}"
testCompile "org.mockito:mockito-core:${versions.test.mockito}"
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}

buildscript {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.rectanglel.pattrack.wrappers

import android.content.Context
import android.net.ConnectivityManager
import com.rectanglel.patstatic.wrappers.WifiChecker

/**
* <p>Android implementation of checking to see if wifi is on.
* <p>Created by epicstar on 8/13/17.
* @author Jeremy Jao
* @since 160080002
*/
class AndroidWifiChecker constructor(context: Context): WifiChecker {

private val connectivityManager : ConnectivityManager =
context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager

override fun isOnWifi(): Boolean {
val networkInfo = connectivityManager.activeNetworkInfo
return networkInfo.type == ConnectivityManager.TYPE_WIFI
}

}
10 changes: 9 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.1.3-2'
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
apply plugin: 'kotlin'

allprojects {
repositories {
Expand Down Expand Up @@ -59,7 +62,6 @@ ext {

// versions for all dependencies
versions = [
kotlin: '1.1.0',
java: [
annotation: '10.0-b28',
target: JavaVersion.VERSION_1_8,
Expand Down Expand Up @@ -102,3 +104,9 @@ ext {
]
]
}
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}
7 changes: 7 additions & 0 deletions pat-static/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'me.tatarka.retrolambda'


buildscript {
ext.kotlin_version = '1.1.3-2'
repositories {
jcenter()
mavenCentral()
Expand All @@ -14,6 +16,7 @@ buildscript {
// check for updates of 3rd party libs:
// `./gradlew dependencyUpdates -Drevision=release`
classpath "com.github.ben-manes:gradle-versions-plugin:${versions.gradleVersions}"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

Expand All @@ -32,6 +35,7 @@ dependencies {

testCompile "junit:junit:${versions.test.junit}"
testCompile "org.mockito:mockito-core:${versions.test.mockito}"
compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}

sourceSets {
Expand All @@ -55,3 +59,6 @@ task cleanCachedRoutes(type: Delete) {
}

jar.dependsOn cacheRoutes
repositories {
mavenCentral()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.rectanglel.patstatic.wrappers

/**
* <p>Checks if
* <p>Created by epicstar on 8/13/17.
* @author Jeremy Jao
*/
public interface WifiChecker {
/**
* Checks if wifi is on.
*/
fun isOnWifi() : Boolean
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.rectanglel.patstatic.patterns

import com.rectanglel.patstatic.mock.PatApiMock
import com.rectanglel.patstatic.model.RetrofitPatApi
import com.rectanglel.patstatic.model.StaticData
import com.rectanglel.patstatic.wrappers.WifiChecker
import org.junit.Before
import org.mockito.Mockito
import java.io.File

/**
* Created by epicstar on 8/13/17.
*/
class PatternDataManagerTestKt { // TODO: rename this to PatternDataManagerTest
private lateinit var dir : File
private lateinit var patternDataManager : PatternDataManager
private lateinit var patapi : RetrofitPatApi
private lateinit var staticData : StaticData
private lateinit var wifiChecker : WifiChecker

@Before
fun setUp() {
dir = File ("testDirectory")
dir.mkdirs()
patapi = PatApiMock.getPatApiMock()
staticData = Mockito.mock(StaticData::class.java)
wifiChecker = Mockito.mock(WifiChecker::class.java)
patternDataManager = Mockito.spy(PatternDataManager(
dir,
patapi,
staticData
))
}


}

0 comments on commit 57fedd6

Please sign in to comment.