Merge "[AWARE] Fix unit tests"
This commit is contained in:
@@ -18,11 +18,10 @@ package android.net.wifi.aware;
|
|||||||
|
|
||||||
import static org.hamcrest.core.IsEqual.equalTo;
|
import static org.hamcrest.core.IsEqual.equalTo;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.ArgumentMatchers.any;
|
||||||
import static org.mockito.Matchers.anyInt;
|
import static org.mockito.ArgumentMatchers.anyInt;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.ArgumentMatchers.eq;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.ArgumentMatchers.isNull;
|
||||||
import static org.mockito.Matchers.isNull;
|
|
||||||
import static org.mockito.Mockito.inOrder;
|
import static org.mockito.Mockito.inOrder;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||||
@@ -140,8 +139,8 @@ public class WifiAwareManagerTest {
|
|||||||
|
|
||||||
// (1) connect + success
|
// (1) connect + success
|
||||||
mDut.attach(mockCallback, mMockLooperHandler);
|
mDut.attach(mockCallback, mMockLooperHandler);
|
||||||
inOrder.verify(mockAwareService).connect(binder.capture(), anyString(),
|
inOrder.verify(mockAwareService).connect(binder.capture(), any(),
|
||||||
clientProxyCallback.capture(), (ConfigRequest) isNull(), eq(false));
|
clientProxyCallback.capture(), isNull(), eq(false));
|
||||||
clientProxyCallback.getValue().onConnectSuccess(clientId);
|
clientProxyCallback.getValue().onConnectSuccess(clientId);
|
||||||
mMockLooper.dispatchAll();
|
mMockLooper.dispatchAll();
|
||||||
inOrder.verify(mockCallback).onAttached(sessionCaptor.capture());
|
inOrder.verify(mockCallback).onAttached(sessionCaptor.capture());
|
||||||
@@ -150,8 +149,7 @@ public class WifiAwareManagerTest {
|
|||||||
// (2) publish - should succeed
|
// (2) publish - should succeed
|
||||||
PublishConfig publishConfig = new PublishConfig.Builder().build();
|
PublishConfig publishConfig = new PublishConfig.Builder().build();
|
||||||
session.publish(publishConfig, mockSessionCallback, mMockLooperHandler);
|
session.publish(publishConfig, mockSessionCallback, mMockLooperHandler);
|
||||||
inOrder.verify(mockAwareService).publish(eq(clientId), eq(publishConfig),
|
inOrder.verify(mockAwareService).publish(eq(clientId), eq(publishConfig), any());
|
||||||
any(IWifiAwareDiscoverySessionCallback.class));
|
|
||||||
|
|
||||||
// (3) disconnect
|
// (3) disconnect
|
||||||
session.destroy();
|
session.destroy();
|
||||||
@@ -163,8 +161,8 @@ public class WifiAwareManagerTest {
|
|||||||
|
|
||||||
// (5) connect
|
// (5) connect
|
||||||
mDut.attach(mockCallback, mMockLooperHandler);
|
mDut.attach(mockCallback, mMockLooperHandler);
|
||||||
inOrder.verify(mockAwareService).connect(binder.capture(), anyString(),
|
inOrder.verify(mockAwareService).connect(binder.capture(), any(), any(), isNull(),
|
||||||
any(IWifiAwareEventCallback.class), (ConfigRequest) isNull(), eq(false));
|
eq(false));
|
||||||
|
|
||||||
verifyNoMoreInteractions(mockCallback, mockSessionCallback, mockAwareService);
|
verifyNoMoreInteractions(mockCallback, mockSessionCallback, mockAwareService);
|
||||||
}
|
}
|
||||||
@@ -185,16 +183,16 @@ public class WifiAwareManagerTest {
|
|||||||
|
|
||||||
// (1) connect + failure
|
// (1) connect + failure
|
||||||
mDut.attach(mockCallback, mMockLooperHandler);
|
mDut.attach(mockCallback, mMockLooperHandler);
|
||||||
inOrder.verify(mockAwareService).connect(any(IBinder.class), anyString(),
|
inOrder.verify(mockAwareService).connect(any(), any(), clientProxyCallback.capture(),
|
||||||
clientProxyCallback.capture(), (ConfigRequest) isNull(), eq(false));
|
isNull(), eq(false));
|
||||||
clientProxyCallback.getValue().onConnectFail(reason);
|
clientProxyCallback.getValue().onConnectFail(reason);
|
||||||
mMockLooper.dispatchAll();
|
mMockLooper.dispatchAll();
|
||||||
inOrder.verify(mockCallback).onAttachFailed();
|
inOrder.verify(mockCallback).onAttachFailed();
|
||||||
|
|
||||||
// (2) connect + success
|
// (2) connect + success
|
||||||
mDut.attach(mockCallback, mMockLooperHandler);
|
mDut.attach(mockCallback, mMockLooperHandler);
|
||||||
inOrder.verify(mockAwareService).connect(any(IBinder.class), anyString(),
|
inOrder.verify(mockAwareService).connect(any(), any(), clientProxyCallback.capture(),
|
||||||
clientProxyCallback.capture(), (ConfigRequest) isNull(), eq(false));
|
isNull(), eq(false));
|
||||||
clientProxyCallback.getValue().onConnectSuccess(clientId);
|
clientProxyCallback.getValue().onConnectSuccess(clientId);
|
||||||
mMockLooper.dispatchAll();
|
mMockLooper.dispatchAll();
|
||||||
inOrder.verify(mockCallback).onAttached(sessionCaptor.capture());
|
inOrder.verify(mockCallback).onAttached(sessionCaptor.capture());
|
||||||
@@ -203,8 +201,7 @@ public class WifiAwareManagerTest {
|
|||||||
// (4) subscribe: should succeed
|
// (4) subscribe: should succeed
|
||||||
SubscribeConfig subscribeConfig = new SubscribeConfig.Builder().build();
|
SubscribeConfig subscribeConfig = new SubscribeConfig.Builder().build();
|
||||||
session.subscribe(subscribeConfig, mockSessionCallback, mMockLooperHandler);
|
session.subscribe(subscribeConfig, mockSessionCallback, mMockLooperHandler);
|
||||||
inOrder.verify(mockAwareService).subscribe(eq(clientId), eq(subscribeConfig),
|
inOrder.verify(mockAwareService).subscribe(eq(clientId), eq(subscribeConfig), any());
|
||||||
any(IWifiAwareDiscoverySessionCallback.class));
|
|
||||||
|
|
||||||
verifyNoMoreInteractions(mockCallback, mockSessionCallback, mockAwareService);
|
verifyNoMoreInteractions(mockCallback, mockSessionCallback, mockAwareService);
|
||||||
}
|
}
|
||||||
@@ -223,19 +220,19 @@ public class WifiAwareManagerTest {
|
|||||||
|
|
||||||
// (1) connect + success
|
// (1) connect + success
|
||||||
mDut.attach(mockCallback, mMockLooperHandler);
|
mDut.attach(mockCallback, mMockLooperHandler);
|
||||||
inOrder.verify(mockAwareService).connect(any(IBinder.class), anyString(),
|
inOrder.verify(mockAwareService).connect(any(), any(), clientProxyCallback.capture(),
|
||||||
clientProxyCallback.capture(), (ConfigRequest) isNull(), eq(false));
|
isNull(), eq(false));
|
||||||
clientProxyCallback.getValue().onConnectSuccess(clientId);
|
clientProxyCallback.getValue().onConnectSuccess(clientId);
|
||||||
mMockLooper.dispatchAll();
|
mMockLooper.dispatchAll();
|
||||||
inOrder.verify(mockCallback).onAttached(any(WifiAwareSession.class));
|
inOrder.verify(mockCallback).onAttached(any());
|
||||||
|
|
||||||
// (2) connect + success
|
// (2) connect + success
|
||||||
mDut.attach(mockCallback, mMockLooperHandler);
|
mDut.attach(mockCallback, mMockLooperHandler);
|
||||||
inOrder.verify(mockAwareService).connect(any(IBinder.class), anyString(),
|
inOrder.verify(mockAwareService).connect(any(), any(), clientProxyCallback.capture(),
|
||||||
clientProxyCallback.capture(), (ConfigRequest) isNull(), eq(false));
|
isNull(), eq(false));
|
||||||
clientProxyCallback.getValue().onConnectSuccess(clientId + 1);
|
clientProxyCallback.getValue().onConnectSuccess(clientId + 1);
|
||||||
mMockLooper.dispatchAll();
|
mMockLooper.dispatchAll();
|
||||||
inOrder.verify(mockCallback).onAttached(any(WifiAwareSession.class));
|
inOrder.verify(mockCallback).onAttached(any());
|
||||||
|
|
||||||
verifyNoMoreInteractions(mockCallback, mockSessionCallback, mockAwareService);
|
verifyNoMoreInteractions(mockCallback, mockSessionCallback, mockAwareService);
|
||||||
}
|
}
|
||||||
@@ -278,8 +275,8 @@ public class WifiAwareManagerTest {
|
|||||||
|
|
||||||
// (0) connect + success
|
// (0) connect + success
|
||||||
mDut.attach(mMockLooperHandler, configRequest, mockCallback, null);
|
mDut.attach(mMockLooperHandler, configRequest, mockCallback, null);
|
||||||
inOrder.verify(mockAwareService).connect(any(IBinder.class), anyString(),
|
inOrder.verify(mockAwareService).connect(any(), any(), clientProxyCallback.capture(),
|
||||||
clientProxyCallback.capture(), eq(configRequest), eq(false));
|
eq(configRequest), eq(false));
|
||||||
clientProxyCallback.getValue().onConnectSuccess(clientId);
|
clientProxyCallback.getValue().onConnectSuccess(clientId);
|
||||||
mMockLooper.dispatchAll();
|
mMockLooper.dispatchAll();
|
||||||
inOrder.verify(mockCallback).onAttached(sessionCaptor.capture());
|
inOrder.verify(mockCallback).onAttached(sessionCaptor.capture());
|
||||||
@@ -370,8 +367,8 @@ public class WifiAwareManagerTest {
|
|||||||
|
|
||||||
// (1) connect successfully
|
// (1) connect successfully
|
||||||
mDut.attach(mMockLooperHandler, configRequest, mockCallback, null);
|
mDut.attach(mMockLooperHandler, configRequest, mockCallback, null);
|
||||||
inOrder.verify(mockAwareService).connect(any(IBinder.class), anyString(),
|
inOrder.verify(mockAwareService).connect(any(), any(), clientProxyCallback.capture(),
|
||||||
clientProxyCallback.capture(), eq(configRequest), eq(false));
|
eq(configRequest), eq(false));
|
||||||
clientProxyCallback.getValue().onConnectSuccess(clientId);
|
clientProxyCallback.getValue().onConnectSuccess(clientId);
|
||||||
mMockLooper.dispatchAll();
|
mMockLooper.dispatchAll();
|
||||||
inOrder.verify(mockCallback).onAttached(sessionCaptor.capture());
|
inOrder.verify(mockCallback).onAttached(sessionCaptor.capture());
|
||||||
@@ -426,8 +423,8 @@ public class WifiAwareManagerTest {
|
|||||||
|
|
||||||
// (0) connect + success
|
// (0) connect + success
|
||||||
mDut.attach(mMockLooperHandler, configRequest, mockCallback, null);
|
mDut.attach(mMockLooperHandler, configRequest, mockCallback, null);
|
||||||
inOrder.verify(mockAwareService).connect(any(IBinder.class), anyString(),
|
inOrder.verify(mockAwareService).connect(any(), any(), clientProxyCallback.capture(),
|
||||||
clientProxyCallback.capture(), eq(configRequest), eq(false));
|
eq(configRequest), eq(false));
|
||||||
clientProxyCallback.getValue().onConnectSuccess(clientId);
|
clientProxyCallback.getValue().onConnectSuccess(clientId);
|
||||||
mMockLooper.dispatchAll();
|
mMockLooper.dispatchAll();
|
||||||
inOrder.verify(mockCallback).onAttached(sessionCaptor.capture());
|
inOrder.verify(mockCallback).onAttached(sessionCaptor.capture());
|
||||||
@@ -507,8 +504,8 @@ public class WifiAwareManagerTest {
|
|||||||
|
|
||||||
// (1) connect successfully
|
// (1) connect successfully
|
||||||
mDut.attach(mMockLooperHandler, configRequest, mockCallback, null);
|
mDut.attach(mMockLooperHandler, configRequest, mockCallback, null);
|
||||||
inOrder.verify(mockAwareService).connect(any(IBinder.class), anyString(),
|
inOrder.verify(mockAwareService).connect(any(), any(), clientProxyCallback.capture(),
|
||||||
clientProxyCallback.capture(), eq(configRequest), eq(false));
|
eq(configRequest), eq(false));
|
||||||
clientProxyCallback.getValue().onConnectSuccess(clientId);
|
clientProxyCallback.getValue().onConnectSuccess(clientId);
|
||||||
mMockLooper.dispatchAll();
|
mMockLooper.dispatchAll();
|
||||||
inOrder.verify(mockCallback).onAttached(sessionCaptor.capture());
|
inOrder.verify(mockCallback).onAttached(sessionCaptor.capture());
|
||||||
@@ -899,8 +896,7 @@ public class WifiAwareManagerTest {
|
|||||||
final RttManager.RttResult rttResults = new RttManager.RttResult();
|
final RttManager.RttResult rttResults = new RttManager.RttResult();
|
||||||
rttResults.distance = 10;
|
rttResults.distance = 10;
|
||||||
|
|
||||||
when(mockAwareService.startRanging(anyInt(), anyInt(),
|
when(mockAwareService.startRanging(anyInt(), anyInt(), any())).thenReturn(rangingId);
|
||||||
any(RttManager.ParcelableRttParams.class))).thenReturn(rangingId);
|
|
||||||
|
|
||||||
InOrder inOrder = inOrder(mockCallback, mockSessionCallback, mockAwareService,
|
InOrder inOrder = inOrder(mockCallback, mockSessionCallback, mockAwareService,
|
||||||
mockPublishSession, mockRttListener);
|
mockPublishSession, mockRttListener);
|
||||||
@@ -919,8 +915,8 @@ public class WifiAwareManagerTest {
|
|||||||
|
|
||||||
// (1) connect successfully
|
// (1) connect successfully
|
||||||
mDut.attach(mMockLooperHandler, configRequest, mockCallback, null);
|
mDut.attach(mMockLooperHandler, configRequest, mockCallback, null);
|
||||||
inOrder.verify(mockAwareService).connect(any(IBinder.class), anyString(),
|
inOrder.verify(mockAwareService).connect(any(), any(), clientProxyCallback.capture(),
|
||||||
clientProxyCallback.capture(), eq(configRequest), eq(false));
|
eq(configRequest), eq(false));
|
||||||
clientProxyCallback.getValue().onConnectSuccess(clientId);
|
clientProxyCallback.getValue().onConnectSuccess(clientId);
|
||||||
mMockLooper.dispatchAll();
|
mMockLooper.dispatchAll();
|
||||||
inOrder.verify(mockCallback).onAttached(sessionCaptor.capture());
|
inOrder.verify(mockCallback).onAttached(sessionCaptor.capture());
|
||||||
@@ -994,8 +990,8 @@ public class WifiAwareManagerTest {
|
|||||||
|
|
||||||
// (1) connect successfully
|
// (1) connect successfully
|
||||||
mDut.attach(mMockLooperHandler, configRequest, mockCallback, null);
|
mDut.attach(mMockLooperHandler, configRequest, mockCallback, null);
|
||||||
inOrder.verify(mockAwareService).connect(any(IBinder.class), anyString(),
|
inOrder.verify(mockAwareService).connect(any(), any(), clientProxyCallback.capture(),
|
||||||
clientProxyCallback.capture(), eq(configRequest), eq(false));
|
eq(configRequest), eq(false));
|
||||||
clientProxyCallback.getValue().onConnectSuccess(clientId);
|
clientProxyCallback.getValue().onConnectSuccess(clientId);
|
||||||
mMockLooper.dispatchAll();
|
mMockLooper.dispatchAll();
|
||||||
inOrder.verify(mockCallback).onAttached(sessionCaptor.capture());
|
inOrder.verify(mockCallback).onAttached(sessionCaptor.capture());
|
||||||
@@ -1085,8 +1081,8 @@ public class WifiAwareManagerTest {
|
|||||||
|
|
||||||
// (1) connect successfully
|
// (1) connect successfully
|
||||||
mDut.attach(mMockLooperHandler, configRequest, mockCallback, null);
|
mDut.attach(mMockLooperHandler, configRequest, mockCallback, null);
|
||||||
inOrder.verify(mockAwareService).connect(any(IBinder.class), anyString(),
|
inOrder.verify(mockAwareService).connect(any(), any(), clientProxyCallback.capture(),
|
||||||
clientProxyCallback.capture(), eq(configRequest), eq(false));
|
eq(configRequest), eq(false));
|
||||||
clientProxyCallback.getValue().onConnectSuccess(clientId);
|
clientProxyCallback.getValue().onConnectSuccess(clientId);
|
||||||
mMockLooper.dispatchAll();
|
mMockLooper.dispatchAll();
|
||||||
inOrder.verify(mockCallback).onAttached(sessionCaptor.capture());
|
inOrder.verify(mockCallback).onAttached(sessionCaptor.capture());
|
||||||
|
|||||||
Reference in New Issue
Block a user