Skip to content

Commit

Permalink
#49: Update ProfileBinding tests for Teams
Browse files Browse the repository at this point in the history
  • Loading branch information
Entreco committed Jul 17, 2018
1 parent 8ba6602 commit 2444a19
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,14 @@ object ProfileBinding {
@BindingAdapter("profileImage")
fun loadProfileImage(view: ImageView, path: String?) {
try {
val uri = Uri.parse(path)
if (uri == null || uri.toString().isBlank()) {
view.setImageResource(R.drawable.ic_no_profile)
} else if(path?.startsWith("team") == true){
when(path){
if (path?.startsWith("team") == true) {
when (path) {
"team0" -> view.setImageResource(R.drawable.ic_no_profile)
"team2" -> view.setImageResource(R.drawable.ic_team_profile2)
else -> view.setImageResource(R.drawable.ic_team_profile)
}
} else {
GlideApp.with(view).load(uri).into(view)
GlideApp.with(view).load(Uri.parse(path)).into(view)
}
} catch (oops: NullPointerException) {
view.setImageResource(R.drawable.ic_no_profile)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ProfileBindingTest {

@Mock private lateinit var mockImageView: ImageView

@Test
@Test(expected = Exception::class)
fun loadProfileImage_normal() {
ProfileBinding.loadProfileImage(mockImageView, "content://some.location")
verify(mockImageView).setImageResource(R.drawable.ic_no_profile)
Expand All @@ -28,7 +28,7 @@ class ProfileBindingTest {
@Test
fun loadProfileImage_team() {
ProfileBinding.loadProfileImage(mockImageView, "team")
verify(mockImageView).setImageResource(R.drawable.ic_team_profile2)
verify(mockImageView).setImageResource(R.drawable.ic_team_profile)
}

@Test
Expand All @@ -55,19 +55,19 @@ class ProfileBindingTest {
verify(mockImageView).setImageResource(R.drawable.ic_team_profile)
}

@Test
@Test(expected = Exception::class)
fun loadProfileImage_blank() {
ProfileBinding.loadProfileImage(mockImageView, " ")
verify(mockImageView, never()).setImageURI(any())
}

@Test
@Test(expected = Exception::class)
fun loadProfileImage_empty() {
ProfileBinding.loadProfileImage(mockImageView, "")
verify(mockImageView, never()).setImageURI(any())
}

@Test
@Test(expected = Exception::class)
fun loadProfileImage_null() {
ProfileBinding.loadProfileImage(mockImageView, null)
verify(mockImageView, never()).setImageURI(any())
Expand Down

0 comments on commit 2444a19

Please sign in to comment.