Below is the code which I am trying to Mock,
this.dynamoDb.getTable(PropertyUtil.get(Constants.SOME_TABLE_NAME))
.putItem(
new PutItemSpec()
.withItem(new Item().withString("ID", pId).withString("eId", pEId)
.withString("activeInd", pActiveInd)));
What I have tried is below,
mockStatic(AmazonDynamoDBClientBuilder.class);
when(AmazonDynamoDBClientBuilder.defaultClient()).thenReturn(Mockito.mock(AmazonDynamoDB.class));
PowerMockito.mockStatic(PropertyUtil.class);
when(PropertyUtil.get(Constants.Some__ID_MAPPING_TABLE_NAME)).thenReturn("SOME_TABLE_NAME");
Table vTable = mock(Table.class);
PutItemSpec vPutItemSpec = mock(PutItemSpec.class);
PutItemResult vPutItemResult = new PutItemResult();
PowerMockito.whenNew(PutItemSpec.class).withAnyArguments().thenReturn(vPutItemSpec);
PowerMockito.when(vTable.putItem(vPutItemSpec)).thenReturn(vPutItemOutcome);
And the error that I get due to this is below,
java.lang.IllegalArgumentException: null
at com.amazonaws.services.dynamodbv2.document.PutItemOutcome.<init>(PutItemOutcome.java:33) ~[aws-java-sdk-dynamodb-1.11.400.jar:?]
at com.amazonaws.services.dynamodbv2.document.internal.PutItemImpl.doPutItem(PutItemImpl.java:86) ~[aws-java-sdk-dynamodb-1.11.400.jar:?]
at com.amazonaws.services.dynamodbv2.document.internal.PutItemImpl.putItem(PutItemImpl.java:63) ~[aws-java-sdk-dynamodb-1.11.400.jar:?]
at com.amazonaws.services.dynamodbv2.document.Table.putItem(Table.java:168) ~[aws-java-sdk-dynamodb-1.11.400.jar:?]
Please suggest, what I need to fix, I am new to Mock and JUnit. Thanks in Advance.