Example usage for java.lang NoSuchMethodError NoSuchMethodError

List of usage examples for java.lang NoSuchMethodError NoSuchMethodError

Introduction

In this page you can find the example usage for java.lang NoSuchMethodError NoSuchMethodError.

Prototype

public NoSuchMethodError() 

Source Link

Document

Constructs a NoSuchMethodError with no detail message.

Usage

From source file:Main.java

public static Method findMethodByNameAndReturnType(Class<?> targetObject, String methodName, String returnType,
        Class<?>... params) {
    for (Method method : targetObject.getDeclaredMethods()) {
        if (method.getReturnType().getName().equals(returnType) && method.getName().equals(methodName)) {
            Class[] parameterTypes = method.getParameterTypes();
            if (params.length != parameterTypes.length) {
                continue;
            }/*from w w  w . j  av  a  2s .  c  om*/
            for (int i = 0; i < params.length; i++) {
                if (params[i] != parameterTypes[i]) {
                    break;
                }
            }
            method.setAccessible(true);
            return method;
        }
    }
    throw new NoSuchMethodError();
}

From source file:org.jolokia.http.AgentServletTest.java

@Test
public void unknownMethodWhenSettingContentType() throws ServletException, IOException {
    prepareStandardInitialisation();//from w  w w . ja va 2 s . co m

    StringWriter sw = initRequestResponseMocks(getStandardRequestSetup(), new Runnable() {
        public void run() {
            response.setCharacterEncoding("utf-8");
            expectLastCall().andThrow(new NoSuchMethodError());
            response.setContentType("text/plain; charset=utf-8");
            response.setStatus(200);
        }
    });
    expect(request.getPathInfo()).andReturn(HttpTestUtil.HEAP_MEMORY_GET_REQUEST);
    expect(request.getParameter(ConfigKey.MIME_TYPE.getKeyValue())).andReturn(null);
    expect(request.getAttribute("subject")).andReturn(null);

    replay(request, response);

    servlet.doGet(request, response);

    assertTrue(sw.toString().contains("used"));
    servlet.destroy();
}