package de.jsmithy.rest.jaxrs.nutshell.client;

import static org.junit.Assert.*;

import javax.ws.rs.client.Client;

import org.junit.*;
import org.junit.runners.MethodSorters;
import org.mockito.Mockito;

/**
 * Test case for the conversational aspects of type DefaultRestServiceClientTest.
 * 
 * @author Erik Lotz
 * @since 2017-04-12
 * 
 */
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class DefaultRestServiceClientConversationTest {
	private DefaultRestServiceClient sut = Mockito.spy(DefaultRestServiceClient.class);;
	
	@Before
	public void setUp() {
		Client clientMock = Mockito.mock(Client.class);
		Mockito.doReturn(clientMock).when(sut).createRestClient();
	}

	@After
	public void tearDown() {
		if (sut.isConversationStarted()) {
			sut.closeConversation();
		}
	}
	
	@Test
	public void testIsConversationStarted_after_creation() {
		boolean result = sut.isConversationStarted();
		
		assertFalse("Conversation must not be started now!", result);
	}
	
	@Test
	public void testOpenConversation_success() {
		sut.openConversation();
		
		boolean result = sut.isConversationStarted();
		
		assertTrue("Conversation must be started now!", result);
	}
	
	@Test(expected=IllegalStateException.class)
	public void testOpenConversation_when_it_has_been_already_openened() {
		sut.openConversation();
		
		sut.openConversation();
	}
	
	@Test
	public void testCloseConversation_success() {
		sut.openConversation();
		
		sut.closeConversation();
		
		boolean result = sut.isConversationStarted();
		assertFalse("Conversation must not be started now!", result);
	}
	
	@Test(expected=IllegalStateException.class)
	public void testCloseConversation_without_opening_it_before() {
		sut.closeConversation();
	}
}

@@ -479,16 +479,19 @@
 ient sut
+Spy
  = Mocki
@@ -654,16 +654,19 @@
 when(sut
+Spy
 ).create
@@ -726,16 +726,19 @@
 %09if (sut
+Spy
 .isConve
@@ -759,24 +759,27 @@
 ()) %7B%0A%09%09%09sut
+Spy
 .closeConver
@@ -876,32 +876,35 @@
 ean result = sut
+Spy
 .isConversationS
@@ -1035,32 +1035,35 @@
 uccess() %7B%0A%09%09sut
+Spy
 .openConversatio
@@ -1084,32 +1084,35 @@
 ean result = sut
+Spy
 .isConversationS
@@ -1302,32 +1302,35 @@
 enened() %7B%0A%09%09sut
+Spy
 .openConversatio
@@ -1338,24 +1338,27 @@
 ();%0A%09%09%0A%09%09sut
+Spy
 .openConvers
@@ -1430,16 +1430,19 @@
  %7B%0A%09%09sut
+Spy
 .openCon
@@ -1458,24 +1458,27 @@
 ();%0A%09%09%0A%09%09sut
+Spy
 .closeConver
@@ -1512,16 +1512,19 @@
 lt = sut
+Spy
 .isConve
@@ -1725,16 +1725,19 @@
  %7B%0A%09%09sut
+Spy
 .closeCo

Clean Code. Improve variable name.