Merge "Convert testing classest to Kotlin" into main
diff --git a/tests/multivalentTests/src/com/android/launcher3/celllayout/HotseatReorderUnitTest.kt b/tests/multivalentTests/src/com/android/launcher3/celllayout/HotseatReorderUnitTest.kt
index c32461e..a3c7f4f 100644
--- a/tests/multivalentTests/src/com/android/launcher3/celllayout/HotseatReorderUnitTest.kt
+++ b/tests/multivalentTests/src/com/android/launcher3/celllayout/HotseatReorderUnitTest.kt
@@ -104,7 +104,7 @@
         val cl = cellLayoutBuilder.createCellLayout(board.width, board.height, false)
         // The views have to be sorted or the result can vary
         board.icons
-            .map(IconPoint::getCoord)
+            .map(IconPoint::coord)
             .sortedWith(
                 Comparator.comparing { p: Any -> (p as Point).x }
                     .thenComparing { p: Any -> (p as Point).y }
@@ -120,9 +120,7 @@
                 )
             }
         board.widgets
-            .sortedWith(
-                Comparator.comparing(WidgetRect::getCellX).thenComparing(WidgetRect::getCellY)
-            )
+            .sortedWith(Comparator.comparing(WidgetRect::cellX).thenComparing(WidgetRect::cellY))
             .forEach { widget ->
                 addViewInCellLayout(
                     cl,
diff --git a/tests/multivalentTests/src/com/android/launcher3/celllayout/board/BoardClasses.kt b/tests/multivalentTests/src/com/android/launcher3/celllayout/board/BoardClasses.kt
new file mode 100644
index 0000000..3cbfc5a
--- /dev/null
+++ b/tests/multivalentTests/src/com/android/launcher3/celllayout/board/BoardClasses.kt
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.launcher3.celllayout.board
+
+import android.graphics.Point
+import android.graphics.Rect
+
+/** Represents a widget in a CellLayoutBoard */
+data class WidgetRect(
+    val type: Char,
+    val bounds: Rect,
+) {
+    val spanX: Int = bounds.right - bounds.left + 1
+    val spanY: Int = bounds.top - bounds.bottom + 1
+    val cellY: Int = bounds.bottom
+    val cellX: Int = bounds.left
+
+    fun shouldIgnore() = type == CellType.IGNORE
+
+    fun contains(x: Int, y: Int) = bounds.contains(x, y)
+}
+
+/**
+ * [A-Z]: Represents a folder and number of icons in the folder is represented by the order of
+ * letter in the alphabet, A=2, B=3, C=4 ... etc.
+ */
+data class FolderPoint(val coord: Point, val type: Char) {
+    val numberIconsInside: Int = type.code - 'A'.code + 2
+}
+
+/** Represents an icon in a CellLayoutBoard */
+data class IconPoint(val coord: Point, val type: Char = CellType.ICON)
+
+object CellType {
+    // The cells marked by this will be filled by 1x1 widgets and will be ignored when
+    // validating
+    const val IGNORE = 'x'
+
+    // The cells marked by this will be filled by app icons
+    const val ICON = 'i'
+
+    // The cells marked by FOLDER will be filled by folders with 27 app icons inside
+    const val FOLDER = 'Z'
+
+    // Empty space
+    const val EMPTY = '-'
+
+    // Widget that will be saved as "main widget" for easier retrieval
+    const val MAIN_WIDGET = 'm' // Everything else will be consider a widget
+}
diff --git a/tests/multivalentTests/src/com/android/launcher3/celllayout/board/CellLayoutBoard.java b/tests/multivalentTests/src/com/android/launcher3/celllayout/board/CellLayoutBoard.java
index e5ad888..04bfee9 100644
--- a/tests/multivalentTests/src/com/android/launcher3/celllayout/board/CellLayoutBoard.java
+++ b/tests/multivalentTests/src/com/android/launcher3/celllayout/board/CellLayoutBoard.java
@@ -88,7 +88,7 @@
 
     public WidgetRect getWidgetOfType(char type) {
         return mWidgetsRects.stream()
-                .filter(widgetRect -> widgetRect.mType == type).findFirst().orElse(null);
+                .filter(widgetRect -> widgetRect.getType() == type).findFirst().orElse(null);
     }
 
     public WidgetRect getWidgetAt(int x, int y) {
@@ -117,8 +117,8 @@
     }
 
     private void removeWidgetFromBoard(WidgetRect widget) {
-        for (int xi = widget.mBounds.left; xi <= widget.mBounds.right; xi++) {
-            for (int yi = widget.mBounds.bottom; yi <= widget.mBounds.top; yi++) {
+        for (int xi = widget.getBounds().left; xi <= widget.getBounds().right; xi++) {
+            for (int yi = widget.getBounds().bottom; yi <= widget.getBounds().top; yi++) {
                 mWidget[xi][yi] = '-';
             }
         }
@@ -127,7 +127,7 @@
     private void removeOverlappingItems(Rect rect) {
         // Remove overlapping widgets and remove them from the board
         mWidgetsRects = mWidgetsRects.stream().filter(widget -> {
-            if (rect.intersect(widget.mBounds)) {
+            if (rect.intersect(widget.getBounds())) {
                 removeWidgetFromBoard(widget);
                 return false;
             }
@@ -135,8 +135,8 @@
         }).collect(Collectors.toList());
         // Remove overlapping icons and remove them from the board
         mIconPoints = mIconPoints.stream().filter(iconPoint -> {
-            int x = iconPoint.coord.x;
-            int y = iconPoint.coord.y;
+            int x = iconPoint.getCoord().x;
+            int y = iconPoint.getCoord().y;
             if (rect.contains(x, y)) {
                 mWidget[x][y] = '-';
                 return false;
@@ -146,8 +146,8 @@
 
         // Remove overlapping folders and remove them from the board
         mFolderPoints = mFolderPoints.stream().filter(folderPoint -> {
-            int x = folderPoint.coord.x;
-            int y = folderPoint.coord.y;
+            int x = folderPoint.getCoord().x;
+            int y = folderPoint.getCoord().y;
             if (rect.contains(x, y)) {
                 mWidget[x][y] = '-';
                 return false;
@@ -159,7 +159,7 @@
     private void removeOverlappingItems(Point p) {
         // Remove overlapping widgets and remove them from the board
         mWidgetsRects = mWidgetsRects.stream().filter(widget -> {
-            if (IdenticalBoardComparator.Companion.touchesPoint(widget.mBounds, p)) {
+            if (IdenticalBoardComparator.Companion.touchesPoint(widget.getBounds(), p)) {
                 removeWidgetFromBoard(widget);
                 return false;
             }
@@ -167,8 +167,8 @@
         }).collect(Collectors.toList());
         // Remove overlapping icons and remove them from the board
         mIconPoints = mIconPoints.stream().filter(iconPoint -> {
-            int x = iconPoint.coord.x;
-            int y = iconPoint.coord.y;
+            int x = iconPoint.getCoord().x;
+            int y = iconPoint.getCoord().y;
             if (p.x == x && p.y == y) {
                 mWidget[x][y] = '-';
                 return false;
@@ -178,8 +178,8 @@
 
         // Remove overlapping folders and remove them from the board
         mFolderPoints = mFolderPoints.stream().filter(folderPoint -> {
-            int x = folderPoint.coord.x;
-            int y = folderPoint.coord.y;
+            int x = folderPoint.getCoord().x;
+            int y = folderPoint.getCoord().y;
             if (p.x == x && p.y == y) {
                 mWidget[x][y] = '-';
                 return false;
@@ -226,7 +226,7 @@
 
     public void removeItem(char type) {
         mWidgetsRects.stream()
-                .filter(widgetRect -> widgetRect.mType == type)
+                .filter(widgetRect -> widgetRect.getType() == type)
                 .forEach(widgetRect -> removeOverlappingItems(
                         new Point(widgetRect.getCellX(), widgetRect.getCellY())));
     }
@@ -365,10 +365,10 @@
         board.mWidth = lines[0].length();
         board.mWidgetsRects = getRects(board.mWidget);
         board.mWidgetsRects.forEach(widgetRect -> {
-            if (widgetRect.mType == CellType.MAIN_WIDGET) {
+            if (widgetRect.getType() == CellType.MAIN_WIDGET) {
                 board.mMain = widgetRect;
             }
-            board.mWidgetsMap.put(widgetRect.mType, widgetRect);
+            board.mWidgetsMap.put(widgetRect.getType(), widgetRect);
         });
         board.mIconPoints = getIconPoints(board.mWidget);
         board.mFolderPoints = getFolderPoints(board.mWidget);
diff --git a/tests/multivalentTests/src/com/android/launcher3/celllayout/board/CellType.java b/tests/multivalentTests/src/com/android/launcher3/celllayout/board/CellType.java
deleted file mode 100644
index 49c146b..0000000
--- a/tests/multivalentTests/src/com/android/launcher3/celllayout/board/CellType.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Copyright (C) 2023 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.launcher3.celllayout.board;
-
-public class CellType {
-    // The cells marked by this will be filled by 1x1 widgets and will be ignored when
-    // validating
-    public static final char IGNORE = 'x';
-    // The cells marked by this will be filled by app icons
-    public static final char ICON = 'i';
-    // The cells marked by FOLDER will be filled by folders with 27 app icons inside
-    public static final char FOLDER = 'Z';
-    // Empty space
-    public static final char EMPTY = '-';
-    // Widget that will be saved as "main widget" for easier retrieval
-    public static final char MAIN_WIDGET = 'm';
-    // Everything else will be consider a widget
-}
diff --git a/tests/multivalentTests/src/com/android/launcher3/celllayout/board/FolderPoint.java b/tests/multivalentTests/src/com/android/launcher3/celllayout/board/FolderPoint.java
deleted file mode 100644
index 39ba434..0000000
--- a/tests/multivalentTests/src/com/android/launcher3/celllayout/board/FolderPoint.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Copyright (C) 2023 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.launcher3.celllayout.board;
-
-import android.graphics.Point;
-
-public class FolderPoint {
-    public Point coord;
-    public char mType;
-
-    public FolderPoint(Point coord, char type) {
-        this.coord = coord;
-        mType = type;
-    }
-
-    /**
-     * [A-Z]: Represents a folder and number of icons in the folder is represented by
-     * the order of letter in the alphabet, A=2, B=3, C=4 ... etc.
-     */
-    public int getNumberIconsInside() {
-        return (mType - 'A') + 2;
-    }
-}
diff --git a/tests/multivalentTests/src/com/android/launcher3/celllayout/board/IconPoint.java b/tests/multivalentTests/src/com/android/launcher3/celllayout/board/IconPoint.java
deleted file mode 100644
index d3d2970..0000000
--- a/tests/multivalentTests/src/com/android/launcher3/celllayout/board/IconPoint.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Copyright (C) 2023 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.launcher3.celllayout.board;
-
-import android.graphics.Point;
-
-public class IconPoint {
-    public Point coord;
-    public char mType;
-
-    public IconPoint(Point coord, char type) {
-        this.coord = coord;
-        mType = type;
-    }
-
-    public char getType() {
-        return mType;
-    }
-
-    public void setType(char type) {
-        mType = type;
-    }
-
-    public Point getCoord() {
-        return coord;
-    }
-
-    public void setCoord(Point coord) {
-        this.coord = coord;
-    }
-}
diff --git a/tests/multivalentTests/src/com/android/launcher3/celllayout/board/IdenticalBoardComparator.kt b/tests/multivalentTests/src/com/android/launcher3/celllayout/board/IdenticalBoardComparator.kt
index a4a420c..aacd940 100644
--- a/tests/multivalentTests/src/com/android/launcher3/celllayout/board/IdenticalBoardComparator.kt
+++ b/tests/multivalentTests/src/com/android/launcher3/celllayout/board/IdenticalBoardComparator.kt
@@ -26,11 +26,11 @@
 
     /** Converts a list of WidgetRect into a map of the count of different widget.bounds */
     private fun widgetsToBoundsMap(widgets: List<WidgetRect>) =
-        widgets.groupingBy { it.mBounds }.eachCount()
+        widgets.groupingBy { it.bounds }.eachCount()
 
     /** Converts a list of IconPoint into a map of the count of different icon.coord */
     private fun iconsToPosCountMap(widgets: List<IconPoint>) =
-        widgets.groupingBy { it.getCoord() }.eachCount()
+        widgets.groupingBy { it.coord }.eachCount()
 
     override fun compare(
         cellLayoutBoard: CellLayoutBoard,
@@ -47,7 +47,7 @@
             widgetsToBoundsMap(
                 otherCellLayoutBoard.widgets
                     .filter { !it.shouldIgnore() }
-                    .filter { !overlapsWithIgnored(ignoredRectangles, it.mBounds) }
+                    .filter { !overlapsWithIgnored(ignoredRectangles, it.bounds) }
             )
 
         if (widgetsMap != otherWidgetMap) {
diff --git a/tests/multivalentTests/src/com/android/launcher3/celllayout/board/TestWorkspaceBuilder.java b/tests/multivalentTests/src/com/android/launcher3/celllayout/board/TestWorkspaceBuilder.java
deleted file mode 100644
index 8a427dd..0000000
--- a/tests/multivalentTests/src/com/android/launcher3/celllayout/board/TestWorkspaceBuilder.java
+++ /dev/null
@@ -1,192 +0,0 @@
-/*
- * Copyright (C) 2023 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.launcher3.celllayout.board;
-
-import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
-import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
-
-import static com.android.launcher3.ui.TestViewHelpers.findWidgetProvider;
-import static com.android.launcher3.util.WidgetUtils.createWidgetInfo;
-
-import android.content.ComponentName;
-import android.content.Context;
-import android.graphics.Rect;
-import android.os.Process;
-import android.os.UserHandle;
-import android.util.Log;
-
-import com.android.launcher3.InvariantDeviceProfile;
-import com.android.launcher3.LauncherSettings;
-import com.android.launcher3.celllayout.FavoriteItemsTransaction;
-import com.android.launcher3.model.data.AppInfo;
-import com.android.launcher3.model.data.FolderInfo;
-import com.android.launcher3.model.data.ItemInfo;
-import com.android.launcher3.model.data.LauncherAppWidgetInfo;
-import com.android.launcher3.model.data.WorkspaceItemInfo;
-import com.android.launcher3.widget.LauncherAppWidgetProviderInfo;
-
-import java.util.function.Supplier;
-import java.util.stream.IntStream;
-
-public class TestWorkspaceBuilder {
-
-    private static final String TAG = "CellLayoutBoardBuilder";
-    private static final String TEST_ACTIVITY_PACKAGE_PREFIX = "com.android.launcher3.tests.";
-    private ComponentName mAppComponentName = new ComponentName(
-            "com.google.android.calculator", "com.android.calculator2.Calculator");
-    private UserHandle mMyUser;
-
-    private Context mContext;
-
-    public TestWorkspaceBuilder(Context context) {
-        mMyUser = Process.myUserHandle();
-        mContext = context;
-    }
-
-    /**
-     * Fills the given rect in WidgetRect with 1x1 widgets. This is useful to equalize cases.
-     */
-    private FavoriteItemsTransaction fillWithWidgets(WidgetRect widgetRect,
-            FavoriteItemsTransaction transaction, int screenId) {
-        int initX = widgetRect.getCellX();
-        int initY = widgetRect.getCellY();
-        for (int x = initX; x < initX + widgetRect.getSpanX(); x++) {
-            for (int y = initY; y < initY + widgetRect.getSpanY(); y++) {
-                try {
-                    // this widgets are filling, we don't care if we can't place them
-                    transaction.addItem(createWidgetInCell(
-                            new WidgetRect(CellType.IGNORE,
-                                    new Rect(x, y, x, y)), screenId));
-                } catch (Exception e) {
-                    Log.d(TAG, "Unable to place filling widget at " + x + "," + y);
-                }
-            }
-        }
-        return transaction;
-    }
-
-    private AppInfo getApp() {
-        return new AppInfo(mAppComponentName, "test icon", mMyUser,
-                AppInfo.makeLaunchIntent(mAppComponentName));
-    }
-
-    /**
-     * Helper to set the app to use for the test workspace,
-     *  using activity-alias from AndroidManifest-common.
-     * @param testAppName the android:name field of the test app activity-alias to use
-     */
-    public void setTestAppActivityAlias(String testAppName) {
-        this.mAppComponentName = new ComponentName(
-            getInstrumentation().getContext().getPackageName(),
-        TEST_ACTIVITY_PACKAGE_PREFIX + testAppName
-        );
-    }
-
-    private void addCorrespondingWidgetRect(WidgetRect widgetRect,
-            FavoriteItemsTransaction transaction, int screenId) {
-        if (widgetRect.mType == 'x') {
-            fillWithWidgets(widgetRect, transaction, screenId);
-        } else {
-            transaction.addItem(createWidgetInCell(widgetRect, screenId));
-        }
-    }
-
-    /**
-     * Builds the given board into the transaction
-     */
-    public FavoriteItemsTransaction buildFromBoard(CellLayoutBoard board,
-            FavoriteItemsTransaction transaction, final int screenId) {
-        board.getWidgets().forEach(
-                (widgetRect) -> addCorrespondingWidgetRect(widgetRect, transaction, screenId));
-        board.getIcons().forEach((iconPoint) ->
-                transaction.addItem(() -> createIconInCell(iconPoint, screenId))
-        );
-        board.getFolders().forEach((folderPoint) ->
-                transaction.addItem(() -> createFolderInCell(folderPoint, screenId))
-        );
-        return transaction;
-    }
-
-    /**
-     * Fills the hotseat row with apps instead of suggestions, for this to work the workspace should
-     * be clean otherwise this doesn't overrides the existing icons.
-     */
-    public FavoriteItemsTransaction fillHotseatIcons(FavoriteItemsTransaction transaction) {
-        IntStream.range(0, InvariantDeviceProfile.INSTANCE.get(mContext).numDatabaseHotseatIcons)
-                .forEach(i -> transaction.addItem(() -> getHotseatValues(i)));
-        return transaction;
-    }
-
-    private Supplier<ItemInfo> createWidgetInCell(
-            WidgetRect widgetRect, int screenId) {
-        // Create the widget lazily since the appWidgetId can get lost during setup
-        return () -> {
-            LauncherAppWidgetProviderInfo info = findWidgetProvider(false);
-            LauncherAppWidgetInfo item = createWidgetInfo(info, getApplicationContext(), true);
-            item.cellX = widgetRect.getCellX();
-            item.cellY = widgetRect.getCellY();
-            item.spanX = widgetRect.getSpanX();
-            item.spanY = widgetRect.getSpanY();
-            item.screenId = screenId;
-            return item;
-        };
-    }
-
-    public FolderInfo createFolderInCell(FolderPoint folderPoint, int screenId) {
-        FolderInfo folderInfo = new FolderInfo();
-        folderInfo.screenId = screenId;
-        folderInfo.container = LauncherSettings.Favorites.CONTAINER_DESKTOP;
-        folderInfo.cellX = folderPoint.coord.x;
-        folderInfo.cellY = folderPoint.coord.y;
-        folderInfo.minSpanY = folderInfo.minSpanX = folderInfo.spanX = folderInfo.spanY = 1;
-        folderInfo.setOption(FolderInfo.FLAG_MULTI_PAGE_ANIMATION, true, null);
-
-        for (int i = 0; i < folderPoint.getNumberIconsInside(); i++) {
-            folderInfo.add(getDefaultWorkspaceItem(screenId), false);
-        }
-
-        return folderInfo;
-    }
-
-    private WorkspaceItemInfo getDefaultWorkspaceItem(int screenId) {
-        WorkspaceItemInfo item = new WorkspaceItemInfo(getApp());
-        item.screenId = screenId;
-        item.minSpanY = item.minSpanX = item.spanX = item.spanY = 1;
-        item.container = LauncherSettings.Favorites.CONTAINER_DESKTOP;
-        return item;
-    }
-
-    private ItemInfo createIconInCell(IconPoint iconPoint, int screenId) {
-        WorkspaceItemInfo item = new WorkspaceItemInfo(getApp());
-        item.screenId = screenId;
-        item.cellX = iconPoint.getCoord().x;
-        item.cellY = iconPoint.getCoord().y;
-        item.minSpanY = item.minSpanX = item.spanX = item.spanY = 1;
-        item.container = LauncherSettings.Favorites.CONTAINER_DESKTOP;
-        return item;
-    }
-
-    private ItemInfo getHotseatValues(int x) {
-        WorkspaceItemInfo item = new WorkspaceItemInfo(getApp());
-        item.cellX = x;
-        item.cellY = 0;
-        item.minSpanY = item.minSpanX = item.spanX = item.spanY = 1;
-        item.rank = x;
-        item.screenId = x;
-        item.container = LauncherSettings.Favorites.CONTAINER_HOTSEAT;
-        return item;
-    }
-}
diff --git a/tests/multivalentTests/src/com/android/launcher3/celllayout/board/TestWorkspaceBuilder.kt b/tests/multivalentTests/src/com/android/launcher3/celllayout/board/TestWorkspaceBuilder.kt
new file mode 100644
index 0000000..8952b85
--- /dev/null
+++ b/tests/multivalentTests/src/com/android/launcher3/celllayout/board/TestWorkspaceBuilder.kt
@@ -0,0 +1,191 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package com.android.launcher3.celllayout.board
+
+import android.content.ComponentName
+import android.content.Context
+import android.graphics.Rect
+import android.os.Process
+import android.os.UserHandle
+import android.util.Log
+import androidx.test.core.app.ApplicationProvider
+import androidx.test.platform.app.InstrumentationRegistry
+import com.android.launcher3.InvariantDeviceProfile
+import com.android.launcher3.LauncherSettings
+import com.android.launcher3.celllayout.FavoriteItemsTransaction
+import com.android.launcher3.model.data.AppInfo
+import com.android.launcher3.model.data.FolderInfo
+import com.android.launcher3.model.data.ItemInfo
+import com.android.launcher3.model.data.WorkspaceItemInfo
+import com.android.launcher3.ui.TestViewHelpers
+import com.android.launcher3.util.WidgetUtils
+import java.util.function.Supplier
+
+class TestWorkspaceBuilder(private val mContext: Context) {
+
+    private var appComponentName =
+        ComponentName("com.google.android.calculator", "com.android.calculator2.Calculator")
+    private val myUser: UserHandle = Process.myUserHandle()
+
+    /** Fills the given rect in WidgetRect with 1x1 widgets. This is useful to equalize cases. */
+    private fun fillWithWidgets(
+        widgetRect: WidgetRect,
+        transaction: FavoriteItemsTransaction,
+        screenId: Int
+    ): FavoriteItemsTransaction {
+        val initX = widgetRect.cellX
+        val initY = widgetRect.cellY
+        for (x in initX until initX + widgetRect.spanX) {
+            for (y in initY until initY + widgetRect.spanY) {
+                try {
+                    // this widgets are filling, we don't care if we can't place them
+                    transaction.addItem(
+                        createWidgetInCell(WidgetRect(CellType.IGNORE, Rect(x, y, x, y)), screenId)
+                    )
+                } catch (e: Exception) {
+                    Log.d(TAG, "Unable to place filling widget at $x,$y")
+                }
+            }
+        }
+        return transaction
+    }
+
+    private fun app() =
+        AppInfo(appComponentName, "test icon", myUser, AppInfo.makeLaunchIntent(appComponentName))
+
+    /**
+     * Helper to set the app to use for the test workspace, using activity-alias from
+     * AndroidManifest-common.
+     *
+     * @param testAppName the android:name field of the test app activity-alias to use
+     */
+    fun setTestAppActivityAlias(testAppName: String) {
+        appComponentName =
+            ComponentName(
+                InstrumentationRegistry.getInstrumentation().context.packageName,
+                TEST_ACTIVITY_PACKAGE_PREFIX + testAppName
+            )
+    }
+
+    private fun addCorrespondingWidgetRect(
+        widgetRect: WidgetRect,
+        transaction: FavoriteItemsTransaction,
+        screenId: Int
+    ) {
+        if (widgetRect.type == 'x') {
+            fillWithWidgets(widgetRect, transaction, screenId)
+        } else {
+            transaction.addItem(createWidgetInCell(widgetRect, screenId))
+        }
+    }
+
+    /** Builds the given board into the transaction */
+    fun buildFromBoard(
+        board: CellLayoutBoard,
+        transaction: FavoriteItemsTransaction,
+        screenId: Int
+    ): FavoriteItemsTransaction {
+        board.widgets.forEach { addCorrespondingWidgetRect(it, transaction, screenId) }
+        board.icons.forEach { transaction.addItem { createIconInCell(it, screenId) } }
+        board.folders.forEach { transaction.addItem { createFolderInCell(it, screenId) } }
+        return transaction
+    }
+
+    /**
+     * Fills the hotseat row with apps instead of suggestions, for this to work the workspace should
+     * be clean otherwise this doesn't overrides the existing icons.
+     */
+    fun fillHotseatIcons(transaction: FavoriteItemsTransaction): FavoriteItemsTransaction {
+        for (i in 0..<InvariantDeviceProfile.INSTANCE[mContext].numDatabaseHotseatIcons) {
+            transaction.addItem { getHotseatValues(i) }
+        }
+        return transaction
+    }
+
+    private fun createWidgetInCell(widgetRect: WidgetRect, paramScreenId: Int): Supplier<ItemInfo> {
+        // Create the widget lazily since the appWidgetId can get lost during setup
+        return Supplier<ItemInfo> {
+            WidgetUtils.createWidgetInfo(
+                    TestViewHelpers.findWidgetProvider(false),
+                    ApplicationProvider.getApplicationContext(),
+                    true
+                )
+                .apply {
+                    cellX = widgetRect.cellX
+                    cellY = widgetRect.cellY
+                    spanX = widgetRect.spanX
+                    spanY = widgetRect.spanY
+                    screenId = paramScreenId
+                }
+        }
+    }
+
+    fun createFolderInCell(folderPoint: FolderPoint, paramScreenId: Int): FolderInfo =
+        FolderInfo().apply {
+            screenId = paramScreenId
+            container = LauncherSettings.Favorites.CONTAINER_DESKTOP
+            cellX = folderPoint.coord.x
+            cellY = folderPoint.coord.y
+            spanY = 1
+            spanX = 1
+            minSpanX = 1
+            minSpanY = 1
+            setOption(FolderInfo.FLAG_MULTI_PAGE_ANIMATION, true, null)
+            for (i in 0 until folderPoint.numberIconsInside) {
+                add(getDefaultWorkspaceItem(paramScreenId), false)
+            }
+        }
+
+    private fun getDefaultWorkspaceItem(paramScreenId: Int): WorkspaceItemInfo =
+        WorkspaceItemInfo(app()).apply {
+            screenId = paramScreenId
+            spanY = 1
+            spanX = 1
+            minSpanX = 1
+            minSpanY = 1
+            container = LauncherSettings.Favorites.CONTAINER_DESKTOP
+        }
+
+    private fun createIconInCell(iconPoint: IconPoint, paramScreenId: Int) =
+        WorkspaceItemInfo(app()).apply {
+            screenId = paramScreenId
+            cellX = iconPoint.coord.x
+            cellY = iconPoint.coord.y
+            spanY = 1
+            spanX = 1
+            minSpanX = 1
+            minSpanY = 1
+            container = LauncherSettings.Favorites.CONTAINER_DESKTOP
+        }
+
+    private fun getHotseatValues(x: Int) =
+        WorkspaceItemInfo(app()).apply {
+            cellX = x
+            cellY = 0
+            spanY = 1
+            spanX = 1
+            minSpanX = 1
+            minSpanY = 1
+            rank = x
+            screenId = x
+            container = LauncherSettings.Favorites.CONTAINER_HOTSEAT
+        }
+
+    companion object {
+        private const val TAG = "CellLayoutBoardBuilder"
+        private const val TEST_ACTIVITY_PACKAGE_PREFIX = "com.android.launcher3.tests."
+    }
+}
diff --git a/tests/multivalentTests/src/com/android/launcher3/celllayout/board/WidgetRect.java b/tests/multivalentTests/src/com/android/launcher3/celllayout/board/WidgetRect.java
deleted file mode 100644
index c90ce85..0000000
--- a/tests/multivalentTests/src/com/android/launcher3/celllayout/board/WidgetRect.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright (C) 2023 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.launcher3.celllayout.board;
-
-import android.graphics.Rect;
-
-public class WidgetRect {
-    public char mType;
-    public Rect mBounds;
-
-    public WidgetRect(char type, Rect bounds) {
-        this.mType = type;
-        this.mBounds = bounds;
-    }
-
-    public int getSpanX() {
-        return mBounds.right - mBounds.left + 1;
-    }
-
-    public int getSpanY() {
-        return mBounds.top - mBounds.bottom + 1;
-    }
-
-    public int getCellX() {
-        return mBounds.left;
-    }
-
-    public int getCellY() {
-        return mBounds.bottom;
-    }
-
-    boolean shouldIgnore() {
-        return this.mType == CellType.IGNORE;
-    }
-
-    boolean contains(int x, int y) {
-        return mBounds.contains(x, y);
-    }
-
-    @Override
-    public String toString() {
-        return "WidgetRect type = " + mType + " x = " + getCellX() + " | y " + getCellY()
-                + " xs = " + getSpanX() + " ys = " + getSpanY();
-    }
-}