4444import java .util .Collections ;
4545import java .util .List ;
4646
47+
4748import static junit .framework .TestCase .assertEquals ;
4849import static junit .framework .TestCase .assertFalse ;
4950import static junit .framework .TestCase .assertNull ;
@@ -350,8 +351,8 @@ public void onEvent(SoftButtonObject softButtonObject, OnButtonEvent onButtonEve
350351 softButtonStateList .add (softButtonState1 );
351352 softButtonStateList2 .add (softButtonState1 );
352353 softButtonStateList2 .add (softButtonState2 );
353- softButtonObject1 = new SoftButtonObject ("hi" , softButtonStateList , "Hi" , null );
354- softButtonObject2 = new SoftButtonObject ("hi" , softButtonStateList2 , "Hi" , null );
354+ softButtonObject1 = new SoftButtonObject ("hi" , softButtonStateList , softButtonStateList . get ( 0 ). getName () , null );
355+ softButtonObject2 = new SoftButtonObject ("hi" , softButtonStateList2 , softButtonStateList2 . get ( 0 ). getName () , null );
355356 assertNotEquals (softButtonObject1 , softButtonObject2 );
356357
357358 // Case 5: SoftButtonStates are not the same, assertFalse
@@ -365,8 +366,8 @@ public void onEvent(SoftButtonObject softButtonObject, OnButtonEvent onButtonEve
365366 assertNotEquals (softButtonObject1 , softButtonObject2 );
366367
367368 // Case 7: SoftButtonObject currentStateName not same, assertFalse
368- softButtonObject1 = new SoftButtonObject ("hi" , softButtonStateList , "Hi" , null );
369- softButtonObject2 = new SoftButtonObject ("hi" , softButtonStateList , "Hi2" , null );
369+ softButtonObject1 = new SoftButtonObject ("hi" , softButtonStateList2 , softButtonStateList2 . get ( 0 ). getName () , null );
370+ softButtonObject2 = new SoftButtonObject ("hi" , softButtonStateList2 , softButtonStateList2 . get ( 1 ). getName () , null );
370371 assertNotEquals (softButtonObject1 , softButtonObject2 );
371372 }
372373
@@ -402,4 +403,117 @@ public void testSoftButtonStateEquals() {
402403 softButtonState2 = new SoftButtonState ("object1-state1" , "o1s1" , artwork1 );
403404 assertEquals (softButtonState1 , softButtonState2 );
404405 }
406+
407+ /**
408+ * Test constructing SoftButtonObject with an empty state list
409+ */
410+ @ Test
411+ public void testConstructSoftButtonObjectWithEmptyStateList () {
412+ List <SoftButtonState > stateList = new ArrayList <>();
413+ SoftButtonObject softButtonObject = new SoftButtonObject ("hello_there" , stateList , "general_kenobi" , null );
414+ assertNull (softButtonObject .getStates ());
415+ }
416+
417+ /**
418+ * Test constructing SoftButtonObject with an nonempty state list
419+ */
420+ @ Test
421+ public void testConstructSoftButtonObjectWithNonEmptyStateList () {
422+ List <SoftButtonState > stateList = new ArrayList <>();
423+ SoftButtonState softButtonState = new SoftButtonState ("general_kenobi" , "General Kenobi" , null );
424+ stateList .add (softButtonState );
425+ SoftButtonObject softButtonObject = new SoftButtonObject ("hello_there" , stateList , "general_kenobi" , null );
426+ assertEquals (stateList , softButtonObject .getStates ());
427+ }
428+
429+ /**
430+ * Test constructing SoftButtonObject with an invalid initialStateName
431+ */
432+ @ Test
433+ public void testConstructSoftButtonObjectWithInvalidInitialStateName () {
434+ List <SoftButtonState > stateList = new ArrayList <>();
435+ SoftButtonState softButtonState = new SoftButtonState ("general_kenobi" , "General Kenobi" , null );
436+ stateList .add (softButtonState );
437+ SoftButtonObject softButtonObject = new SoftButtonObject ("hello_there" , stateList , "hello_there" , null );
438+ assertNull (softButtonObject .getStates ());
439+ }
440+
441+ /**
442+ * Test assigning an empty state list to existing SoftButtonObject
443+ */
444+ @ Test
445+ public void testAssignEmptyStateListToSoftButtonObject () {
446+ List <SoftButtonState > nonEmptyStateList = new ArrayList <>();
447+ List <SoftButtonState > emptyStateList = new ArrayList <>();
448+ SoftButtonState softButtonState = new SoftButtonState ("general_kenobi" , "General Kenobi" , null );
449+ nonEmptyStateList .add (softButtonState );
450+
451+ SoftButtonObject softButtonObject = new SoftButtonObject ("hello_there" , nonEmptyStateList , "general_kenobi" , null );
452+
453+ softButtonObject .setStates (emptyStateList );
454+ assertEquals (nonEmptyStateList , softButtonObject .getStates ());
455+ }
456+
457+ /**
458+ * Test assigning a state list with the current state to existing SoftButtonObject
459+ */
460+ @ Test
461+ public void testAssignStateListWithCurrentStateToSoftButtonObject () {
462+ List <SoftButtonState > stateList1 = new ArrayList <>();
463+ SoftButtonState softButtonState1 = new SoftButtonState ("hello_there" , "Hello there" , null );
464+ stateList1 .add (softButtonState1 );
465+
466+ List <SoftButtonState > stateList2 = new ArrayList <>();
467+ SoftButtonState softButtonState2 = new SoftButtonState ("general_kenobi" , "General Kenobi" , null );
468+ stateList2 .add (softButtonState1 );
469+ stateList2 .add (softButtonState2 );
470+
471+ SoftButtonObject softButtonObject = new SoftButtonObject ("general_kenobi" , stateList1 , "hello_there" , null );
472+
473+ softButtonObject .setStates (stateList2 );
474+
475+ assertEquals (stateList2 , softButtonObject .getStates ());
476+ }
477+
478+ /**
479+ * Test assigning a state list without the current state to existing SoftButtonObject
480+ */
481+ @ Test
482+ public void testAssignStateListWithoutCurrentStateToSoftButtonObject () {
483+ List <SoftButtonState > stateList1 = new ArrayList <>();
484+ SoftButtonState softButtonState1 = new SoftButtonState ("hello_there" , "Hello there" , null );
485+ stateList1 .add (softButtonState1 );
486+
487+ List <SoftButtonState > stateList2 = new ArrayList <>();
488+ SoftButtonState softButtonState2 = new SoftButtonState ("general_kenobi" , "General Kenobi" , null );
489+ stateList2 .add (softButtonState2 );
490+
491+ SoftButtonObject softButtonObject = new SoftButtonObject ("general_kenobi" , stateList1 , "hello_there" , null );
492+
493+ softButtonObject .setStates (stateList2 );
494+
495+ assertEquals (stateList2 , softButtonObject .getStates ());
496+ }
497+
498+ /**
499+ * Test assigning a state list with states that have the same name to existing SoftButtonObject
500+ */
501+ @ Test
502+ public void testAssignSameNameStateListToSoftButtonObject () {
503+ List <SoftButtonState > stateListUnique = new ArrayList <>();
504+ SoftButtonState softButtonState1 = new SoftButtonState ("hello_there" , "Hello there" , null );
505+ stateListUnique .add (softButtonState1 );
506+
507+ List <SoftButtonState > stateListDuplicateNames = new ArrayList <>();
508+ SoftButtonState softButtonState2 = new SoftButtonState ("general_kenobi" , "General Kenobi" , null );
509+ stateListDuplicateNames .add (softButtonState2 );
510+ SoftButtonState softButtonState3 = new SoftButtonState ("general_kenobi" , "General Kenobi Again" , null );
511+ stateListDuplicateNames .add (softButtonState3 );
512+
513+ SoftButtonObject softButtonObject = new SoftButtonObject ("general_kenobi" , stateListUnique , "hello_there" , null );
514+
515+ softButtonObject .setStates (stateListDuplicateNames );
516+
517+ assertEquals (stateListUnique , softButtonObject .getStates ());
518+ }
405519}
0 commit comments