使用Spock进行Amazon Dynamodb的单元测试

时间:2019-08-25 17:53:51

标签: java unit-testing nullpointerexception spock

我是使用dynamodb的新手,我尝试对其中一种方法进行统一测试。

当我尝试模拟

DeleteItemSpec deleteItemSpec = new DeleteItemSpec().withPrimaryKey(new PrimaryKey("id", id, "date", date).withConditionExpression("id = :id")

它返回NPE。我该如何用许多属性来模拟呢?

很抱歉提出这样一个愚蠢的问题,但整夜都在寻求解决方案。

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("...")
        }
    }
}

0 个答案:

没有答案
相关问题