AmazonAuthHelper { @VisibleForTesting String formatPayloadForPut(String date, String payloadStr, S3File s3File) { return String.format(payloadStr, s3File.getMd5Base64(), s3File.getContentType(), date, s3User.getBucket(), s3File.getObjectKey()); } @Inject  AmazonAuthHelper(SignatureHelper signatureHelper, S3User s3User); @NonNull String getAmazonAuthForPut(String date, String payloadStr, S3File s3File); @NonNull String getAmazonAuthForGet(String date, String payloadStr, String filename);  }
@Test public void shouldFormatPublicPayloadCorrectly() { AmazonAuthHelper helper = new AmazonAuthHelper(null, new S3User("bucket", null, null)); S3File s3File = spy(new S3File(new File("dir", "name.png"), true, "dir", "action", "md564","md5hex")); when(s3File.getContentType()).thenReturn("type"); String formattedPayload = helper.formatPayloadForPut("12-12-2009", PAYLOAD_PUT_PUBLIC, s3File); assertEquals("PUT\nmd564\ntype\n12-12-2009\nx-amz-acl:public-read\n/bucket/dir/name.png", formattedPayload); }
@Test(expected = NullPointerException.class) public void shouldFormatPayloadFailIfNullPayload() { AmazonAuthHelper helper = new AmazonAuthHelper(null, new S3User("bucket", null, null)); S3File s3File = spy(new S3File(new File("dir", "name.png"), true, "dir", "action", "md564","md5hex")); when(s3File.getContentType()).thenReturn("type"); helper.formatPayloadForPut("12-12-2009", null, s3File); }
@Test(expected = NullPointerException.class) public void shouldFormatPayloadFailIfNullS3File() { AmazonAuthHelper helper = new AmazonAuthHelper(null, new S3User("bucket", null, null)); helper.formatPayloadForPut("12-12-2009", PAYLOAD_PUT_PUBLIC, null); }