### Question:
ClientCredentialsRequestValidatorImpl implements ClientCredentialsRequestValidator { public void validateRequest(OAuth2Request request, ClientRegistration clientRegistration) throws UnauthorizedClientException { if (!clientRegistration.isConfidential()) { logger.error("Client is not confidential. Public clients cannot use the client credentials grant."); throw new UnauthorizedClientException("Public clients can't use client credentials grant."); } }  void validateRequest(OAuth2Request request, ClientRegistration clientRegistration);  }### Answer:
@Test public void shouldValidateValidRequest() throws UnauthorizedClientException { OAuth2Request request = mock(OAuth2Request.class); ClientRegistration clientRegistration = mock(ClientRegistration.class); given(clientRegistration.isConfidential()).willReturn(true); requestValidator.validateRequest(request, clientRegistration); }
@Test (expectedExceptions = UnauthorizedClientException.class) public void shouldValidateRequestWhenClientRegistrationIsConfidential() throws UnauthorizedClientException { OAuth2Request request = mock(OAuth2Request.class); ClientRegistration clientRegistration = mock(ClientRegistration.class); given(clientRegistration.isConfidential()).willReturn(false); requestValidator.validateRequest(request, clientRegistration); }