title: Mock Test for AWS Secret Manager - Java
body: <p>I am trying to test the AWS SecretManager call using Mockito but when I run the program, I am getting the Null Pointer Exception.</p>
  <pre><code>@ExtendWith(MockitoExtension.class)
  class XXXX{
  
  String secret = &quot;{ \&quot;client_id\&quot;: \&quot;XXXXXX\&quot;,\&quot;client_secret\&quot;: \&quot;XXXXXX\&quot;} &quot;;
      
      @Mock
      AWSSecretsManager secretsClient;
      @Mock
      GetSecretValueRequest secretValueRequest;
      @Mock
      GetSecretValueResult secretValueResult;
  
    @BeforeEach
    public void setUp(){
      lenient().when(secretsClient.getSecretValue(secretValueRequest)).thenReturn(secretValueResult);
      lenient().when(secretValueResult.getSecretString()).thenReturn(secret);
    }
  
  }
  </code></pre>
  <p>Here, when I am running, I am getting the NullPointerException at <code>when(secretsClient.getSecretValue(secretValueRequest))</code>. It says as <code>secretsClient.getSecretValue(secretValueRequest) is null</code> which is passed as parameter to <code>when()</code>. Any suggestion or advice what I am doing wrong here, please.</p>