Skip to content

Commit 44b38cb

Browse files
authored
Bugfix/issue 1828 Good text failing (#1831)
* Added updateTargetStateWithErrorState() method * Added updatePendingOperationsWithFailedScreenState method. * Added testUpdateTargetStateWithErrorSendingBadData() testing method. * Testing cleanup for clarity * Added null checks for references in updateTargetStateWithErrorState * Added additional tests. * Modified updateTargetStateWithErrorState method to use null safe Objects.equals() * Applying feedback: Made suggested formatting changes. Removed unused supersedePreviousOperations and currentOperationListener variables. Changed passed in reference from updatedState to null for currentScreenDataListener.onError() when text update has not been sent. * Adjusted when updateTargetStateWithErrorState is called. Modified currentScreenDataUpdateListener.onError(updatedState) from null to updatedState.
1 parent 6e6040d commit 44b38cb

File tree

3 files changed

+280
-59
lines changed

3 files changed

+280
-59
lines changed

android/sdl_android/src/androidTest/java/com/smartdevicelink/managers/screen/TextAndGraphicUpdateOperationTest.java

Lines changed: 194 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,24 @@
5252
import static org.mockito.Mockito.verify;
5353
import static org.mockito.Mockito.when;
5454

55+
import junit.framework.TestCase;
56+
5557
@RunWith(AndroidJUnit4.class)
5658
public class TextAndGraphicUpdateOperationTest {
5759

5860
private TextAndGraphicUpdateOperation textAndGraphicUpdateOperation;
5961
private String textField1, textField2, textField3, textField4, mediaTrackField, title;
60-
private MetadataType textField1Type, textField2Type, textField3Type, textField4Type;
61-
private SdlArtwork testArtwork1, testArtwork2, testArtwork3, testArtwork4;
62-
private TextAlignment textAlignment;
62+
private String textField1Fail, textField2Fail, textField3Fail, textField4Fail, mediaTrackFieldFail, titleFail;
63+
private MetadataType textField1Type, textField2Type, textField3Type, textField4Type, textFieldFailType;
64+
private SdlArtwork testArtwork1, testArtwork2, testArtwork3, testArtwork4, testArtworkFail;
65+
private TextAlignment textAlignment, textAlignmentFail;
6366
private WindowCapability defaultMainWindowCapability;
6467
private TextAndGraphicState currentScreenData;
68+
private TextAndGraphicState errorTestState, errorTestState2;
6569
private CompletionListener listener;
6670
private TextAndGraphicManager.CurrentScreenDataUpdatedListener currentScreenDataUpdatedListener;
6771
private SdlArtwork blankArtwork;
68-
private TemplateConfiguration configuration;
72+
private TemplateConfiguration configuration, configurationFail;
6973
ISdl internalInterface;
7074
FileManager fileManager;
7175

@@ -188,6 +192,13 @@ public void setUp() throws Exception {
188192
mediaTrackField = "dudes";
189193
title = "dudes";
190194

195+
textField1Fail = "It is\nbad data";
196+
textField2Fail = "Wednesday\nbad data";
197+
textField3Fail = "My\nbad data";
198+
textField4Fail = "Dudes\nbad data";
199+
mediaTrackFieldFail = "dudes\nbad data";
200+
titleFail = "dudes\nbad data";
201+
191202
blankArtwork = new SdlArtwork();
192203
blankArtwork.setType(FileType.GRAPHIC_PNG);
193204
blankArtwork.setName("blankArtwork");
@@ -197,9 +208,10 @@ public void setUp() throws Exception {
197208
textField2Type = MetadataType.MEDIA_TITLE;
198209
textField3Type = MetadataType.MEDIA_TITLE;
199210
textField4Type = MetadataType.MEDIA_TITLE;
200-
211+
textFieldFailType = MetadataType.valueForString("failType");
201212

202213
textAlignment = TextAlignment.CENTERED;
214+
textAlignmentFail = TextAlignment.valueForString("failAlignment");
203215

204216
testArtwork1 = new SdlArtwork();
205217
testArtwork1.setName("testFile1");
@@ -225,9 +237,37 @@ public void setUp() throws Exception {
225237
testArtwork4.setUri(uri4);
226238
testArtwork4.setType(FileType.GRAPHIC_PNG);
227239

240+
testArtworkFail = new SdlArtwork();
241+
testArtworkFail.setName("testFileFail");
242+
Uri uriFail = Uri.parse("android.resource://" + mTestContext.getPackageName() + "/no_file");
243+
testArtworkFail.setUri(uriFail);
244+
testArtworkFail.setType(FileType.GRAPHIC_PNG);
245+
228246
configuration = new TemplateConfiguration();
229247
configuration.setTemplate(PredefinedLayout.GRAPHIC_WITH_TEXT.toString());
230248

249+
configurationFail = new TemplateConfiguration();
250+
configurationFail.setTemplate("failConfiguration");
251+
252+
errorTestState = new TextAndGraphicState();
253+
errorTestState2 = new TextAndGraphicState();
254+
255+
errorTestState2.setTextField1(textField1);
256+
errorTestState2.setTextField2(textField2);
257+
errorTestState2.setTextField3(textField3Fail);
258+
errorTestState2.setTextField4(textField4Fail);
259+
errorTestState2.setTextField1Type(textFieldFailType);
260+
errorTestState2.setTextField2Type(textFieldFailType);
261+
errorTestState2.setTextField3Type(textFieldFailType);
262+
errorTestState2.setTextField4Type(textFieldFailType);
263+
errorTestState2.setMediaTrackTextField(mediaTrackFieldFail);
264+
errorTestState2.setTitle(titleFail);
265+
errorTestState2.setPrimaryGraphic(testArtworkFail);
266+
errorTestState2.setSecondaryGraphic(testArtworkFail);
267+
errorTestState2.setTextAlignment(textAlignmentFail);
268+
errorTestState2.setTemplateConfiguration(configurationFail);
269+
270+
231271
currentScreenData = new TextAndGraphicState();
232272
currentScreenData.setTextField1("Old");
233273
currentScreenData.setTextField2("Text");
@@ -241,12 +281,10 @@ public void setUp() throws Exception {
241281
currentScreenDataUpdatedListener = new TextAndGraphicManager.CurrentScreenDataUpdatedListener() {
242282
@Override
243283
public void onUpdate(TextAndGraphicState newState) {
244-
245284
}
246285

247286
@Override
248-
public void onError() {
249-
287+
public void onError(TextAndGraphicState errorState) {
250288
}
251289
};
252290

@@ -257,7 +295,6 @@ public void onError() {
257295
textAndGraphicUpdateOperation = new TextAndGraphicUpdateOperation(internalInterface, fileManager, defaultMainWindowCapability, currentScreenData, textsAndGraphicsState, listener, currentScreenDataUpdatedListener);
258296
}
259297

260-
261298
private void setUpCompletionListener() {
262299
listener = new CompletionListener() {
263300
@Override
@@ -1017,4 +1054,152 @@ public void testOnShowFail() {
10171054

10181055
}
10191056

1057+
@Test
1058+
public void testOnShowFailBadDataDoesNotUpdateScreen(){
1059+
doAnswer(onShowFail).when(internalInterface).sendRPC(any(Show.class));
1060+
doAnswer(onArtworkUploadSuccess).when(fileManager).uploadArtworks(any(List.class), any(MultipleFileCompletionListener.class));
1061+
when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(4, 0));
1062+
1063+
TextAndGraphicState textsAndGraphicsState = new TextAndGraphicState(textField1Fail, textField2Fail, textField3Fail, textField4Fail,
1064+
mediaTrackFieldFail, titleFail, testArtworkFail, testArtworkFail, textAlignmentFail, textFieldFailType, textFieldFailType, textFieldFailType, textFieldFailType, configurationFail);
1065+
textAndGraphicUpdateOperation = new TextAndGraphicUpdateOperation(internalInterface, fileManager, defaultMainWindowCapability, currentScreenData, textsAndGraphicsState, listener, currentScreenDataUpdatedListener);
1066+
1067+
// Test Images need to be uploaded, sending text and uploading images
1068+
textAndGraphicUpdateOperation.onExecute();
1069+
1070+
// Sending in bad data should result in no updates to the current screen
1071+
assertEquals("Old", textAndGraphicUpdateOperation.getCurrentScreenData().getTextField1());
1072+
assertEquals("Text", textAndGraphicUpdateOperation.getCurrentScreenData().getTextField2());
1073+
assertEquals("Not", textAndGraphicUpdateOperation.getCurrentScreenData().getTextField3());
1074+
assertEquals("Important", textAndGraphicUpdateOperation.getCurrentScreenData().getTextField4());
1075+
TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getMediaTrackTextField());
1076+
assertEquals(testArtwork1, textAndGraphicUpdateOperation.getCurrentScreenData().getPrimaryGraphic());
1077+
assertEquals(testArtwork2, textAndGraphicUpdateOperation.getCurrentScreenData().getSecondaryGraphic());
1078+
TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getTextAlignment());
1079+
TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getTextField1Type());
1080+
TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getTextField2Type());
1081+
TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getTextField3Type());
1082+
TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getTextField4Type());
1083+
assertEquals(configuration, textAndGraphicUpdateOperation.getCurrentScreenData().getTemplateConfiguration());
1084+
}
1085+
1086+
@Test
1087+
public void testUpdateTargetStateWithErrorStateNullDoesNotUpdateCurrentScreen() {
1088+
when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(4, 0));
1089+
1090+
errorTestState.setTextField1(null);
1091+
errorTestState.setTextField2(null);
1092+
errorTestState.setTextField3(null);
1093+
errorTestState.setTextField4(null);
1094+
errorTestState.setTextField1Type(null);
1095+
errorTestState.setTextField2Type(null);
1096+
errorTestState.setTextField3Type(null);
1097+
errorTestState.setTextField4Type(null);
1098+
errorTestState.setMediaTrackTextField(null);
1099+
errorTestState.setTitle(null);
1100+
errorTestState.setPrimaryGraphic(null);
1101+
errorTestState.setSecondaryGraphic(null);
1102+
errorTestState.setTextAlignment(null);
1103+
errorTestState.setTemplateConfiguration(null);
1104+
1105+
textAndGraphicUpdateOperation = new TextAndGraphicUpdateOperation(internalInterface, fileManager, defaultMainWindowCapability, currentScreenData, errorTestState, listener, currentScreenDataUpdatedListener);
1106+
// Testing updateTargetStateWithErrorState method
1107+
textAndGraphicUpdateOperation.updateTargetStateWithErrorState(errorTestState);
1108+
textAndGraphicUpdateOperation.onExecute();
1109+
1110+
// Setting fields to null should result in no updates to the current screen
1111+
assertEquals("Old", textAndGraphicUpdateOperation.getCurrentScreenData().getTextField1());
1112+
assertEquals("Text", textAndGraphicUpdateOperation.getCurrentScreenData().getTextField2());
1113+
assertEquals("Not", textAndGraphicUpdateOperation.getCurrentScreenData().getTextField3());
1114+
assertEquals("Important", textAndGraphicUpdateOperation.getCurrentScreenData().getTextField4());
1115+
TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getMediaTrackTextField());
1116+
assertEquals(testArtwork1, textAndGraphicUpdateOperation.getCurrentScreenData().getPrimaryGraphic());
1117+
assertEquals(testArtwork2, textAndGraphicUpdateOperation.getCurrentScreenData().getSecondaryGraphic());
1118+
TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getTextAlignment());
1119+
TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getTextField1Type());
1120+
TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getTextField2Type());
1121+
TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getTextField3Type());
1122+
TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getTextField4Type());
1123+
assertEquals(configuration, textAndGraphicUpdateOperation.getCurrentScreenData().getTemplateConfiguration());
1124+
}
1125+
1126+
@Test
1127+
public void testUpdateTargetStateWithErrorBadDataDoesNotUpdateCurrentScreen() {
1128+
when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(4, 0));
1129+
1130+
errorTestState.setTextField1(textField1Fail);
1131+
errorTestState.setTextField2(textField2Fail);
1132+
errorTestState.setTextField3(textField3Fail);
1133+
errorTestState.setTextField4(textField4Fail);
1134+
errorTestState.setTextField1Type(textFieldFailType);
1135+
errorTestState.setTextField2Type(textFieldFailType);
1136+
errorTestState.setTextField3Type(textFieldFailType);
1137+
errorTestState.setTextField4Type(textFieldFailType);
1138+
errorTestState.setMediaTrackTextField(mediaTrackFieldFail);
1139+
errorTestState.setTitle(titleFail);
1140+
errorTestState.setPrimaryGraphic(testArtworkFail);
1141+
errorTestState.setSecondaryGraphic(testArtworkFail);
1142+
errorTestState.setTextAlignment(textAlignmentFail);
1143+
errorTestState.setTemplateConfiguration(configurationFail);
1144+
1145+
textAndGraphicUpdateOperation = new TextAndGraphicUpdateOperation(internalInterface, fileManager, defaultMainWindowCapability, currentScreenData, errorTestState, listener, currentScreenDataUpdatedListener);
1146+
// Testing updateTargetStateWithErrorState method
1147+
textAndGraphicUpdateOperation.updateTargetStateWithErrorState(errorTestState);
1148+
textAndGraphicUpdateOperation.onExecute();
1149+
1150+
// Setting bad data should result in no updates to the current screen
1151+
assertEquals("Old", textAndGraphicUpdateOperation.getCurrentScreenData().getTextField1());
1152+
assertEquals("Text", textAndGraphicUpdateOperation.getCurrentScreenData().getTextField2());
1153+
assertEquals("Not", textAndGraphicUpdateOperation.getCurrentScreenData().getTextField3());
1154+
assertEquals("Important", textAndGraphicUpdateOperation.getCurrentScreenData().getTextField4());
1155+
TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getMediaTrackTextField());
1156+
assertEquals(testArtwork1, textAndGraphicUpdateOperation.getCurrentScreenData().getPrimaryGraphic());
1157+
assertEquals(testArtwork2, textAndGraphicUpdateOperation.getCurrentScreenData().getSecondaryGraphic());
1158+
TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getTextAlignment());
1159+
TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getTextField1Type());
1160+
TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getTextField2Type());
1161+
TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getTextField3Type());
1162+
TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getTextField4Type());
1163+
assertEquals(configuration, textAndGraphicUpdateOperation.getCurrentScreenData().getTemplateConfiguration());
1164+
}
1165+
1166+
@Test
1167+
public void testUpdateTargetStateWithErrorBadDataAndGoodData() {
1168+
when(internalInterface.getSdlMsgVersion()).thenReturn(new SdlMsgVersion(4, 0));
1169+
1170+
errorTestState2.setTextField1(textField1Fail);
1171+
errorTestState2.setTextField2(textField2);
1172+
errorTestState2.setTextField3(null);
1173+
errorTestState2.setTextField4(textField4Fail);
1174+
errorTestState2.setTextField1Type(textFieldFailType);
1175+
errorTestState2.setTextField2Type(textFieldFailType);
1176+
errorTestState2.setTextField3Type(textFieldFailType);
1177+
errorTestState2.setTextField4Type(textFieldFailType);
1178+
errorTestState2.setMediaTrackTextField(mediaTrackFieldFail);
1179+
errorTestState2.setTitle(titleFail);
1180+
errorTestState2.setPrimaryGraphic(testArtworkFail);
1181+
errorTestState2.setSecondaryGraphic(testArtworkFail);
1182+
errorTestState2.setTextAlignment(textAlignmentFail);
1183+
errorTestState2.setTemplateConfiguration(configurationFail);
1184+
1185+
textAndGraphicUpdateOperation = new TextAndGraphicUpdateOperation(internalInterface, fileManager, defaultMainWindowCapability, currentScreenData, errorTestState2, listener, currentScreenDataUpdatedListener);
1186+
// Testing updateTargetStateWithErrorState method
1187+
textAndGraphicUpdateOperation.updateTargetStateWithErrorState(errorTestState2);
1188+
textAndGraphicUpdateOperation.onExecute();
1189+
1190+
// Setting mix of good and bad data should result in only updates to those fields with good data
1191+
assertEquals("Old", textAndGraphicUpdateOperation.getCurrentScreenData().getTextField1());
1192+
assertEquals(errorTestState2.getTextField2(), textAndGraphicUpdateOperation.getCurrentScreenData().getTextField2());
1193+
assertEquals("Not", textAndGraphicUpdateOperation.getCurrentScreenData().getTextField3());
1194+
assertEquals("Important", textAndGraphicUpdateOperation.getCurrentScreenData().getTextField4());
1195+
TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getMediaTrackTextField());
1196+
assertEquals(errorTestState2.getPrimaryGraphic(), textAndGraphicUpdateOperation.getCurrentScreenData().getPrimaryGraphic());
1197+
assertEquals(errorTestState2.getSecondaryGraphic(), textAndGraphicUpdateOperation.getCurrentScreenData().getSecondaryGraphic());
1198+
TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getTextAlignment());
1199+
TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getTextField1Type());
1200+
TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getTextField2Type());
1201+
TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getTextField3Type());
1202+
TestCase.assertNull(textAndGraphicUpdateOperation.getCurrentScreenData().getTextField4Type());
1203+
assertEquals(configuration, textAndGraphicUpdateOperation.getCurrentScreenData().getTemplateConfiguration());
1204+
}
10201205
}

0 commit comments

Comments
 (0)