Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/src/main/java/com/me/registrationtask/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)


}
}
32 changes: 32 additions & 0 deletions app/src/main/java/com/me/registrationtask/UserDaoImpl.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.me.registrationtask

import com.me.registrationtask.db.UserDao
import com.me.registrationtask.module.UserEntity

class UserDaoImpl : UserDao {

// AN ARRAYLIST THAT IS OF THE TYPE UserEntity
private val mArrayList: ArrayList<UserEntity> = ArrayList()


// THE IMPORTED FUNCTION FROM THE UserDao INTERFACE
override fun saveUser(user: UserEntity) {

// ADDED THE USER DATA TO THE ARRAYLIST
mArrayList.add(user)
}

override fun getUser(username: String, password: String): UserEntity {

// FROM THE ARRAYLIST FIND THE USERNAME AND PASSWORD PARAMETER
val findingUser = mArrayList.find { it.username == username && it.password == password }

// IF ITS NOT FOUND, THROW AN EXCEPTION
if (findingUser == null) throw NullPointerException("User Not Found")

// ELSE RETURN THE VARIABLE
else return findingUser
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ class AuthenticationTask(private val userRepository: IUserRepository) {

return userRepository.login(username, password)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ import org.mockito.MockitoAnnotations
@RunWith(JUnit4::class)
class UserRepositoryTest {

// THIS IS THE DEPENDENCY WHICH IS CONSTRUCTORS IN A CLASS
// THE CONSTRUCTORS IS MOST TIMES AN INTERFACE

@Mock
lateinit var userDao: UserDao

// THIS IS THE NAME OF THE CLASS, WHICH IS A TYPE OF THE CLASS

lateinit var userRepository: UserRepository

var fakeUser = UserEntity(
Expand Down