Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This commit not only adds Koin, but also configures a basic infrastructure for testing, allowing us to change behaviors as needed.
- Loading branch information
1 parent
103d256
commit 1b6715b
Showing
13 changed files
with
115 additions
and
6 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
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,10 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="net.rafaeltoledo.social"> | ||
|
||
<application> | ||
<meta-data | ||
android:name="firebase_analytics_collection_deactivated" | ||
android:value="true" /> | ||
</application> | ||
|
||
</manifest> |
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
16 changes: 15 additions & 1 deletion
16
app/src/main/kotlin/net/rafaeltoledo/social/MainActivity.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 |
---|---|---|
@@ -1,5 +1,19 @@ | ||
package net.rafaeltoledo.social | ||
|
||
import android.os.Bundle | ||
import android.support.v7.app.AppCompatActivity | ||
import android.widget.TextView | ||
import org.koin.android.architecture.ext.viewModel | ||
|
||
class MainActivity : AppCompatActivity() | ||
class MainActivity : AppCompatActivity() { | ||
|
||
private val mainViewModel: MainViewModel by viewModel() | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(TextView(this).apply { | ||
id = R.id.content | ||
text = mainViewModel.getString() | ||
}) | ||
} | ||
} |
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,8 @@ | ||
package net.rafaeltoledo.social | ||
|
||
import android.arch.lifecycle.ViewModel | ||
|
||
class MainViewModel(private val string: String) : ViewModel() { | ||
|
||
fun getString() = string | ||
} |
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,17 @@ | ||
package net.rafaeltoledo.social | ||
|
||
import android.app.Application | ||
import net.rafaeltoledo.social.di.firstModule | ||
import net.rafaeltoledo.social.di.viewModelModule | ||
import org.koin.android.ext.android.startKoin | ||
|
||
class SocialApp : Application() { | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
startKoin(listOf( | ||
viewModelModule, | ||
firstModule | ||
)) | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
app/src/main/kotlin/net/rafaeltoledo/social/di/FirstModule.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,7 @@ | ||
package net.rafaeltoledo.social.di | ||
|
||
import org.koin.dsl.module.applicationContext | ||
|
||
val firstModule = applicationContext { | ||
bean { "Social App" } | ||
} |
9 changes: 9 additions & 0 deletions
9
app/src/main/kotlin/net/rafaeltoledo/social/di/ViewModelModule.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,9 @@ | ||
package net.rafaeltoledo.social.di | ||
|
||
import net.rafaeltoledo.social.MainViewModel | ||
import org.koin.android.architecture.ext.viewModel | ||
import org.koin.dsl.module.applicationContext | ||
|
||
val viewModelModule = applicationContext { | ||
viewModel { MainViewModel(get()) } | ||
} |
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,4 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<item name="content" type="id" /> | ||
</resources> |
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
17 changes: 15 additions & 2 deletions
17
app/src/test/kotlin/net/rafaeltoledo/social/MainActivityTest.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 |
---|---|---|
@@ -1,16 +1,29 @@ | ||
package net.rafaeltoledo.social | ||
|
||
import org.junit.Assert.assertNotNull | ||
import android.widget.TextView | ||
import com.google.common.truth.Truth.assertThat | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.robolectric.Robolectric | ||
import org.robolectric.RobolectricTestRunner | ||
import org.robolectric.RuntimeEnvironment | ||
|
||
@RunWith(RobolectricTestRunner::class) | ||
class MainActivityTest { | ||
|
||
@Test | ||
fun checkIfActivityIsSuccessfullyCreated() { | ||
assertNotNull(Robolectric.setupActivity(MainActivity::class.java)) | ||
// Arrange | ||
val newValue = "Test Social App" | ||
val app = RuntimeEnvironment.application as TestSocialApp | ||
app.initKoin(newValue) | ||
|
||
// Act | ||
val activity = Robolectric.setupActivity(MainActivity::class.java) | ||
|
||
// Assert | ||
assertThat(activity).isNotNull() | ||
val text = activity.findViewById<TextView>(R.id.content) | ||
assertThat(text.text).isEqualTo(newValue) | ||
} | ||
} |
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,18 @@ | ||
package net.rafaeltoledo.social | ||
|
||
import android.app.Application | ||
import net.rafaeltoledo.social.di.viewModelModule | ||
import org.koin.android.ext.android.startKoin | ||
import org.koin.dsl.module.applicationContext | ||
|
||
class TestSocialApp : Application() { | ||
|
||
fun initKoin(newValue: String) { | ||
startKoin(listOf( | ||
viewModelModule, | ||
applicationContext { | ||
bean { newValue } | ||
} | ||
)) | ||
} | ||
} |
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