コード例 #1
0
 private static void checkImmutableList(List<String> list) {
   try {
     list.add("hello");
     error("%s is mutable%n", list);
   } catch (UnsupportedOperationException e) {
   }
 }
コード例 #2
0
  private static void testGetCandidateLocales() {
    Map<Locale, Locale[]> candidateData = new HashMap<Locale, Locale[]>();
    candidateData.put(
        new Locale("ja", "JP", "YOK"),
        new Locale[] {
          new Locale("ja", "JP", "YOK"), new Locale("ja", "JP"), new Locale("ja"), new Locale("")
        });
    candidateData.put(
        new Locale("ja", "JP"),
        new Locale[] {new Locale("ja", "JP"), new Locale("ja"), new Locale("")});
    candidateData.put(new Locale("ja"), new Locale[] {new Locale("ja"), new Locale("")});

    candidateData.put(
        new Locale("ja", "", "YOK"),
        new Locale[] {new Locale("ja", "", "YOK"), new Locale("ja"), new Locale("")});
    candidateData.put(
        new Locale("", "JP", "YOK"),
        new Locale[] {new Locale("", "JP", "YOK"), new Locale("", "JP"), new Locale("")});
    candidateData.put(
        new Locale("", "", "YOK"), new Locale[] {new Locale("", "", "YOK"), new Locale("")});
    candidateData.put(new Locale("", "JP"), new Locale[] {new Locale("", "JP"), new Locale("")});
    candidateData.put(new Locale(""), new Locale[] {new Locale("")});

    for (Locale locale : candidateData.keySet()) {
      List<Locale> candidates = CONTROL.getCandidateLocales("any", locale);
      List<Locale> expected = Arrays.asList(candidateData.get(locale));
      if (!candidates.equals(expected)) {
        error(
            "Wrong candidates for %s: got %s, expected %s%n",
            toString(locale), candidates, expected);
      }
    }
    final int NARGS = 2;
    for (int mask = 0; mask < (1 << NARGS) - 1; mask++) {
      Object[] data = getNpeArgs(NARGS, mask);
      try {
        List<Locale> candidates = CONTROL.getCandidateLocales((String) data[0], (Locale) data[1]);
        error(
            "getCandidateLocales(%s, %s) doesn't throw NPE.%n",
            data[0], toString((Locale) data[1]));
      } catch (NullPointerException e) {
      }
    }
  }