Classmethod equivalent to unittest.TestCase method (longMessage = False.)
500054
def simple_equality(cls, first, second, msg=None):
        
        if not first==second:
            standardMsg = '%s != %s' % (safe_repr(first), safe_repr(second))
            raise cls.failureException(msg or standardMsg)
1282236
public static void assertValidSetterName(final Method method, Class<? extends Annotation> annotation)
   {
      final String methodName = method.getName();
      final boolean correctMethodNameLength = methodName.length() > 3;
      final boolean isSetterMethodName = methodName.startsWith("set");
      final boolean isUpperCasedPropertyName = correctMethodNameLength ? Character.isUpperCase(methodName.charAt(3)) : false;

      if (!correctMethodNameLength || !isSetterMethodName || !isUpperCasedPropertyName)
      {
         throw annotation == null ? MESSAGES.methodDoesNotRespectJavaBeanSetterMethodName(method) : MESSAGES.methodDoesNotRespectJavaBeanSetterMethodName2(method, annotation);
      }
   }
328124
public static Function<Object,Long> l(final String methodName, final Object... optionalParameters) {
        return methodForLong(methodName, optionalParameters);
    }
875741
private static AssertionError createComparisonFailure(final String reason, final String controlString,
            final String testString) {
        try {
            if (comparisonFailureConstructor == null) {
                final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
                Class<?> comparisonFailureClass = classLoader.loadClass("org.junit.ComparisonFailure");
                comparisonFailureConstructor = comparisonFailureClass.getConstructor(String.class, String.class,
                    String.class);
            }
            return (AssertionError) comparisonFailureConstructor.newInstance(reason, controlString, testString);
        } catch (Exception e) {
            // ClassNotFoundException, NoSuchMethodException, InstantiationException,
            // IllegalAccessException, InvocationTargetException
            LOGGER.info("Either add junit to your classpath or do not call '.throwComparisonFailure()'. " + e);
        }

        return null;
    }
1023678
def _mock_methodcall(self, methodname, localobject, Params=None, **params):
        # pylint: disable=invalid-name
        
        result = self._fake_invokemethod(methodname, localobject, Params,
                                         **params)

        # Sleep for defined number of seconds
        if self._response_delay:
            time.sleep(self._response_delay)

        return result
147647
private Object invoke(String methodName, Object returnValueIfNonExistent,
                          Class<?>[] paramTypes, Object[] params)
        throws DocletInvokeException {
            Method meth;
            try {
                meth = docletClass.getMethod(methodName, paramTypes);
            } catch (NoSuchMethodException exc) {
                if (returnValueIfNonExistent == null) {
                    messager.error(Messager.NOPOS, "main.doclet_method_not_found",
                                   docletClassName, methodName);
                    throw new DocletInvokeException();
                } else {
                    return returnValueIfNonExistent;
                }
            } catch (SecurityException exc) {
                messager.error(Messager.NOPOS, "main.doclet_method_not_accessible",
                               docletClassName, methodName);
                throw new DocletInvokeException();
            }
            if (!Modifier.isStatic(meth.getModifiers())) {
                messager.error(Messager.NOPOS, "main.doclet_method_must_be_static",
                               docletClassName, methodName);
                throw new DocletInvokeException();
            }
            ClassLoader savedCCL =
                Thread.currentThread().getContextClassLoader();
            try {
                if (appClassLoader != null) // will be null if doclet class provided via API
                    Thread.currentThread().setContextClassLoader(appClassLoader);
                return meth.invoke(null , params);
            } catch (IllegalArgumentException exc) {
                messager.error(Messager.NOPOS, "main.internal_error_exception_thrown",
                               docletClassName, methodName, exc.toString());
                throw new DocletInvokeException();
            } catch (IllegalAccessException exc) {
                messager.error(Messager.NOPOS, "main.doclet_method_not_accessible",
                               docletClassName, methodName);
                throw new DocletInvokeException();
            } catch (NullPointerException exc) {
                messager.error(Messager.NOPOS, "main.internal_error_exception_thrown",
                               docletClassName, methodName, exc.toString());
                throw new DocletInvokeException();
            } catch (InvocationTargetException exc) {
                Throwable err = exc.getTargetException();
                if (apiMode)
                    throw new ClientCodeException(err);
                if (err instanceof java.lang.OutOfMemoryError) {
                    messager.error(Messager.NOPOS, "main.out.of.memory");
                } else {
                    messager.error(Messager.NOPOS, "main.exception_thrown",
                               docletClassName, methodName, exc.toString());
                    exc.getTargetException().printStackTrace();
                }
                throw new DocletInvokeException();
            } finally {
                Thread.currentThread().setContextClassLoader(savedCCL);
            }
    }
