Skip to content

Commit

Permalink
Move from Java to Kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
vgaidarji committed Dec 4, 2023
1 parent 97ac990 commit 502aa94
Show file tree
Hide file tree
Showing 16 changed files with 178 additions and 189 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def getVersionName = { ->
}

android {
compileSdkVersion 34
compileSdk 34
defaultConfig {
applicationId "com.vgaidarji.cimatters"
minSdkVersion 24
Expand All @@ -58,8 +58,8 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
lintOptions {
checkReleaseBuilds false
Expand Down

This file was deleted.

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()))
}
}

This file was deleted.

10 changes: 10 additions & 0 deletions app/src/main/java/com/vgaidarji/cimatters/CiMattersApplication.kt
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 app/src/main/java/com/vgaidarji/cimatters/LoginActivity.java

This file was deleted.

51 changes: 51 additions & 0 deletions app/src/main/java/com/vgaidarji/cimatters/LoginActivity.kt
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 app/src/main/java/com/vgaidarji/cimatters/LoginPresenter.java

This file was deleted.

17 changes: 17 additions & 0 deletions app/src/main/java/com/vgaidarji/cimatters/LoginPresenter.kt
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."
}
}
7 changes: 0 additions & 7 deletions app/src/main/java/com/vgaidarji/cimatters/LoginView.java

This file was deleted.

6 changes: 6 additions & 0 deletions app/src/main/java/com/vgaidarji/cimatters/LoginView.kt
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 app/src/main/java/com/vgaidarji/cimatters/MainActivity.java

This file was deleted.

12 changes: 12 additions & 0 deletions app/src/main/java/com/vgaidarji/cimatters/MainActivity.kt
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 app/src/test/java/com/vgaidarji/cimatters/LoginPresenterTest.java

This file was deleted.

31 changes: 31 additions & 0 deletions app/src/test/java/com/vgaidarji/cimatters/LoginPresenterTest.kt
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())
}
}
Loading

0 comments on commit 502aa94

Please sign in to comment.