I am new in using dynamodb, and I tried to do uniting testing on one of the method.
When I try to mock
DeleteItemSpec deleteItemSpec = new DeleteItemSpec().withPrimaryKey(new PrimaryKey("id", id, "date", date).withConditionExpression("id = :id")
It returns NPE. How can I mock this with many properties?
Sorry for such a dumb question, but tried whole night for solution.
public void delete(String id) {
Item item = null;
Iterator<Item> iterator = getId(id);
while (iterator.hasNext()) {
item = iterator.next();
DeleteItemSpec deleteItemSpec = new DeleteItemSpec()
//get null pointer on below line
.withPrimaryKey(new PrimaryKey("id", id, "date", item.getString("date")))
.withConditionExpression("id = :id")
.withValueMap(new ValueMap()
.withString(":id", id))
.withReturnValues(ReturnValue.ALL_OLD);
try {
table.deleteItem(deleteItemSpec);
} catch (Exception e) {e.getLocalizedMessage(), e);
throw new dynamoDBException("...")
}
}
}
iterator.next()evaluated as null?