001 /* 002 * Created on Nov 22, 2007 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 005 * in compliance with the License. You may obtain a copy of the License at 006 * 007 * http://www.apache.org/licenses/LICENSE-2.0 008 * 009 * Unless required by applicable law or agreed to in writing, software distributed under the License 010 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 011 * or implied. See the License for the specific language governing permissions and limitations under 012 * the License. 013 * 014 * Copyright @2007-2009 the original author or authors. 015 */ 016 package org.fest.swing.junit.runner; 017 018 import static org.fest.util.Arrays.isEmpty; 019 import static org.fest.util.Strings.concat; 020 021 import java.lang.reflect.Method; 022 023 /** 024 * Understands formatting utilities for FEST-Swing JUnit runners. 025 * 026 * @author Alex Ruiz 027 * @author Yvonne Wang 028 */ 029 public final class Formatter { 030 031 /** 032 * Returns the name of a test given its class and method names. 033 * @param type the name of the test class. 034 * @param method the name of the test method. 035 * @return the name of a test. 036 */ 037 public static String testNameFrom(Class<?> type, Method method) { 038 return concat(type.getName(), ".", method.getName(), format(method.getParameterTypes())); 039 } 040 041 private static String format(Class<?>[] parameterTypes) { 042 if (isEmpty(parameterTypes)) return ""; 043 StringBuilder b = new StringBuilder("("); 044 for (int i = 0; i < parameterTypes.length; i++) { 045 b.append(parameterTypes[i].getName()); 046 if (i < parameterTypes.length - 1) b.append(", "); 047 } 048 b.append(")"); 049 return b.toString(); 050 } 051 052 private Formatter() {} 053 }