Exemplo n.º 1
0
 @Test
 public void testInexistentLabel() {
   try {
     Labels.getLabel("abra-cadabra");
     fail();
   } catch (Exception e) {
     // exception is good
   }
 }
Exemplo n.º 2
0
  private void findAndTestLabels(File file) throws IOException {
    // TODO: tune these regexps
    final Pattern LABELS_REGEX =
        Pattern.compile("Label.get{1,60}\"([a-z]\\w+?\\.[a-z][\\w.]+?\\w)\"");
    final Pattern EXCEPTION_REGEX = Pattern.compile("new\\s+?(\\w+?Exception)\\(\"([\\w.]+?\\w)\"");

    BufferedReader fileReader = new BufferedReader(new FileReader(file));
    StringBuffer sb = new StringBuffer();
    String fileLine;
    while ((fileLine = fileReader.readLine()) != null) {
      sb.append(fileLine);
    }
    fileReader.close();
    String fileContent = sb.toString();

    String key = null;
    //		String value = null;
    try {
      //			System.out.println(file.getPath());

      Matcher matcher = LABELS_REGEX.matcher(fileContent);
      while (matcher.find()) {
        // try to load the label
        key = matcher.group(1);
        //				value =
        Labels.getLabel(key);
        //				System.out.println(key + "=" + value);
      }

      matcher = EXCEPTION_REGEX.matcher(fileContent);
      while (matcher.find()) {
        // try to load the label
        key = "exception." + matcher.group(1) + "." + matcher.group(2);
        //				value =
        Labels.getLabel(key);
        //				System.out.println(key + "=" + value);
      }
    } catch (MissingResourceException e) {
      throw new AssertionFailedError("Label not found: " + key + ", in file: " + file.getPath());
    }
  }
Exemplo n.º 3
0
 @Test
 public void testSimpleLabel() {
   assertEquals("&Scan", Labels.getLabel("menu.scan"));
 }