1336662
@GwtIncompatible("incompatible method")
    private static Throwable getCauseUsingMethodName(final Throwable throwable, final String methodName) {
        Method method = null;
        try {
            method = throwable.getClass().getMethod(methodName);
        } catch (final NoSuchMethodException | SecurityException ignored) { // NOPMD
            // exception ignored
        }

        if (method != null && Throwable.class.isAssignableFrom(method.getReturnType())) {
            try {
                return (Throwable) method.invoke(throwable);
            } catch (final IllegalAccessException | IllegalArgumentException | InvocationTargetException ignored) { // NOPMD
                // exception ignored
            }
        }
        return null;
    }
1055044
private List<ReportCodeLine> generateReportCodeBody(TestMethod rootMethod,
            RunFailure runFailure, boolean executed) throws IllegalTestScriptException {
        String currentStepLabelTtId = null;
        List<ReportCodeLine> result = new ArrayList<>(rootMethod.getCodeBody().size());
        for (int i = 0; i < rootMethod.getCodeBody().size(); i++) {
            CodeLine codeLine = rootMethod.getCodeBody().get(i);
            String rootTtId = Integer.toString(i);
            String parentTtIdForRoot = null;
            if (codeLine.getCode() instanceof TestStepLabel) {
                parentTtIdForRoot = null;
                currentStepLabelTtId = rootTtId;
            } else if (codeLine.getCode() instanceof TestStep) {
                throw new RuntimeException("not supported");
            } else {
                parentTtIdForRoot = currentStepLabelTtId;
            }

            StackLine rootStackLine = generateStackLine(
                    rootMethod, rootMethod.getKey(), i, codeLine.getStartLine());
            List<StackLine> rootStackLines = new ArrayList<>(1);
            rootStackLines.add(rootStackLine);

            ReportCodeLine reportCodeLine = generateReportCodeLine(
                    codeLine, rootMethod.getArgVariables(), rootStackLines,
                    runFailure, executed, rootTtId, parentTtIdForRoot);
            result.add(reportCodeLine);

            // add direct child to HTML report
            if (codeLine.getCode() instanceof SubMethodInvoke) {
                SubMethodInvoke invoke = (SubMethodInvoke) codeLine.getCode();
                // don't add child HTML report for childInvoke
                // since the code body for the sub method is not the code body of
                // the actually invoked method.
                // TODO consider about this behavior
                if (!invoke.isChildInvoke()) {
                    List<String> parentMethodArgTestDocs = reportCodeLine.getMethodArgTestDocs();
                    List<CodeLine> codeBody = invoke.getSubMethod().getCodeBody();
                    for (int j = 0; j < codeBody.size(); j++) {
                        CodeLine childCodeLine = codeBody.get(j);
                        if (childCodeLine.getCode() instanceof TestStepLabel) {
                            throw new RuntimeException("nested TestStepLabel is not supported yet");
                        } else if (childCodeLine.getCode() instanceof TestStep) {
                            throw new RuntimeException("not supported");
                        }
                        StackLine childStackLine = generateStackLine(invoke.getSubMethod(),
                                invoke.getSubMethodKey(), j, childCodeLine.getStartLine());
                        List<StackLine> childStackLines = new ArrayList<>(2);
                        childStackLines.add(childStackLine);
                        childStackLines.add(rootStackLine);

                        ReportCodeLine childReportCodeLine = generateReportCodeLine(
                                childCodeLine, parentMethodArgTestDocs, childStackLines,
                                runFailure, executed, rootTtId + "_" + j, rootTtId);
                        result.add(childReportCodeLine);
                    }
                }
            }
        }

        // update hasError and alreadyRun status of TestStepLabel CodeLine
        // according to its child code block
        ReportCodeLine currentStepLabelLine = null;
        for (int i = 0; i < result.size(); i++) {
            ReportCodeLine reportCodeLine = result.get(i);
            Code code = reportCodeLine.getCodeLine().getCode();
            if (code instanceof TestStepLabel) {
                currentStepLabelLine = result.get(i);
                continue;
            }
            if (currentStepLabelLine == null) {
                continue; // no TestStepLabel to be updated
            }
            if (reportCodeLine.hasError()) {
                // If child code block contains error,
                // TestStepLabel also has error
                currentStepLabelLine.setHasError(true);
                currentStepLabelLine.setAlreadyRun(true);
                // use error image for child code block
                currentStepLabelLine.setImageId(reportCodeLine.getImageId());
            } else if (!reportCodeLine.isAlreadyRun() && !currentStepLabelLine.hasError()) {
                // If child code block contains not executed line,
                // TestStepLabel is also not executed
                currentStepLabelLine.setHasError(false);
                currentStepLabelLine.setAlreadyRun(false);
            }
        }

        return result;
    }
