### Question:
RestletOAuth2Request extends OAuth2Request { public <T> T getParameter(String name) { Object value = getAttribute(request, name); if (value != null) { return (T) value; } if (getQueryParameter(request, name) != null) { return (T) getQueryParameter(request, name); } if (request.getMethod().equals(Method.POST)) { if (request.getEntity() != null) { if (MediaType.APPLICATION_WWW_FORM.equals(request.getEntity().getMediaType())) { Form form = new Form(request.getEntity()); request.setEntity(form.getWebRepresentation()); return (T) form.getValuesMap().get(name); } else if (MediaType.APPLICATION_JSON.equals(request.getEntity().getMediaType())) { return (T) getBody().get(name).getObject(); } } } return null; } @Inject  RestletOAuth2Request(JacksonRepresentationFactory jacksonRepresentationFactory, @Assisted Request request); Request getRequest(); T getParameter(String name); JsonValue getBody(); @Override Locale getLocale();  }### Answer:
@Test public void shouldRetrieveAttributes() { setAttribute(request); setQueryParam(request); setBodyParam(request); String result = requestUnderTest.getParameter("realm"); assertEquals(result, "realmFromAttribute"); }
@Test public void shouldRetrieveQueryParams() { setQueryParam(request); setBodyParam(request); String result = requestUnderTest.getParameter("realm"); assertEquals(result, "realmFromQueryParam"); }
@Test public void shouldRetrieveBodyParam() { setBodyParam(request); String result = requestUnderTest.getParameter("realm"); assertEquals(result, "realmFromBody"); }
@Test public void shouldRetrieveNullWhenOnlyBodyAndGET() { request.setMethod(Method.GET); setBodyParam(request); String result = requestUnderTest.getParameter("realm"); assertNull(result); }