-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
178 additions
and
189 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
44 changes: 0 additions & 44 deletions
44
app/src/androidTest/java/com/vgaidarji/cimatters/LoginActivityTest.java
This file was deleted.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
app/src/androidTest/java/com/vgaidarji/cimatters/LoginActivityTest.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,48 @@ | ||
package com.vgaidarji.cimatters | ||
|
||
import android.support.test.espresso.Espresso | ||
import android.support.test.espresso.action.ViewActions | ||
import android.support.test.espresso.assertion.ViewAssertions | ||
import android.support.test.espresso.matcher.ViewMatchers | ||
import android.support.test.rule.ActivityTestRule | ||
import android.support.test.runner.AndroidJUnit4 | ||
import org.hamcrest.CoreMatchers | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class LoginActivityTest { | ||
@Rule | ||
var activityTestRule = ActivityTestRule( | ||
LoginActivity::class.java | ||
) | ||
|
||
@Test | ||
@Throws(Exception::class) | ||
fun onLoginClick_shouldOpenNextActivityForAllowedCredentials() { | ||
Espresso.onView(ViewMatchers.withId(R.id.edit_text_email)) | ||
.perform(ViewActions.typeText("[email protected]")) | ||
Espresso.onView(ViewMatchers.withId(R.id.edit_text_password)) | ||
.perform(ViewActions.typeText("1111")) | ||
Espresso.onView(ViewMatchers.withId(R.id.button_login)).perform(ViewActions.click()) | ||
Espresso.onView(ViewMatchers.withText("OK")) | ||
.check(ViewAssertions.matches(ViewMatchers.isDisplayed())) | ||
} | ||
|
||
@Test | ||
@Throws(Exception::class) | ||
fun onLoginClick_shouldShowErrorForIncorrectCredentials() { | ||
Espresso.onView(ViewMatchers.withId(R.id.edit_text_email)) | ||
.perform(ViewActions.typeText("[email protected]")) | ||
Espresso.onView(ViewMatchers.withId(R.id.edit_text_password)) | ||
.perform(ViewActions.typeText("not_a_password")) | ||
Espresso.onView(ViewMatchers.withId(R.id.button_login)).perform(ViewActions.click()) | ||
Espresso.onView( | ||
CoreMatchers.allOf( | ||
ViewMatchers.withId(android.support.design.R.id.snackbar_text), | ||
ViewMatchers.withText("Wrong credentials.") | ||
) | ||
).check(ViewAssertions.matches(ViewMatchers.isDisplayed())) | ||
} | ||
} |
11 changes: 0 additions & 11 deletions
11
app/src/main/java/com/vgaidarji/cimatters/CiMattersApplication.java
This file was deleted.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
app/src/main/java/com/vgaidarji/cimatters/CiMattersApplication.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,10 @@ | ||
package com.vgaidarji.cimatters | ||
|
||
import android.app.Application | ||
|
||
class CiMattersApplication : Application() { | ||
override fun onCreate() { | ||
super.onCreate() | ||
// TODO: integrate with Crashlytics | ||
} | ||
} |
54 changes: 0 additions & 54 deletions
54
app/src/main/java/com/vgaidarji/cimatters/LoginActivity.java
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
app/src/main/java/com/vgaidarji/cimatters/LoginActivity.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,51 @@ | ||
package com.vgaidarji.cimatters | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.support.design.widget.CoordinatorLayout | ||
import android.support.design.widget.Snackbar | ||
import android.support.v7.app.AppCompatActivity | ||
import android.widget.Button | ||
import android.widget.EditText | ||
import butterknife.ButterKnife | ||
import butterknife.InjectView | ||
import butterknife.OnClick | ||
|
||
class LoginActivity : AppCompatActivity(), LoginView { | ||
@InjectView(R.id.coordinator) | ||
var coordinatorLayout: CoordinatorLayout? = null | ||
|
||
@InjectView(R.id.edit_text_email) | ||
var editTextEmail: EditText? = null | ||
|
||
@InjectView(R.id.edit_text_password) | ||
var editTextPassword: EditText? = null | ||
|
||
@InjectView(R.id.button_login) | ||
var buttonLogin: Button? = null | ||
private var presenter: LoginPresenter? = null | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_login) | ||
title = getString(R.string.activity_login) | ||
ButterKnife.inject(this) | ||
presenter = LoginPresenter(this) | ||
} | ||
|
||
@OnClick(R.id.button_login) | ||
fun onLoginClick() { | ||
presenter!!.onLoginClick( | ||
editTextEmail!!.text.toString(), | ||
editTextPassword!!.text.toString() | ||
) | ||
} | ||
|
||
override fun openNextActivity() { | ||
startActivity(Intent(this@LoginActivity, MainActivity::class.java)) | ||
finish() | ||
} | ||
|
||
override fun showError(message: String?) { | ||
message?.let { Snackbar.make(coordinatorLayout!!, it, Snackbar.LENGTH_LONG).show() } | ||
} | ||
} |
21 changes: 0 additions & 21 deletions
21
app/src/main/java/com/vgaidarji/cimatters/LoginPresenter.java
This file was deleted.
Oops, something went wrong.
17 changes: 17 additions & 0 deletions
17
app/src/main/java/com/vgaidarji/cimatters/LoginPresenter.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,17 @@ | ||
package com.vgaidarji.cimatters | ||
|
||
internal class LoginPresenter(private val view: LoginView) { | ||
fun onLoginClick(email: String, password: String) { | ||
if (email == EMAIL && password == PASSWORD) { | ||
view.openNextActivity() | ||
} else { | ||
view.showError(WRONG_CREDENTIALS) | ||
} | ||
} | ||
|
||
companion object { | ||
private const val EMAIL = "[email protected]" | ||
private const val PASSWORD = "1111" | ||
private const val WRONG_CREDENTIALS = "Wrong credentials." | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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,6 @@ | ||
package com.vgaidarji.cimatters | ||
|
||
internal interface LoginView { | ||
fun openNextActivity() | ||
fun showError(message: String?) | ||
} |
14 changes: 0 additions & 14 deletions
14
app/src/main/java/com/vgaidarji/cimatters/MainActivity.java
This file was deleted.
Oops, something went wrong.
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,12 @@ | ||
package com.vgaidarji.cimatters | ||
|
||
import android.os.Bundle | ||
import android.support.v7.app.AppCompatActivity | ||
|
||
class MainActivity : AppCompatActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_main) | ||
title = getString(R.string.activity_main) | ||
} | ||
} |
34 changes: 0 additions & 34 deletions
34
app/src/test/java/com/vgaidarji/cimatters/LoginPresenterTest.java
This file was deleted.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
app/src/test/java/com/vgaidarji/cimatters/LoginPresenterTest.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,31 @@ | ||
package com.vgaidarji.cimatters | ||
|
||
import org.junit.Before | ||
import org.junit.Test | ||
import org.mockito.Matchers | ||
import org.mockito.Mockito | ||
|
||
class LoginPresenterTest { | ||
private lateinit var view: LoginView | ||
private var presenter: LoginPresenter? = null | ||
@Before | ||
@Throws(Exception::class) | ||
fun setUp() { | ||
view = Mockito.mock(LoginView::class.java) | ||
presenter = LoginPresenter(view) | ||
} | ||
|
||
@Test | ||
@Throws(Exception::class) | ||
fun onLoginClick_shouldOpenNextActivityForAllowedCredentials() { | ||
presenter!!.onLoginClick("[email protected]", "1111") | ||
Mockito.verify(view)?.openNextActivity() | ||
} | ||
|
||
@Test | ||
@Throws(Exception::class) | ||
fun onLoginClick_shouldShowErrorForIncorrectCredentials() { | ||
presenter!!.onLoginClick("[email protected]", "not_a_password") | ||
Mockito.verify(view)?.showError(Matchers.anyString()) | ||
} | ||
} |
Oops, something went wrong.