44898c3db4
Originally there was a bug in a method (isTextClippedVertically) in ButtonDropTarget. While attempting to write a unit test it became necessary to refactor ButtonDropTarget and DeleteDropTarget to decouple them from their dependency on launcher in order to allow for a unit test to be written The pattern we are introducing here is to decouple Launcher from a controller, in order to facilitate easier testing. Instead of calling Launcher.getLauncher() we call the method through ActivityContext, which has a testing wrapper already defined. Here is a diagram that explains the old and new pattern Design Pattern: https://screenshot.googleplex.com/7apiE2DaGDrFzy9.png Test: isTextClippedVerticallyTest Bug: b/274402490 Change-Id: I1f3003d0b62dddbceb6e492b15aa5d7352d3a293
43 lines
1.4 KiB
Kotlin
43 lines
1.4 KiB
Kotlin
package com.android.launcher3
|
|
|
|
import android.content.Context
|
|
import androidx.test.core.app.ApplicationProvider.getApplicationContext
|
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
|
import androidx.test.filters.SmallTest
|
|
import com.android.launcher3.Utilities.*
|
|
import com.android.launcher3.util.ActivityContextWrapper
|
|
import com.google.common.truth.Truth.assertThat
|
|
import org.junit.Before
|
|
import org.junit.Test
|
|
import org.junit.runner.RunWith
|
|
|
|
@SmallTest
|
|
@RunWith(AndroidJUnit4::class)
|
|
class DeleteDropTargetTest {
|
|
|
|
private var mContext: Context = ActivityContextWrapper(getApplicationContext())
|
|
|
|
// Use a non-abstract class implementation
|
|
private var buttonDropTarget: DeleteDropTarget = DeleteDropTarget(mContext)
|
|
|
|
@Before
|
|
fun setup() {
|
|
enableRunningInTestHarnessForTests()
|
|
}
|
|
|
|
// Needs mText, mTempRect, getPaddingTop, getPaddingBottom
|
|
// availableHeight as a parameter
|
|
@Test
|
|
fun isTextClippedVerticallyTest() {
|
|
buttonDropTarget.mText = "My Test"
|
|
// No space for text
|
|
assertThat(buttonDropTarget.isTextClippedVertically(30)).isTrue()
|
|
|
|
// Some space for text, and just enough that the text should not be clipped
|
|
assertThat(buttonDropTarget.isTextClippedVertically(50)).isFalse()
|
|
|
|
// A lot of space for text so the text should not be clipped
|
|
assertThat(buttonDropTarget.isTextClippedVertically(100)).isFalse()
|
|
}
|
|
}
|