test/tools/doclint/ResourceTest.java

Mon, 31 Aug 2015 13:37:01 -0700

author
asaha
date
Mon, 31 Aug 2015 13:37:01 -0700
changeset 2971
153d0309e698
parent 0
959103a6100f
permissions
-rw-r--r--

Added tag jdk8u65-b12 for changeset 54e958a3719e

     1 /*
     2  * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  */
    24 /*
    25  * @test
    26  * @bug 8006615
    27  * @summary move remaining messages into resource bundle
    28  */
    30 import java.io.IOException;
    31 import java.io.PrintWriter;
    32 import java.io.StringWriter;
    33 import java.util.Arrays;
    34 import java.util.List;
    35 import java.util.Locale;
    37 import com.sun.tools.doclint.DocLint;
    39 public class ResourceTest {
    40     public static void main(String... args) throws Exception {
    41         Locale prev = Locale.getDefault();
    42         Locale.setDefault(Locale.ENGLISH);
    43         try {
    44             new ResourceTest().run();
    45         } finally {
    46            Locale.setDefault(prev);
    47         }
    48     }
    50     public void run() throws Exception {
    51         test(Arrays.asList("-help"),
    52                 Arrays.asList("Usage:", "Options"));
    53         test(Arrays.asList("-foo"),
    54                 Arrays.asList("bad option: -foo"));
    55     }
    57     void test(List<String> opts, List<String> expects) throws Exception {
    58         StringWriter sw = new StringWriter();
    59         PrintWriter pw = new PrintWriter(sw);
    60         try {
    61             new DocLint().run(pw, opts.toArray(new String[opts.size()]));
    62         } catch (DocLint.BadArgs e) {
    63             pw.println("BadArgs: " + e.getMessage());
    64         } catch (IOException e) {
    65             pw.println("IOException: " + e.getMessage());
    66         } finally {
    67             pw.close();
    68         }
    70         String out = sw.toString();
    71         if (!out.isEmpty()) {
    72             System.err.println(out);
    73         }
    75         for (String e: expects) {
    76             if (!out.contains(e))
    77                 throw new Exception("expected string not found: " + e);
    78         }
    79     }
    80 }

mercurial