[Feature sync] Resolve class-level nullness suppression

This is a chery-picked commit from internal branch which is to
add nullability to reslove the nullness suppression.

Bug: 242631897
Bug: 254155029
Test: atest FrameworksNetTests
Change-Id: I289b0408c0c4ccdefc498d3b6d3f381c2b04132e
This commit is contained in:
Paul Hu
2022-08-22 06:54:12 +00:00
parent e62d151d1e
commit 6c74a13512
15 changed files with 149 additions and 144 deletions

View File

@@ -53,7 +53,7 @@ public class MdnsSocketTests {
private SocketAddress socketIPv4Address;
private SocketAddress socketIPv6Address;
private byte[] data = new byte[25];
private final byte[] data = new byte[25];
private final DatagramPacket datagramPacket = new DatagramPacket(data, data.length);
private NetworkInterface networkInterface;
@@ -74,14 +74,8 @@ public class MdnsSocketTests {
}
@Test
public void testMdnsSocket() throws IOException {
mdnsSocket =
new MdnsSocket(mockMulticastNetworkInterfaceProvider, MdnsConstants.MDNS_PORT) {
@Override
MulticastSocket createMulticastSocket(int port) throws IOException {
return mockMulticastSocket;
}
};
public void mdnsSocket_basicFunctionality() throws IOException {
mdnsSocket = new MdnsSocket(mockMulticastNetworkInterfaceProvider, mockMulticastSocket);
mdnsSocket.send(datagramPacket);
verify(mockMulticastSocket).setNetworkInterface(networkInterface);
verify(mockMulticastSocket).send(datagramPacket);
@@ -100,20 +94,14 @@ public class MdnsSocketTests {
}
@Test
public void testIPv6OnlyNetwork_IPv6Enabled() throws IOException {
public void ipv6OnlyNetwork_ipv6Enabled() throws IOException {
// Have mockMulticastNetworkInterfaceProvider send back an IPv6Only networkInterfaceWrapper
networkInterface = createEmptyNetworkInterface();
when(mockNetworkInterfaceWrapper.getNetworkInterface()).thenReturn(networkInterface);
when(mockMulticastNetworkInterfaceProvider.getMulticastNetworkInterfaces())
.thenReturn(Collections.singletonList(mockNetworkInterfaceWrapper));
mdnsSocket =
new MdnsSocket(mockMulticastNetworkInterfaceProvider, MdnsConstants.MDNS_PORT) {
@Override
MulticastSocket createMulticastSocket(int port) throws IOException {
return mockMulticastSocket;
}
};
mdnsSocket = new MdnsSocket(mockMulticastNetworkInterfaceProvider, mockMulticastSocket);
when(mockMulticastNetworkInterfaceProvider.isOnIpV6OnlyNetwork(
Collections.singletonList(mockNetworkInterfaceWrapper)))
@@ -130,20 +118,14 @@ public class MdnsSocketTests {
}
@Test
public void testIPv6OnlyNetwork_IPv6Toggle() throws IOException {
public void ipv6OnlyNetwork_ipv6Toggle() throws IOException {
// Have mockMulticastNetworkInterfaceProvider send back a networkInterfaceWrapper
networkInterface = createEmptyNetworkInterface();
when(mockNetworkInterfaceWrapper.getNetworkInterface()).thenReturn(networkInterface);
when(mockMulticastNetworkInterfaceProvider.getMulticastNetworkInterfaces())
.thenReturn(Collections.singletonList(mockNetworkInterfaceWrapper));
mdnsSocket =
new MdnsSocket(mockMulticastNetworkInterfaceProvider, MdnsConstants.MDNS_PORT) {
@Override
MulticastSocket createMulticastSocket(int port) throws IOException {
return mockMulticastSocket;
}
};
mdnsSocket = new MdnsSocket(mockMulticastNetworkInterfaceProvider, mockMulticastSocket);
when(mockMulticastNetworkInterfaceProvider.isOnIpV6OnlyNetwork(
Collections.singletonList(mockNetworkInterfaceWrapper)))