curator-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Cameron McKenzie <>
Subject Re: How to mock "create" method of CuratorFramework using jmockit?
Date Mon, 09 Jun 2014 05:27:43 GMT
The JMockit groups are probably a better place to ask given that your
questions aren't really anything to do with Curator.

As far as testing stuff against Curator though, I'd suggest you look at
using the curator TestingServer class. It runs up an in memory version of
ZooKeeper that allows you to test stuff without mocking it all out. Given
all of the timing issues etc. involved with working with ZooKeeper, I find
that this is a much better way to write tests.

On Mon, Jun 9, 2014 at 2:30 PM, Check Peck <> wrote:

> I am using Netflix Curator library as I am working with Zookeeper. And now
> I am trying to write junit test for my code base so I need to mock some of
> the codes for Curator library.
> I am using jmockit library for mocking.
> This is my below code which creates a simple znode in the zookeeper.
>     CuratorFramework client = CuratorClient.createSimple("locahost:2181");
>     client.start();
>     // line 1
>     client.create().creatingParentsIfNeeded().forPath("/hello");
> Now I am trying to mock `create` method of `CuratorFramework` using
> `jmockit` so that it doesn't create the actual znode in Zookeeper.
> But not able to understand how can I mock it properly?
>         new MockUp<CuratorFramework>() {
>             @Mock
>             public CreateBuilder create() {
>                 // what should I return here so that line 1 doesn't
>                 // create actual znode in zookeeper.
>             }
>         };
> Any suggestions will be of great help?

View raw message