Unit testing ButtonDropTarget
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
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 7beac0b..96d713a 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -1799,6 +1799,11 @@
}
@Override
+ public DropTargetHandler getDropTargetHandler() {
+ return new DropTargetHandler(this);
+ }
+
+ @Override
public void startActivityForResult(Intent intent, int requestCode, Bundle options) {
if (requestCode != -1) {
mPendingActivityRequestCode = requestCode;