001package org.w3.ldp.testsuite.reporter;
002
003import java.lang.reflect.Method;
004
005public class ReportUtils {
006        public static final String JAVADOC_BASE_URI = "http://w3c.github.io/ldp-testsuite/api/java/";
007
008        /**
009         * Generates a link to the Javadoc hosted on w3c.github.io for the
010         * corresponding test method, which in turn link back to the source. This
011         * can be added to HTML and EARL test reports.
012         *
013         * @param method
014         *            the test method
015         * @return a link to the Javadoc.
016         * @see <a href="http://w3c.github.io/ldp-testsuite/api/java/">Hosted Javadoc</a>
017         */
018        public static String getJavadocLink(final Method method) {
019                // Example link:
020                //   http://w3c.github.io/ldp-testsuite/api/java/org/w3/ldp/testsuite/test/CommonContainerTest.html#testRequestedInteractionModelCreateNotAllowed(java.lang.String)
021                final StringBuilder link = new StringBuilder();
022                link.append(JAVADOC_BASE_URI);
023                link.append(method.getDeclaringClass().getCanonicalName().replace(".", "/"));
024                link.append(".html#");
025                link.append(method.getName());
026                link.append("(");
027                boolean first = true;
028                for (Class<?> paramType : method.getParameterTypes()) {
029                        if (!first) {
030                                link.append(", ");
031                        }
032
033                        link.append(paramType.getCanonicalName());
034                        first = false;
035                }
036                link.append(")");
037
038                return link.toString();
039        }
040}