langtools/test/jdk/javadoc/doclet/lib/JavadocTester.java
changeset 44684 6ce4d52084e8
parent 42842 2f0b2a65b284
equal deleted inserted replaced
44683:610dc2b48954 44684:6ce4d52084e8
     1 /*
     1 /*
     2  * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2002, 2017, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    44 import java.util.Collections;
    44 import java.util.Collections;
    45 import java.util.EnumMap;
    45 import java.util.EnumMap;
    46 import java.util.HashMap;
    46 import java.util.HashMap;
    47 import java.util.List;
    47 import java.util.List;
    48 import java.util.Map;
    48 import java.util.Map;
       
    49 import java.util.function.Function;
    49 
    50 
    50 
    51 
    51 /**
    52 /**
    52  * Test framework for running javadoc and performing tests on the resulting output.
    53  * Test framework for running javadoc and performing tests on the resulting output.
    53  *
    54  *
   235      * Run all methods annotated with @Test, followed by printSummary.
   236      * Run all methods annotated with @Test, followed by printSummary.
   236      * Typically called on a tester object in main()
   237      * Typically called on a tester object in main()
   237      * @throws Exception if any errors occurred
   238      * @throws Exception if any errors occurred
   238      */
   239      */
   239     public void runTests() throws Exception {
   240     public void runTests() throws Exception {
       
   241         runTests(m -> new Object[0]);
       
   242     }
       
   243 
       
   244     /**
       
   245      * Run all methods annotated with @Test, followed by printSummary.
       
   246      * Typically called on a tester object in main()
       
   247      * @param f a function which will be used to provide arguments to each
       
   248      *          invoked method
       
   249      * @throws Exception if any errors occurred
       
   250      */
       
   251     public void runTests(Function<Method, Object[]> f) throws Exception {
   240         for (Method m: getClass().getDeclaredMethods()) {
   252         for (Method m: getClass().getDeclaredMethods()) {
   241             Annotation a = m.getAnnotation(Test.class);
   253             Annotation a = m.getAnnotation(Test.class);
   242             if (a != null) {
   254             if (a != null) {
   243                 try {
   255                 try {
   244                     out.println("Running test " + m.getName());
   256                     out.println("Running test " + m.getName());
   245                     m.invoke(this, new Object[] { });
   257                     m.invoke(this, f.apply(m));
   246                 } catch (InvocationTargetException e) {
   258                 } catch (InvocationTargetException e) {
   247                     Throwable cause = e.getCause();
   259                     Throwable cause = e.getCause();
   248                     throw (cause instanceof Exception) ? ((Exception) cause) : e;
   260                     throw (cause instanceof Exception) ? ((Exception) cause) : e;
   249                 }
   261                 }
   250                 out.println();
   262                 out.println();