package com.et.monotone.zk;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.Mockito;

import com.netflix.curator.framework.CuratorFramework;
import com.netflix.curator.framework.imps.CuratorFrameworkState;
import com.netflix.curator.framework.recipes.atomic.AtomicValue;
import com.netflix.curator.framework.recipes.atomic.DistributedAtomicLong;
import com.netflix.curator.utils.EnsurePath;

public class ZkGeneratorTest {

	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	@Before
	public void setUp() throws Exception {
	}

	@After
	public void tearDown() throws Exception {
	}

	@Test
	public void test() throws Exception {
		long ID_SEED = 100;
		
		CuratorFramework mockCurator = Mockito.mock(CuratorFramework.class);
		EnsurePath mockEnsurePath = Mockito.mock(EnsurePath.class);
		DistributedAtomicLong mockZkLong = Mockito.mock(DistributedAtomicLong.class);
		AtomicValue<Long> mockAtomicValue = Mockito.mock(AtomicValue.class);

		Mockito.when(mockCurator.getState()).thenReturn(CuratorFrameworkState.STARTED);
		Mockito.when(mockCurator.newNamespaceAwareEnsurePath(Mockito.anyString())).thenReturn(mockEnsurePath);
		Mockito.when(mockEnsurePath.excludingLast()).thenReturn(mockEnsurePath);
		
		
		Mockito.when(mockZkLong.get()).thenReturn(mockAtomicValue);
		Mockito.when(mockAtomicValue.postValue()).thenReturn(ID_SEED);
		Mockito.when(mockZkLong.compareAndSet(Mockito.anyLong(), Mockito.anyLong())).thenReturn(mockAtomicValue);
		Mockito.when(mockAtomicValue.succeeded()).thenReturn(true);

		ZKGenerator mockGenerator = (ZKGenerator) ZKGenerator.newBuilder(mockCurator)
				.setDistributedAtomicLong(mockZkLong).build();
		long id = mockGenerator.nextId();

		Assert.assertTrue(id == ID_SEED + 1);
	}
}
@@ -768,18 +768,16 @@
  = 100;%0A
-%09%09
 %0A%09%09Curat
@@ -1316,21 +1316,16 @@
 ePath);%0A
-%09%09%0A%09%09
 %0A%09%09Mocki
@@ -1440,24 +1440,27 @@
 n(ID_SEED);%0A
+%09%09%0A
 %09%09Mockito.wh
@@ -1477,41 +1477,12 @@
 ong.
-compareAndSet(Mockito.anyLong(), 
+add(
 Mock
@@ -1776,30 +1776,20 @@
 sert
-True(id == ID_SEED + 1
+Equals(1, id
 );%0A%09

fix test