Change to use Dependencies in IpSecService Tests
The interface IpSecServiceConfiguration is refactored to static class Dependencies. Refine the tests to use Dependencies. Bug: 204153604 Test: FrameworksNetTests Change-Id: Ie2b79b1d948a19f64600ed9ea3b60b192dd92dfd
This commit is contained in:
@@ -190,7 +190,7 @@ public class IpSecServiceParameterizedTest {
|
|||||||
|
|
||||||
INetd mMockNetd;
|
INetd mMockNetd;
|
||||||
PackageManager mMockPkgMgr;
|
PackageManager mMockPkgMgr;
|
||||||
IpSecService.IpSecServiceConfiguration mMockIpSecSrvConfig;
|
IpSecService.Dependencies mMockDeps;
|
||||||
IpSecService mIpSecService;
|
IpSecService mIpSecService;
|
||||||
Network fakeNetwork = new Network(0xAB);
|
Network fakeNetwork = new Network(0xAB);
|
||||||
int mUid = Os.getuid();
|
int mUid = Os.getuid();
|
||||||
@@ -219,11 +219,11 @@ public class IpSecServiceParameterizedTest {
|
|||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
mMockNetd = mock(INetd.class);
|
mMockNetd = mock(INetd.class);
|
||||||
mMockPkgMgr = mock(PackageManager.class);
|
mMockPkgMgr = mock(PackageManager.class);
|
||||||
mMockIpSecSrvConfig = mock(IpSecService.IpSecServiceConfiguration.class);
|
mMockDeps = mock(IpSecService.Dependencies.class);
|
||||||
mIpSecService = new IpSecService(mTestContext, mMockIpSecSrvConfig);
|
mIpSecService = new IpSecService(mTestContext, mMockDeps);
|
||||||
|
|
||||||
// Injecting mock netd
|
// Injecting mock netd
|
||||||
when(mMockIpSecSrvConfig.getNetdInstance()).thenReturn(mMockNetd);
|
when(mMockDeps.getNetdInstance(mTestContext)).thenReturn(mMockNetd);
|
||||||
|
|
||||||
// PackageManager should always return true (feature flag tests in IpSecServiceTest)
|
// PackageManager should always return true (feature flag tests in IpSecServiceTest)
|
||||||
when(mMockPkgMgr.hasSystemFeature(anyString())).thenReturn(true);
|
when(mMockPkgMgr.hasSystemFeature(anyString())).thenReturn(true);
|
||||||
|
|||||||
@@ -57,14 +57,14 @@ import java.util.concurrent.ThreadLocalRandom;
|
|||||||
@DevSdkIgnoreRule.IgnoreUpTo(Build.VERSION_CODES.R)
|
@DevSdkIgnoreRule.IgnoreUpTo(Build.VERSION_CODES.R)
|
||||||
public class IpSecServiceRefcountedResourceTest {
|
public class IpSecServiceRefcountedResourceTest {
|
||||||
Context mMockContext;
|
Context mMockContext;
|
||||||
IpSecService.IpSecServiceConfiguration mMockIpSecSrvConfig;
|
IpSecService.Dependencies mMockDeps;
|
||||||
IpSecService mIpSecService;
|
IpSecService mIpSecService;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
mMockContext = mock(Context.class);
|
mMockContext = mock(Context.class);
|
||||||
mMockIpSecSrvConfig = mock(IpSecService.IpSecServiceConfiguration.class);
|
mMockDeps = mock(IpSecService.Dependencies.class);
|
||||||
mIpSecService = new IpSecService(mMockContext, mMockIpSecSrvConfig);
|
mIpSecService = new IpSecService(mMockContext, mMockDeps);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertResourceState(
|
private void assertResourceState(
|
||||||
|
|||||||
@@ -122,18 +122,18 @@ public class IpSecServiceTest {
|
|||||||
|
|
||||||
Context mMockContext;
|
Context mMockContext;
|
||||||
INetd mMockNetd;
|
INetd mMockNetd;
|
||||||
IpSecService.IpSecServiceConfiguration mMockIpSecSrvConfig;
|
IpSecService.Dependencies mMockDeps;
|
||||||
IpSecService mIpSecService;
|
IpSecService mIpSecService;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
mMockContext = mock(Context.class);
|
mMockContext = mock(Context.class);
|
||||||
mMockNetd = mock(INetd.class);
|
mMockNetd = mock(INetd.class);
|
||||||
mMockIpSecSrvConfig = mock(IpSecService.IpSecServiceConfiguration.class);
|
mMockDeps = mock(IpSecService.Dependencies.class);
|
||||||
mIpSecService = new IpSecService(mMockContext, mMockIpSecSrvConfig);
|
mIpSecService = new IpSecService(mMockContext, mMockDeps);
|
||||||
|
|
||||||
// Injecting mock netd
|
// Injecting mock netd
|
||||||
when(mMockIpSecSrvConfig.getNetdInstance()).thenReturn(mMockNetd);
|
when(mMockDeps.getNetdInstance(mMockContext)).thenReturn(mMockNetd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -611,7 +611,7 @@ public class IpSecServiceTest {
|
|||||||
public void testOpenUdpEncapSocketTagsSocket() throws Exception {
|
public void testOpenUdpEncapSocketTagsSocket() throws Exception {
|
||||||
IpSecService.UidFdTagger mockTagger = mock(IpSecService.UidFdTagger.class);
|
IpSecService.UidFdTagger mockTagger = mock(IpSecService.UidFdTagger.class);
|
||||||
IpSecService testIpSecService = new IpSecService(
|
IpSecService testIpSecService = new IpSecService(
|
||||||
mMockContext, mMockIpSecSrvConfig, mockTagger);
|
mMockContext, mMockDeps, mockTagger);
|
||||||
|
|
||||||
IpSecUdpEncapResponse udpEncapResp =
|
IpSecUdpEncapResponse udpEncapResp =
|
||||||
testIpSecService.openUdpEncapsulationSocket(0, new Binder());
|
testIpSecService.openUdpEncapsulationSocket(0, new Binder());
|
||||||
|
|||||||
Reference in New Issue
Block a user