269209
public static MethodInstance getMethodInstanceEL(Object objMaybeNull, Class clazz, Collection.Key methodName, Object[] args) {
	checkAccessibility(objMaybeNull, clazz, methodName);
	args = cleanArgs(args);

	Method[] methods = mStorage.getMethods(clazz, methodName, args.length);// getDeclaredMethods(clazz);

	if (methods != null) {
	    Class[] clazzArgs = getClasses(args);
	    // exact comparsion
	    // print.e("exact:"+methodName);
	    outer: for (int i = 0; i < methods.length; i++) {
		if (methods[i] != null) {
		    Class[] parameterTypes = methods[i].getParameterTypes();
		    for (int y = 0; y < parameterTypes.length; y++) {
			if (toReferenceClass(parameterTypes[y]) != clazzArgs[y]) continue outer;
		    }
		    return new MethodInstance(methods[i], args);
		}
	    }
	    // like comparsion
	    // MethodInstance mi=null;
	    // print.e("like:"+methodName);
	    outer: for (int i = 0; i < methods.length; i++) {
		if (methods[i] != null) {
		    Class[] parameterTypes = methods[i].getParameterTypes();
		    for (int y = 0; y < parameterTypes.length; y++) {
			if (!like(clazzArgs[y], toReferenceClass(parameterTypes[y]))) continue outer;
		    }
		    return new MethodInstance(methods[i], args);
		}
	    }

	    // convert comparsion
	    // print.e("convert:"+methodName);
	    MethodInstance mi = null;
	    int _rating = 0;
	    outer: for (int i = 0; i < methods.length; i++) {
		if (methods[i] != null) {
		    RefInteger rating = (methods.length > 1) ? new RefIntegerImpl(0) : null;
		    Class[] parameterTypes = methods[i].getParameterTypes();
		    Object[] newArgs = new Object[args.length];
		    for (int y = 0; y < parameterTypes.length; y++) {
			try {
			    newArgs[y] = convert(args[y], toReferenceClass(parameterTypes[y]), rating);
			}
			catch (PageException e) {
			    continue outer;
			}
		    }
		    if (mi == null || rating.toInt() > _rating) {
			if (rating != null) _rating = rating.toInt();
			mi = new MethodInstance(methods[i], newArgs);
		    }
		    // return new MethodInstance(methods[i],newArgs);
		}
	    }
	    return mi;
	}
	return null;
    }
1121709
public void startScenario( Class<?> testClass, Method method, List<NamedArgument> arguments ) {
        listener.scenarioStarted( testClass, method, arguments );

        if( method.isAnnotationPresent( Pending.class ) ) {
            Pending annotation = method.getAnnotation( Pending.class );

            if( annotation.failIfPass() ) {
                failIfPass();
            } else if( !annotation.executeSteps() ) {
                methodInterceptor.disableMethodExecution();
                executeLifeCycleMethods = false;
            }
            suppressExceptions = true;
        } else if( method.isAnnotationPresent( NotImplementedYet.class ) ) {
            NotImplementedYet annotation = method.getAnnotation( NotImplementedYet.class );

            if( annotation.failIfPass() ) {
                failIfPass();
            } else if( !annotation.executeSteps() ) {
                methodInterceptor.disableMethodExecution();
                executeLifeCycleMethods = false;
            }
            suppressExceptions = true;
        }

    }
