summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Grover <joeygrover@gmail.com>2019-10-10 15:07:38 -0400
committerJoey Grover <joeygrover@gmail.com>2019-10-10 15:07:38 -0400
commit1ac694277dac36257ef3febc225dfeee435caab8 (patch)
treee5ec070b9e63e798aa4854e51ce9de1b585f1d39
parente5a9220d382f9ba0c03a71a238ce2683fe4c6e8d (diff)
downloadsdl_android-1ac694277dac36257ef3febc225dfeee435caab8.tar.gz
Update MenuCell clone method
-rw-r--r--android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuCellTests.java16
-rw-r--r--base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java32
2 files changed, 27 insertions, 21 deletions
diff --git a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuCellTests.java b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuCellTests.java
index 6aa9b479a..3800eea41 100644
--- a/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuCellTests.java
+++ b/android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/menu/MenuCellTests.java
@@ -33,6 +33,7 @@
package com.smartdevicelink.managers.screen.menu;
import com.smartdevicelink.AndroidTestCase2;
+import com.smartdevicelink.managers.file.SdlArtworkTests;
import com.smartdevicelink.proxy.rpc.enums.MenuLayout;
import com.smartdevicelink.proxy.rpc.enums.TriggerSource;
import com.smartdevicelink.test.Test;
@@ -116,4 +117,19 @@ public class MenuCellTests extends AndroidTestCase2 {
assertFalse(menuCell.equals(menuCell3));
}
+ public void testClone(){
+ MenuCell original = new MenuCell(Test.GENERAL_STRING, Test.GENERAL_ARTWORK, Test.GENERAL_STRING_LIST, menuSelectionListener);
+ MenuCell clone = original.clone();
+
+ assertNotNull(clone);
+ assertNotSame(original, clone);
+
+ assertEquals(original.getTitle(), clone.getTitle());
+ assertEquals(original.getCellId(), clone.getCellId());
+ assertEquals(original.getParentCellId(), clone.getParentCellId());
+
+ SdlArtworkTests.equalTest(original.getIcon(), clone.getIcon());
+
+ }
+
}
diff --git a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java
index 519dcad93..a922c9d59 100644
--- a/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java
+++ b/base/src/main/java/com/smartdevicelink/managers/screen/menu/MenuCell.java
@@ -37,6 +37,7 @@ import android.support.annotation.Nullable;
import com.smartdevicelink.managers.file.filetypes.SdlArtwork;
import com.smartdevicelink.proxy.rpc.enums.MenuLayout;
+import com.smartdevicelink.util.DebugTool;
import java.util.ArrayList;
import java.util.List;
@@ -322,33 +323,22 @@ public class MenuCell implements Cloneable{
/**
* Creates a deep copy of the object
- * @return deep copy of the object
+ * @return deep copy of the object, null if an exception occurred
*/
@Override
public MenuCell clone() {
- final MenuCell clone;
try {
- clone = (MenuCell) super.clone();
+ MenuCell clone = (MenuCell) super.clone();
+ if(this.icon != null){
+ clone.setIcon(this.icon.clone());
+ }
+ return clone;
} catch (CloneNotSupportedException e) {
- throw new RuntimeException("superclass messed up", e);
- }
- clone.title = this.title;
- clone.icon = this.icon == null ? null : this.icon.clone();
- clone.voiceCommands = null;
- if (this.voiceCommands != null){
- clone.voiceCommands = new ArrayList<>();
- clone.voiceCommands.addAll(this.voiceCommands);
- }
- clone.subCells = null;
- if (this.subCells != null) {
- clone.subCells = new ArrayList<>();
- for (MenuCell subCell : this.subCells) {
- clone.subCells.add(subCell == null ? null : subCell.clone());
+ if(DebugTool.isDebugEnabled()){
+ throw new RuntimeException("Clone not supported by super class");
}
}
- clone.menuSelectionListener = this.menuSelectionListener;
- clone.parentCellId = this.parentCellId;
- clone.cellId = this.cellId;
- return clone;
+
+ return null;
}
}