### Question:
BasicAuthenticationHandler implements ClientAuthenticationHandler { public OAuth2HandlerError addOAuth2Authentication(final HttpRequest request, final OAuth2Accessor accessor) { try { if (request == null) { return BasicAuthenticationHandler.getError("request is null"); } if (accessor == null || !accessor.isValid() || accessor.isErrorResponse()) { return BasicAuthenticationHandler.getError("accessor is invalid " + accessor); } final String clientId = accessor.getClientId(); if (clientId == null) { return BasicAuthenticationHandler.getError("client_id is null"); } final byte[] secretBytes = accessor.getClientSecret(); if (secretBytes == null) { return BasicAuthenticationHandler.getError("client_secret is secret"); } final String secret = new String(secretBytes, "UTF-8"); final String authString = clientId + ':' + secret; final byte[] authBytes = Base64.encodeBase64(authString.getBytes()); request.setHeader(OAuth2Message.AUTHORIZATION_HEADER, "Basic: " + new String(authBytes)); return null; } catch (final Exception e) { return BasicAuthenticationHandler.getError("Exception adding basic auth headers", e); } }  OAuth2HandlerError addOAuth2Authentication(final HttpRequest request,
          final OAuth2Accessor accessor); String geClientAuthenticationType();  }### Answer:
@Test public void testAddOAuth2Authentication1() throws Exception { final BasicAuthenticationHandler fixture = new BasicAuthenticationHandler(); final HttpRequest request = null; final OAuth2Accessor accessor = MockUtils.getOAuth2Accessor_Code(); final OAuth2HandlerError result = fixture.addOAuth2Authentication(request, accessor); Assert.assertNotNull(result); Assert.assertEquals(null, result.getCause()); Assert.assertEquals("request is null", result.getContextMessage()); Assert.assertEquals( "org.apache.shindig.gadgets.oauth2.handler.OAuth2HandlerError : AUTHENTICATION_PROBLEM : request is null : : :null", result.toString()); }
@Test public void testAddOAuth2Authentication2() throws Exception { final BasicAuthenticationHandler fixture = new BasicAuthenticationHandler(); final HttpRequest request = new HttpRequest(Uri.fromJavaUri(new URI(""))); final OAuth2Accessor accessor = null; final OAuth2HandlerError result = fixture.addOAuth2Authentication(request, accessor); Assert.assertNotNull(result); Assert.assertEquals(null, result.getCause()); Assert.assertEquals("accessor is invalid null", result.getContextMessage()); Assert.assertEquals( "org.apache.shindig.gadgets.oauth2.handler.OAuth2HandlerError : AUTHENTICATION_PROBLEM : accessor is invalid null : : :null", result.toString()); }
@Test public void testAddOAuth2Authentication4() throws Exception { final BasicAuthenticationHandler fixture = new BasicAuthenticationHandler(); final HttpRequest request = new HttpRequest(Uri.fromJavaUri(new URI(""))); final OAuth2Accessor accessor = MockUtils.getOAuth2Accessor_Code(); final OAuth2HandlerError result = fixture.addOAuth2Authentication(request, accessor); Assert.assertNull(result); final String authHeader = request.getHeader("Authorization"); Assert.assertNotNull(authHeader); Assert.assertEquals("Basic: Y2xpZW50SWQxOmNsaWVudFNlY3JldDE=", authHeader); }