1090752
@Deprecated
    protected void validateInstanceMethods(List<Throwable> errors) {
        validatePublicVoidNoArgMethods(After.class, false, errors);
        validatePublicVoidNoArgMethods(Before.class, false, errors);
        validateTestMethods(errors);

        if (computeTestMethods().isEmpty()) {
            errors.add(new Exception("No runnable methods"));
        }
    }
135798
private boolean mockingObsoleteMethod(MethodTree enclosingMethod, VisitorState state, Type type) {
    // mutable boolean to return result from visitor
    boolean[] found = {false};
    enclosingMethod.accept(
        new TreeScanner<Void, Void>() {
          @Override
          public Void visitMethodInvocation(MethodInvocationTree node, Void unused) {
            if (found[0]) {
              return null;
            }
            if (MOCKITO_MATCHER.matches(node, state)) {
              Type stubber = ASTHelpers.getReturnType(node);
              if (!stubber.getTypeArguments().isEmpty()
                  && ASTHelpers.isSameType(
                      getOnlyElement(stubber.getTypeArguments()), type, state)) {
                found[0] = true;
              }
            }
            return super.visitMethodInvocation(node, null);
          }
        },
        null);
    return found[0];
  }
735142
@Override
  public MethodVisitor visitMethod(
      final int access,
      final String name,
      final String desc,
      final String signature,
      final String[] exceptions) {
    MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
    return new CodeSizeEvaluator(mv) {
      @Override
      public void visitEnd() {
        super.visitEnd();
        if (getMaxSize() > 64 * 1024) {
          state = State.FAIL_TOO_LONG;
          message = "the method " + name + " was too long.";
        }
      }
    };
  }
33578
public static void assertOneParameter(final Method method, Class<? extends Annotation> annotation)
   {
      if (method.getParameterTypes().length != 1)
      {
         throw annotation == null ? MESSAGES.methodHasToDeclareExactlyOneParameter(method) : MESSAGES.methodHasToDeclareExactlyOneParameter2(method, annotation);
      }
   }
435637
protected void assertNoNameParameter(Method executeMethod, String urlPattern, String elementName) {
        if (!elementName.isEmpty()) {
            throwUrlPatternNamedParameterUnsupportedException(executeMethod, urlPattern, elementName);
        }
    }
673307
def exception(message):
    """"""

    def decorator(method):
        """Inner decorator so we can accept arguments."""

        @wraps(method)
        def wrapper(self, *args, **kwargs):
            """Innermost decorator wrapper - this is confusing."""
            if self.messages:
                kwargs['message'] = args[0] if args else kwargs.get('message', message)
            else:
                kwargs['message'] = None
            kwargs['prefix'] = self.prefix
            kwargs['statsd'] = self.statsd

            return method(self, **kwargs)

        return wrapper

    return decorator
1307823
private synchronized void tryProcessMethod(Class<?> clazz, String methodName, boolean expectedToExist, Class<?> ... parameterTypes) {
        
        final Method method;
        try {
            method = clazz.getMethod(methodName, parameterTypes);
        } catch (NoSuchMethodException ex) {
            Level logLevel = expectedToExist ? Level.INFO : Level.CONFIG;
            if (LOGGER.isLoggable(logLevel)) {
                String methodSpec = String.format("%s(%s)", methodName, StringUtils.join(parameterTypes, ","));
                LOGGER.log(logLevel, "No method {0} for class {1}", new Object[] {methodSpec, clazz});
            }
            return;
        } catch (RuntimeException ex) {
            Level logLevel = expectedToExist ? Level.INFO : Level.CONFIG;
            if (LOGGER.isLoggable(logLevel)) {
                String methodSpec = String.format("%s(%s)", methodName, StringUtils.join(parameterTypes, ","));
                LOGGER.log(logLevel, "Failed to retrieve the method {0} for class {1}", new Object[] {methodSpec, clazz});
            }
            return;
        }
        
        Class<?> returnType = method.getReturnType();
            // We do not veto the the root class
            if (ParameterValue.class.isAssignableFrom(returnType)) {
                if (!ParameterValue.class.equals(returnType)) {
                    // Add this class to the cache
                    paramValueCache_maskedClasses.add(returnType.getName());
                }
            }
    }