Skip to content

Commit cdadf4e

Browse files
Update unit tests to include tests for WindowCapabilitySupportsPrimaryImage()
1 parent 445c576 commit cdadf4e

2 files changed

Lines changed: 81 additions & 6 deletions

File tree

android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuManagerTests.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,15 @@ public void testSettingNonUniqueCells() {
261261

262262
@Test
263263
public void testUpdatingOldWay() {
264+
ISdl internalInterface = mock(ISdl.class);
265+
when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(new Version(8, 0, 0)));
266+
264267
// Force Menu Manager to use the old way of deleting / sending all
265268
menuManager.setDynamicUpdatesMode(DynamicMenuUpdatesMode.FORCE_OFF);
266269
assertEquals(menuManager.dynamicMenuUpdatesMode, DynamicMenuUpdatesMode.FORCE_OFF);
267270
// when we only send one command to update, we should only be returned one add command
268271
List<MenuCell> newArray = Arrays.asList(mainCell1, mainCell4);
269-
assertEquals(MenuReplaceUtilities.allCommandsForCells(newArray, menuManager.fileManager.get(), menuManager.windowCapability, MenuLayout.LIST).size(), 4); // 1 root cells, 1 sub menu root cell, 2 sub menu cells
272+
assertEquals(MenuReplaceUtilities.allCommandsForCells(internalInterface, newArray, menuManager.fileManager.get(), menuManager.windowCapability, MenuLayout.LIST).size(), 4); // 1 root cells, 1 sub menu root cell, 2 sub menu cells
270273
menuManager.currentHMILevel = HMILevel.HMI_FULL;
271274
menuManager.setMenuCells(newArray);
272275

android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuReplaceUtilitiesTests.java

Lines changed: 77 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,16 @@
3434

3535
import androidx.test.ext.junit.runners.AndroidJUnit4;
3636

37+
import com.smartdevicelink.managers.ISdl;
3738
import com.smartdevicelink.managers.file.FileManager;
3839
import com.smartdevicelink.managers.file.filetypes.SdlArtwork;
3940
import com.smartdevicelink.proxy.rpc.ImageField;
41+
import com.smartdevicelink.proxy.rpc.SdlMsgVersion;
4042
import com.smartdevicelink.proxy.rpc.WindowCapability;
4143
import com.smartdevicelink.proxy.rpc.enums.ImageFieldName;
4244
import com.smartdevicelink.proxy.rpc.enums.MenuLayout;
4345
import com.smartdevicelink.test.TestValues;
46+
import com.smartdevicelink.util.Version;
4447

4548
import org.junit.Before;
4649
import org.junit.Test;
@@ -209,8 +212,77 @@ public void testAddMenuRequestWithCommandId() {
209212
assertEquals(1, actualMenuCellList.get(4).getSubCells().get(1).getSubCells().size());
210213
}
211214

215+
@Test
216+
public void testWindowCapabilitySupportsPrimaryImage() {
217+
WindowCapability windowCapability;
218+
ISdl internalInterface = mock(ISdl.class);
219+
MenuCell menuCell = mock(MenuCell.class);
220+
221+
// Test case 0
222+
windowCapability = createWindowCapability(false, true);
223+
when(menuCell.isSubMenuCell()).thenReturn(true);
224+
when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(new Version(4, 9, 0)));
225+
assertTrue(MenuReplaceUtilities.windowCapabilitySupportsPrimaryImage(internalInterface, windowCapability, menuCell));
226+
227+
// Test case 1
228+
windowCapability = createWindowCapability(false, false);
229+
when(menuCell.isSubMenuCell()).thenReturn(true);
230+
when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(new Version(4, 9, 0)));
231+
assertFalse(MenuReplaceUtilities.windowCapabilitySupportsPrimaryImage(internalInterface, windowCapability, menuCell));
232+
233+
// Test case 2
234+
windowCapability = createWindowCapability(false, false);
235+
when(menuCell.isSubMenuCell()).thenReturn(true);
236+
when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(new Version(5, 0, 0)));
237+
assertTrue(MenuReplaceUtilities.windowCapabilitySupportsPrimaryImage(internalInterface, windowCapability, menuCell));
238+
239+
// Test case 3
240+
windowCapability = createWindowCapability(false, false);
241+
when(menuCell.isSubMenuCell()).thenReturn(true);
242+
when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(new Version(6, 0, 0)));
243+
assertTrue(MenuReplaceUtilities.windowCapabilitySupportsPrimaryImage(internalInterface, windowCapability, menuCell));
244+
245+
// Test case 4
246+
windowCapability = createWindowCapability(false, false);
247+
when(menuCell.isSubMenuCell()).thenReturn(true);
248+
when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(new Version(7, 0, 0)));
249+
assertTrue(MenuReplaceUtilities.windowCapabilitySupportsPrimaryImage(internalInterface, windowCapability, menuCell));
250+
251+
// Test case 5
252+
windowCapability = createWindowCapability(false, false);
253+
when(menuCell.isSubMenuCell()).thenReturn(true);
254+
when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(new Version(7, 1, 0)));
255+
assertFalse(MenuReplaceUtilities.windowCapabilitySupportsPrimaryImage(internalInterface, windowCapability, menuCell));
256+
257+
// Test case 6
258+
windowCapability = createWindowCapability(false, false);
259+
when(menuCell.isSubMenuCell()).thenReturn(true);
260+
when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(new Version(8, 0, 0)));
261+
assertFalse(MenuReplaceUtilities.windowCapabilitySupportsPrimaryImage(internalInterface, windowCapability, menuCell));
262+
263+
// Test case 7
264+
windowCapability = createWindowCapability(false, true);
265+
when(menuCell.isSubMenuCell()).thenReturn(true);
266+
when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(new Version(8, 0, 0)));
267+
assertTrue(MenuReplaceUtilities.windowCapabilitySupportsPrimaryImage(internalInterface, windowCapability, menuCell));
268+
269+
// Test case 8
270+
windowCapability = createWindowCapability(false, false);
271+
when(menuCell.isSubMenuCell()).thenReturn(false);
272+
when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(new Version(8, 0, 0)));
273+
assertFalse(MenuReplaceUtilities.windowCapabilitySupportsPrimaryImage(internalInterface, windowCapability, menuCell));
274+
275+
// Test case 8
276+
windowCapability = createWindowCapability(true, false);
277+
when(menuCell.isSubMenuCell()).thenReturn(false);
278+
when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(new Version(8, 0, 0)));
279+
assertTrue(MenuReplaceUtilities.windowCapabilitySupportsPrimaryImage(internalInterface, windowCapability, menuCell));
280+
}
281+
212282
@Test
213283
public void testShouldCellIncludeImage() {
284+
ISdl internalInterface = mock(ISdl.class);
285+
when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(new Version(8, 0, 0)));
214286
MenuCell menuCell;
215287
WindowCapability windowCapability;
216288
FileManager fileManager;
@@ -220,31 +292,31 @@ public void testShouldCellIncludeImage() {
220292
menuCell = new MenuCell(TestValues.GENERAL_STRING, TestValues.GENERAL_ARTWORK, voiceCommands, null);
221293
windowCapability = createWindowCapability(true, true);
222294
fileManager = createMockFileManager(true);
223-
assertTrue(MenuReplaceUtilities.shouldCellIncludePrimaryImageFromCell(menuCell, fileManager, windowCapability));
295+
assertTrue(MenuReplaceUtilities.shouldCellIncludePrimaryImageFromCell(internalInterface, menuCell, fileManager, windowCapability));
224296

225297
// Case 2 - Image are not supported
226298
menuCell = new MenuCell(TestValues.GENERAL_STRING, TestValues.GENERAL_ARTWORK, voiceCommands, null);
227299
windowCapability = createWindowCapability(false, false);
228300
fileManager = createMockFileManager(true);
229-
assertFalse(MenuReplaceUtilities.shouldCellIncludePrimaryImageFromCell(menuCell, fileManager, windowCapability));
301+
assertFalse(MenuReplaceUtilities.shouldCellIncludePrimaryImageFromCell(internalInterface, menuCell, fileManager, windowCapability));
230302

231303
// Case 3 - Artwork is null
232304
menuCell = new MenuCell(TestValues.GENERAL_STRING, null, voiceCommands, null);
233305
windowCapability = createWindowCapability(true, true);
234306
fileManager = createMockFileManager(true);
235-
assertFalse(MenuReplaceUtilities.shouldCellIncludePrimaryImageFromCell(menuCell, fileManager, windowCapability));
307+
assertFalse(MenuReplaceUtilities.shouldCellIncludePrimaryImageFromCell(internalInterface, menuCell, fileManager, windowCapability));
236308

237309
// Case 4 - Artwork has not been uploaded
238310
menuCell = new MenuCell(TestValues.GENERAL_STRING, TestValues.GENERAL_ARTWORK, voiceCommands, null);
239311
windowCapability = createWindowCapability(true, true);
240312
fileManager = createMockFileManager(false);
241-
assertFalse(MenuReplaceUtilities.shouldCellIncludePrimaryImageFromCell(menuCell, fileManager, windowCapability));
313+
assertFalse(MenuReplaceUtilities.shouldCellIncludePrimaryImageFromCell(internalInterface, menuCell, fileManager, windowCapability));
242314

243315
// Case 5 - Artwork is static icon
244316
menuCell = new MenuCell(TestValues.GENERAL_STRING, TestValues.GENERAL_ARTWORK_STATIC, voiceCommands, null);
245317
windowCapability = createWindowCapability(true, true);
246318
fileManager = createMockFileManager(false);
247-
assertTrue(MenuReplaceUtilities.shouldCellIncludePrimaryImageFromCell(menuCell, fileManager, windowCapability));
319+
assertTrue(MenuReplaceUtilities.shouldCellIncludePrimaryImageFromCell(internalInterface, menuCell, fileManager, windowCapability));
248320
}
249321

250322
private WindowCapability createWindowCapability (boolean supportsCmdIcon, boolean supportsSubMenuIcon) {

0 commit comments

Comments
 (0)