Skip to content
This repository has been archived by the owner on Jun 25, 2024. It is now read-only.

Commit

Permalink
fix: #6 - ❌ icon animator
Browse files Browse the repository at this point in the history
Signed-off-by: Pierre-Yves Lapersonne (Orange) <pierreyves.lapersonne@orange.com>
  • Loading branch information
pylapp committed Sep 12, 2019
1 parent 85d2c82 commit b242fe7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ package com.orange.labs.orangetrainingbox.ui.animations

import android.app.Activity
import android.widget.ImageView
import androidx.test.rule.ActivityTestRule
import androidx.test.runner.AndroidJUnit4
import com.orange.labs.orangetrainingbox.R
import com.orange.labs.orangetrainingbox.ui.MainActivity
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito.mock
Expand All @@ -32,12 +35,18 @@ import org.mockito.Mockito.mock
*
* @author Pierre-Yves Lapersonne
* @since 28/08/2019
* @version 1.0.0
* @version 1.1.0
*/
@RunWith(AndroidJUnit4::class)
class InstrumentedTestIconAnimator {


/**
* Activity to play with
*/
@Rule
@JvmField var activityActivityTestRule = ActivityTestRule(MainActivity::class.java)

/**
* The object to test
*/
Expand Down Expand Up @@ -67,7 +76,7 @@ class InstrumentedTestIconAnimator {
fun animateGameIcon() {

// First call
val activity: Activity = mock(Activity::class.java)
val activity = activityActivityTestRule.activity
val imageView: ImageView = mock(ImageView::class.java)
iconAnimator?.animateGameIcon(activity, imageView, 500, arrayOf(R.mipmap.ic_sheep_moving_1, R.mipmap.ic_sheep_moving_2))

Expand All @@ -76,17 +85,24 @@ class InstrumentedTestIconAnimator {
iconAnimator?.animateGameIcon(activity, imageView, 500, arrayOf(R.mipmap.ic_sheep_moving_1, R.mipmap.ic_sheep_moving_2))
}

// Empty array of images
iconAnimator?.animateGameIcon(activity, imageView, 500, arrayOf())
}

/**
* Test the animateGameIcon() with an array of images... without images.
*/
@Test (expected = IllegalArgumentException::class)
fun animateIconWithEmptyArrayOfImages() {
val activity = activityActivityTestRule.activity
val imageView: ImageView = mock(ImageView::class.java)
iconAnimator?.animateGameIcon(activity, imageView, 500, arrayOf())
}

/**
* Test the animateGameIcon() with negative period
*/
@Test (expected = IllegalArgumentException::class)
fun animateIconWithNegativePeriod() {
val activity: Activity = mock(Activity::class.java)
val activity = activityActivityTestRule.activity
val imageView: ImageView = mock(ImageView::class.java)
iconAnimator?.animateGameIcon(activity, imageView, -1, arrayOf(R.mipmap.ic_sheep_moving_1, R.mipmap.ic_sheep_moving_2))
}
Expand All @@ -101,7 +117,7 @@ class InstrumentedTestIconAnimator {
iconAnimator?.stopAnimateGameIcon()

// Call after started animation
val activity: Activity = mock(Activity::class.java)
val activity = activityActivityTestRule.activity
val imageView: ImageView = mock(ImageView::class.java)
iconAnimator?.animateGameIcon(activity, imageView, 500, arrayOf(R.mipmap.ic_sheep_moving_1, R.mipmap.ic_sheep_moving_2))
iconAnimator?.stopAnimateGameIcon()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import kotlin.concurrent.schedule
*
* @author Pierre-Yves Lapersonne
* @since 23/05/20190
* @version 1.2.0
* @version 1.2.1
*/
class IconAnimator {

Expand Down Expand Up @@ -64,7 +64,9 @@ class IconAnimator {
*/
fun animateGameIcon(context: Activity, imageView: ImageView, period: Long, images: Array<Int>) {
period.takeIf { it >= 0 } ?: throw IllegalArgumentException("The period cannot be negative")
images.takeIf { it.isNotEmpty() } ?: throw IllegalArgumentException("The array of images is empty. What should be displayed? O_o")
if (timer != null) stopAnimateGameIcon()
ticker = 0
timer = Timer()
timer?.schedule(delay=0, period=period) {
context.runOnUiThread {
Expand Down

0 comments on commit b242fe7

Please sign in to comment.