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:
Aaron Huang
2021-11-27 00:24:27 +08:00
parent 1c4a66ddc4
commit ced49fd763
3 changed files with 12 additions and 12 deletions

View File

@@ -190,7 +190,7 @@ public class IpSecServiceParameterizedTest {
INetd mMockNetd;
PackageManager mMockPkgMgr;
IpSecService.IpSecServiceConfiguration mMockIpSecSrvConfig;
IpSecService.Dependencies mMockDeps;
IpSecService mIpSecService;
Network fakeNetwork = new Network(0xAB);
int mUid = Os.getuid();
@@ -219,11 +219,11 @@ public class IpSecServiceParameterizedTest {
public void setUp() throws Exception {
mMockNetd = mock(INetd.class);
mMockPkgMgr = mock(PackageManager.class);
mMockIpSecSrvConfig = mock(IpSecService.IpSecServiceConfiguration.class);
mIpSecService = new IpSecService(mTestContext, mMockIpSecSrvConfig);
mMockDeps = mock(IpSecService.Dependencies.class);
mIpSecService = new IpSecService(mTestContext, mMockDeps);
// Injecting mock netd
when(mMockIpSecSrvConfig.getNetdInstance()).thenReturn(mMockNetd);
when(mMockDeps.getNetdInstance(mTestContext)).thenReturn(mMockNetd);
// PackageManager should always return true (feature flag tests in IpSecServiceTest)
when(mMockPkgMgr.hasSystemFeature(anyString())).thenReturn(true);

View File

@@ -57,14 +57,14 @@ import java.util.concurrent.ThreadLocalRandom;
@DevSdkIgnoreRule.IgnoreUpTo(Build.VERSION_CODES.R)
public class IpSecServiceRefcountedResourceTest {
Context mMockContext;
IpSecService.IpSecServiceConfiguration mMockIpSecSrvConfig;
IpSecService.Dependencies mMockDeps;
IpSecService mIpSecService;
@Before
public void setUp() throws Exception {
mMockContext = mock(Context.class);
mMockIpSecSrvConfig = mock(IpSecService.IpSecServiceConfiguration.class);
mIpSecService = new IpSecService(mMockContext, mMockIpSecSrvConfig);
mMockDeps = mock(IpSecService.Dependencies.class);
mIpSecService = new IpSecService(mMockContext, mMockDeps);
}
private void assertResourceState(

View File

@@ -122,18 +122,18 @@ public class IpSecServiceTest {
Context mMockContext;
INetd mMockNetd;
IpSecService.IpSecServiceConfiguration mMockIpSecSrvConfig;
IpSecService.Dependencies mMockDeps;
IpSecService mIpSecService;
@Before
public void setUp() throws Exception {
mMockContext = mock(Context.class);
mMockNetd = mock(INetd.class);
mMockIpSecSrvConfig = mock(IpSecService.IpSecServiceConfiguration.class);
mIpSecService = new IpSecService(mMockContext, mMockIpSecSrvConfig);
mMockDeps = mock(IpSecService.Dependencies.class);
mIpSecService = new IpSecService(mMockContext, mMockDeps);
// Injecting mock netd
when(mMockIpSecSrvConfig.getNetdInstance()).thenReturn(mMockNetd);
when(mMockDeps.getNetdInstance(mMockContext)).thenReturn(mMockNetd);
}
@Test
@@ -611,7 +611,7 @@ public class IpSecServiceTest {
public void testOpenUdpEncapSocketTagsSocket() throws Exception {
IpSecService.UidFdTagger mockTagger = mock(IpSecService.UidFdTagger.class);
IpSecService testIpSecService = new IpSecService(
mMockContext, mMockIpSecSrvConfig, mockTagger);
mMockContext, mMockDeps, mockTagger);
IpSecUdpEncapResponse udpEncapResp =
testIpSecService.openUdpEncapsulationSocket(0, new Binder());