1 /*
   2  * @test /nodynamiccopyright/
   3  * @bug 8206986
   4  * @summary Verify cases with multiple labels work properly.
   5  * @compile/fail/ref=MultipleLabelsStatement-old.out -source 9 -Xlint:-options -XDrawDiagnostics MultipleLabelsStatement.java
   6  * @compile MultipleLabelsStatement.java
   7  * @run main MultipleLabelsStatement
   8  */
   9 
  10 import java.util.Objects;
  11 import java.util.function.Function;
  12 
  13 public class MultipleLabelsStatement {
  14     public static void main(String... args) {
  15         new MultipleLabelsStatement().run();
  16     }
  17 
  18     private void run() {
  19         runTest(this::statement1);
  20     }
  21 
  22     private void runTest(Function<T, String> print) {
  23         check(T.A,  print, "A");
  24         check(T.B,  print, "B-C");
  25         check(T.C,  print, "B-C");
  26         check(T.D,  print, "D");
  27         check(T.E,  print, "other");
  28     }
  29 
  30     private String statement1(T t) {
  31         String res;
  32 
  33         switch (t) {
  34             case A: res = "A"; break;
  35             case B, C: res = "B-C"; break;
  36             case D: res = "D"; break;
  37             default: res = "other"; break;
  38         }
  39 
  40         return res;
  41     }
  42 
  43     private void check(T t, Function<T, String> print, String expected) {
  44         String result = print.apply(t);
  45         if (!Objects.equals(result, expected)) {
  46             throw new AssertionError("Unexpected result: " + result);
  47         }
  48     }
  49 
  50     enum T {
  51         A, B, C, D, E;
  52     }
  53 }