title: How to mock AWS API using Mockito in java
body: <p>I need help to mock AWS APIs using Mockito in Java. As I have tried to mock RDS connection but connection returns null statement object. I have to mock S3, AWS Data pipeline, <code>JavaSaprkContext</code>, RDS connection, Lambda, SNS and DynamoDB.</p>
  
  <p>Here is my code for RDS Connection, that returns null statement object:</p>
  
  <pre><code>public void testGetRDSConnection() throws SQLException{
      Connection connection = mock(Connection.class);
      Statement stmt = null;
      stmt = connection.createStatement(); // Get NULL statement Object
      ResultSet rs = stmt.executeQuery("SELECT * FROM table");
      if (rs.next()) {
          System.out.println("+ve Test is PASSED Name = testGetRDSConnection ");
      } else {
          System.out.println("+ve Test is FAILED Name= testGetRDSConnection ");
      }
  
  }
  </code></pre>
  
  <p>and test case for S3, that return null metadata object:</p>
  
  <pre><code> public void testGetObjectMetadata(){
      ObjectMetadata obj = S3Util.getObjectMetadata(mock(AmazonS3Client.class), bucketName, filePath);
      if (obj == null) {
          System.out.println("+ve Test is FAILED Name= 'testGetObjectMetadata()' No metadata found");
          fail("+ve Test is FAILED Name= 'testGetObjectMetadata()' No metadata found");
  
      } else if (obj != null) {
          System.out.println("+ve Test is FAILED Name= 'testGetObjectMetadata()'");
  
      }
  }
  </code></pre>