Add makeDependencies method in IpSecService related tests
Bug: 204153604 Test: FrameworksNetTest Change-Id: Iea5731273e4772966466088f11a4c6334fa19f5d
This commit is contained in:
@@ -60,6 +60,7 @@ import android.net.Network;
|
||||
import android.os.Binder;
|
||||
import android.os.Build;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.RemoteException;
|
||||
import android.system.Os;
|
||||
import android.test.mock.MockContext;
|
||||
import android.util.ArraySet;
|
||||
@@ -188,9 +189,15 @@ public class IpSecServiceParameterizedTest {
|
||||
}
|
||||
}
|
||||
|
||||
private IpSecService.Dependencies makeDependencies() throws RemoteException {
|
||||
final IpSecService.Dependencies deps = mock(IpSecService.Dependencies.class);
|
||||
when(deps.getNetdInstance(mTestContext)).thenReturn(mMockNetd);
|
||||
return deps;
|
||||
}
|
||||
|
||||
INetd mMockNetd;
|
||||
PackageManager mMockPkgMgr;
|
||||
IpSecService.Dependencies mMockDeps;
|
||||
IpSecService.Dependencies mDeps;
|
||||
IpSecService mIpSecService;
|
||||
Network fakeNetwork = new Network(0xAB);
|
||||
int mUid = Os.getuid();
|
||||
@@ -219,11 +226,8 @@ public class IpSecServiceParameterizedTest {
|
||||
public void setUp() throws Exception {
|
||||
mMockNetd = mock(INetd.class);
|
||||
mMockPkgMgr = mock(PackageManager.class);
|
||||
mMockDeps = mock(IpSecService.Dependencies.class);
|
||||
mIpSecService = new IpSecService(mTestContext, mMockDeps);
|
||||
|
||||
// Injecting mock netd
|
||||
when(mMockDeps.getNetdInstance(mTestContext)).thenReturn(mMockNetd);
|
||||
mDeps = makeDependencies();
|
||||
mIpSecService = new IpSecService(mTestContext, mDeps);
|
||||
|
||||
// PackageManager should always return true (feature flag tests in IpSecServiceTest)
|
||||
when(mMockPkgMgr.hasSystemFeature(anyString())).thenReturn(true);
|
||||
|
||||
@@ -46,6 +46,7 @@ import android.os.Binder;
|
||||
import android.os.Build;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
import android.os.Process;
|
||||
import android.os.RemoteException;
|
||||
import android.system.ErrnoException;
|
||||
import android.system.Os;
|
||||
import android.system.StructStat;
|
||||
@@ -122,24 +123,22 @@ public class IpSecServiceTest {
|
||||
|
||||
Context mMockContext;
|
||||
INetd mMockNetd;
|
||||
IpSecService.Dependencies mMockDeps;
|
||||
IpSecService.Dependencies mDeps;
|
||||
IpSecService mIpSecService;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mMockContext = mock(Context.class);
|
||||
mMockNetd = mock(INetd.class);
|
||||
mMockDeps = mock(IpSecService.Dependencies.class);
|
||||
mIpSecService = new IpSecService(mMockContext, mMockDeps);
|
||||
|
||||
// Injecting mock netd
|
||||
when(mMockDeps.getNetdInstance(mMockContext)).thenReturn(mMockNetd);
|
||||
mDeps = makeDependencies();
|
||||
mIpSecService = new IpSecService(mMockContext, mDeps);
|
||||
assertNotNull(mIpSecService);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIpSecServiceCreate() throws InterruptedException {
|
||||
IpSecService ipSecSrv = IpSecService.create(mMockContext);
|
||||
assertNotNull(ipSecSrv);
|
||||
private IpSecService.Dependencies makeDependencies() throws RemoteException {
|
||||
final IpSecService.Dependencies deps = mock(IpSecService.Dependencies.class);
|
||||
when(deps.getNetdInstance(mMockContext)).thenReturn(mMockNetd);
|
||||
return deps;
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -611,7 +610,7 @@ public class IpSecServiceTest {
|
||||
public void testOpenUdpEncapSocketTagsSocket() throws Exception {
|
||||
IpSecService.UidFdTagger mockTagger = mock(IpSecService.UidFdTagger.class);
|
||||
IpSecService testIpSecService = new IpSecService(
|
||||
mMockContext, mMockDeps, mockTagger);
|
||||
mMockContext, mDeps, mockTagger);
|
||||
|
||||
IpSecUdpEncapResponse udpEncapResp =
|
||||
testIpSecService.openUdpEncapsulationSocket(0, new Binder());
|
||||
|
||||
Reference in New Issue
Block a user