Skip multicast test if it is not supported

DatagramChannelMulticastTest had some tests that
would not check the supportsMulticast flag to see
if they should execute before accessing fields that
are not initialized when supportsMulticast
is false.

supportsMulticast is set to false when the system
property "android.cts.device.multicast" is "false"
(normally provided by the CTS runner).

Thanks to bohu@ for the original fix.

BUG: 37719321
Test: vogar --vm-arg "-Dandroid.cts.device.multicast=false" \
luni/src/test/java/libcore/java/nio/channels/DatagramChannelMulticastTest.java
Change-Id: I0d3de3512b8f8ac300546f072eb98e760ccfbe66
diff --git a/luni/src/test/java/libcore/java/nio/channels/DatagramChannelMulticastTest.java b/luni/src/test/java/libcore/java/nio/channels/DatagramChannelMulticastTest.java
index ae45c0d..69110e0 100644
--- a/luni/src/test/java/libcore/java/nio/channels/DatagramChannelMulticastTest.java
+++ b/luni/src/test/java/libcore/java/nio/channels/DatagramChannelMulticastTest.java
@@ -711,6 +711,9 @@
 
     /** Checks that block() works when the receiver is bound to the multicast group address */
     public void test_block_filtersAsExpected_groupBind_ipv4() throws Exception {
+        if (!supportsMulticast) {
+            return;
+        }
         InetAddress ipv4LocalAddress = getLocalIpv4Address(ipv4NetworkInterface);
         test_block_filtersAsExpected(
                 ipv4LocalAddress /* senderBindAddress */,
@@ -721,6 +724,9 @@
 
     /** Checks that block() works when the receiver is bound to the multicast group address */
     public void test_block_filtersAsExpected_groupBind_ipv6() throws Exception {
+        if (!supportsMulticast) {
+            return;
+        }
         InetAddress ipv6LocalAddress = getLocalIpv6Address(ipv6NetworkInterface);
         test_block_filtersAsExpected(
                 ipv6LocalAddress /* senderBindAddress */,
@@ -731,6 +737,9 @@
 
     /** Checks that block() works when the receiver is bound to the "any" address */
     public void test_block_filtersAsExpected_anyBind_ipv4() throws Exception {
+        if (!supportsMulticast) {
+            return;
+        }
         InetAddress ipv4LocalAddress = getLocalIpv4Address(ipv4NetworkInterface);
         test_block_filtersAsExpected(
                 ipv4LocalAddress /* senderBindAddress */,
@@ -741,6 +750,9 @@
 
     /** Checks that block() works when the receiver is bound to the "any" address */
     public void test_block_filtersAsExpected_anyBind_ipv6() throws Exception {
+        if (!supportsMulticast) {
+            return;
+        }
         InetAddress ipv6LocalAddress = getLocalIpv6Address(ipv6NetworkInterface);
         test_block_filtersAsExpected(
                 ipv6LocalAddress /* senderBindAddress */,
@@ -753,9 +765,6 @@
             InetAddress senderBindAddress, InetAddress receiverBindAddress,
             InetAddress groupAddress, NetworkInterface networkInterface)
             throws Exception {
-        if (!supportsMulticast) {
-            return;
-        }
         DatagramChannel sendingChannel = DatagramChannel.open();
         // In order to block a sender the sender's address must be known. The sendingChannel is
         // explicitly bound to a known, non-loopback address.
@@ -973,6 +982,9 @@
      * address
      */
     public void test_joinSourceSpecific_null() throws Exception {
+        if (!supportsMulticast) {
+            return;
+        }
         InetAddress ipv4LocalAddress = getLocalIpv4Address(ipv4NetworkInterface);
         test_joinSourceSpecific(
                 ipv4LocalAddress /* senderBindAddress */,
@@ -987,6 +999,9 @@
      * address
      */
     public void test_joinSourceSpecific_groupBind_ipv4() throws Exception {
+        if (!supportsMulticast) {
+            return;
+        }
         InetAddress ipv4LocalAddress = getLocalIpv4Address(ipv4NetworkInterface);
         test_joinSourceSpecific(
                 ipv4LocalAddress /* senderBindAddress */,
@@ -1001,6 +1016,9 @@
      * address
      */
     public void test_joinSourceSpecific_groupBind_ipv6() throws Exception {
+        if (!supportsMulticast) {
+            return;
+        }
         InetAddress ipv6LocalAddress = getLocalIpv6Address(ipv6NetworkInterface);
         test_joinSourceSpecific(
                 ipv6LocalAddress /* senderBindAddress */,
@@ -1012,6 +1030,9 @@
 
     /** Checks that a source-specific join() works when the receiver is bound to the "any" address */
     public void test_joinSourceSpecific_anyBind_ipv4() throws Exception {
+        if (!supportsMulticast) {
+            return;
+        }
         InetAddress ipv4LocalAddress = getLocalIpv4Address(ipv4NetworkInterface);
         test_joinSourceSpecific(
                 ipv4LocalAddress /* senderBindAddress */,
@@ -1023,6 +1044,9 @@
 
     /** Checks that a source-specific join() works when the receiver is bound to the "any" address */
     public void test_joinSourceSpecific_anyBind_ipv6() throws Exception {
+        if (!supportsMulticast) {
+            return;
+        }
         InetAddress ipv6LocalAddress = getLocalIpv6Address(ipv6NetworkInterface);
         test_joinSourceSpecific(
                 ipv6LocalAddress /* senderBindAddress */,
@@ -1044,9 +1068,6 @@
             InetAddress senderBindAddress, InetAddress receiverBindAddress, InetAddress groupAddress,
             InetAddress badSenderAddress, NetworkInterface networkInterface)
             throws Exception {
-        if (!supportsMulticast) {
-            return;
-        }
         DatagramChannel sendingChannel = DatagramChannel.open();
         // In order to be source-specific the sender's address must be known. The sendingChannel is
         // explicitly bound to a known, non-loopback address.