2323
2424import android .view .View ;
2525import android .view .ViewGroup ;
26+ import android .widget .Button ;
27+ import android .widget .LinearLayout ;
28+ import android .widget .TextView ;
29+
30+ import androidx .test .platform .app .InstrumentationRegistry ;
2631
2732import com .smartdevicelink .managers .ISdl ;
33+ import com .smartdevicelink .managers .lifecycle .OnSystemCapabilityListener ;
34+ import com .smartdevicelink .managers .lifecycle .SystemCapabilityManager ;
2835import com .smartdevicelink .proxy .rpc .HapticRect ;
2936import com .smartdevicelink .proxy .rpc .Rectangle ;
3037import com .smartdevicelink .proxy .rpc .SendHapticData ;
4047import org .mockito .ArgumentCaptor ;
4148import org .mockito .Captor ;
4249import org .mockito .Mock ;
50+ import org .mockito .Mockito ;
4351import org .mockito .invocation .InvocationOnMock ;
4452import org .mockito .junit .MockitoJUnitRunner ;
4553import org .mockito .stubbing .Answer ;
4654
4755import java .util .ArrayList ;
4856import java .util .List ;
4957
58+ import static org .mockito .ArgumentMatchers .anyBoolean ;
59+ import static org .mockito .ArgumentMatchers .eq ;
60+ import static org .mockito .ArgumentMatchers .isNull ;
5061import static org .mockito .Mockito .any ;
5162import static org .mockito .Mockito .doAnswer ;
63+ import static org .mockito .Mockito .doReturn ;
5264import static org .mockito .Mockito .mock ;
5365import static org .mockito .Mockito .times ;
5466import static org .mockito .Mockito .verify ;
6072@ RunWith (MockitoJUnitRunner .Strict .class )
6173public class HapticInterfaceManagerTest extends TestCase {
6274 @ Mock
63- private ISdl mockProxy ;
75+ private ISdl interalInterface ;
6476
6577 @ Captor
6678 private ArgumentCaptor <SendHapticData > captor ;
@@ -69,7 +81,7 @@ public class HapticInterfaceManagerTest extends TestCase {
6981
7082 @ Before
7183 public void setUp () throws Exception {
72- hapticMgr = new HapticInterfaceManager (mockProxy );
84+ hapticMgr = new HapticInterfaceManager (interalInterface );
7385 }
7486
7587 @ After
@@ -89,14 +101,14 @@ public void testSetHapticData() throws Exception {
89101 hRect .setRect (rect );
90102 rects .add (hRect );
91103 hapticMgr .setHapticData (rects );
92- verify (mockProxy ). sendRPCRequest (any (SendHapticData .class ));
104+ verify (interalInterface ). sendRPC (any (SendHapticData .class ));
93105 }
94106
95107 @ Test
96108 public void testRefreshHapticData () throws Exception {
97109 View root = createViews ();
98110 hapticMgr .refreshHapticData (root );
99- verify (mockProxy ).sendRPC (captor .capture ());
111+ verify (interalInterface ).sendRPC (captor .capture ());
100112 SendHapticData data = captor .getValue ();
101113 assertNotNull ("SendHapticData RPC" , data );
102114 List <HapticRect > list = data .getHapticRectData ();
@@ -107,11 +119,11 @@ public void testRefreshHapticData() throws Exception {
107119 @ Test
108120 public void testRefreshHapticDataNull () throws Exception {
109121 hapticMgr .refreshHapticData (null );
110- verify (mockProxy ).sendRPC (captor .capture ());
122+ verify (interalInterface ).sendRPC (captor .capture ());
111123 SendHapticData data = captor .getValue ();
112124 assertNotNull ("SendHapticData RPC" , data );
113125 List <HapticRect > list = data .getHapticRectData ();
114- assertNull ("List" , list );
126+ assertTrue ("List" , list . isEmpty () );
115127 }
116128
117129 @ Test
@@ -206,11 +218,11 @@ public void testRefreshWithUserData() throws Exception {
206218 hRect .setRect (rect );
207219 rects .add (hRect );
208220 hapticMgr .setHapticData (rects );
209- verify (mockProxy ). sendRPCRequest (any (SendHapticData .class ));
221+ verify (interalInterface ). sendRPC (any (SendHapticData .class ));
210222
211223 View root = createViews ();
212224 hapticMgr .refreshHapticData (root );
213- verify (mockProxy , times (1 )).sendRPCRequest (any (SendHapticData .class ));
225+ verify (interalInterface , times (1 )).sendRPC (any (SendHapticData .class ));
214226 }
215227
216228 private View createViews () {
@@ -232,55 +244,45 @@ private View createViews() {
232244 when (parent2 .getChildAt (0 )).thenReturn (view );
233245 when (parent2 .getChildAt (1 )).thenReturn (view );
234246
235- when (view .isFocusable ()).then (new Answer <Boolean >() {
236- private int count = 0 ;
237247
238- @ Override
239- public Boolean answer (InvocationOnMock invocation ) throws Throwable {
240- int curCount = count ++;
241- return (curCount == 1 ) || (curCount == 2 ) || (curCount == 3 );
242- }
243- });
244- when (view .isClickable ()).then (new Answer <Boolean >() {
248+ doAnswer (new Answer <Boolean >() {
245249 private int count = 0 ;
246250
247251 @ Override
248252 public Boolean answer (InvocationOnMock invocation ) throws Throwable {
249253 int curCount = count ++;
250- return (curCount == 0 ) || (curCount == 3 );
254+ return (curCount >= 1 ) && (curCount <= 4 );
251255 }
252- });
256+ }). when ( view ). isClickable () ;
253257
254258 return parent1 ;
255259 }
256260
257261
258262 private View createView (final int x , final int y , int w , int h ) {
259- View button = mock (View .class );
260- when (button .isFocusable ()).thenReturn (true );
261- doAnswer (new Answer () {
263+ View button = new Button (InstrumentationRegistry .getInstrumentation ().getContext ()) {
262264 @ Override
263- public int [] answer (InvocationOnMock invocation ) throws Throwable {
264- int [] args = (int [])(invocation .getArguments ()[0 ]);
265- args [0 ] = x ;
266- args [1 ] = y ;
267- return args ;
265+ public void getLocationOnScreen (int [] outLocation ) {
266+ super .getLocationOnScreen (outLocation );
267+ outLocation [0 ] = x ;
268+ outLocation [1 ] = y ;
268269 }
269- }). when ( button ). getLocationOnScreen ( any ( int []. class )) ;
270-
271- when ( button .getWidth ()). thenReturn (w );
272- when ( button .getHeight ()). thenReturn (h );
270+ };
271+ button . setClickable ( true );
272+ button .setRight (w );
273+ button .setBottom (h );
273274 return button ;
274275 }
275276
276277 private void assertViewWithCapability (int x , int y , int w , int h , Rectangle expected , VideoStreamingCapability capability ) {
277- when (mockProxy .getCapability (SystemCapabilityType .VIDEO_STREAMING )).thenReturn (capability );
278+ SystemCapabilityManager systemCapabilityManager = mock (SystemCapabilityManager .class );
279+ when (systemCapabilityManager .getCapability (eq (SystemCapabilityType .VIDEO_STREAMING ), (OnSystemCapabilityListener ) isNull (), anyBoolean ())).thenReturn (capability );
280+ doReturn (systemCapabilityManager ).when (interalInterface ).getSystemCapabilityManager ();
278281
279282 View button = createView (x , y , w , h );
280283
281-
282284 hapticMgr .refreshHapticData (button );
283- verify (mockProxy ).sendRPC (captor .capture ());
285+ verify (interalInterface ).sendRPC (captor .capture ());
284286
285287 SendHapticData data = captor .getValue ();
286288 List <HapticRect > list = data .getHapticRectData ();
0 commit comments