如何模拟"创建"使用jmockit的CuratorFramework方法?

时间:2014-06-09 04:45:21

标签: java unit-testing apache-zookeeper jmockit apache-curator

我正在使用Netflix Curator库,因为我正在使用Zookeeper。现在我正在尝试为我的代码库编写junit测试,所以我需要模拟一些Curator库的代码。我正在使用jmockit库进行模拟。

这是我的下面的代码,它在zookeeper中创建了一个简单的znode。

CuratorFramework client = CuratorClient.createSimple("locahost:2181");
client.start();

// line 1
client.create().creatingParentsIfNeeded().forPath("/hello");

现在我正在尝试使用create模拟CuratorFramework jmockit方法,以便它不会在Zookeeper中创建实际的znode。

但是不能理解我怎么能狠狠地嘲笑它?

    new MockUp<CuratorFramework>() {
        @Mock
        public CreateBuilder create() {

            // what should I return here so that line 1 doesn't
            // create actual znode in zookeeper.
        }
    };

以下是CuratorFramework code及其implementation

任何建议都会有很大帮助吗?

0 个答案:

没有答案
相关问题