-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#319: interface wrapper around Android Wifi state
Not quite finished. We should edit the unit tests in PatternDataManager, move it to PatternDataManagerTestKt, then rename this to patternDataManagerTest.kt
- Loading branch information
Showing
6 changed files
with
94 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
app/src/main/kotlin/com/rectanglel/pattrack/wrappers/AndroidWifiChecker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
pat-static/src/main/kotlin/com/rectanglel/patstatic/wrappers/WifiChecker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
36 changes: 36 additions & 0 deletions
36
pat-static/src/test/kotlin/com/rectanglel/patstatic/patterns/PatternDataManagerTestKt.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
)) | ||
} | ||
|
||
|
||
} |