package org.sagebionetworks.web.unitclient;

import static org.junit.Assert.*;
import static org.mockito.Matchers.*;
import static org.mockito.Mockito.*;

import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.sagebionetworks.web.client.ClientLoggerImpl;
import org.sagebionetworks.web.client.SynapseClientAsync;
import org.sagebionetworks.web.shared.exceptions.ConflictException;

import com.google.gwt.user.client.rpc.AsyncCallback;


public class ClientLoggerImplTest {

	ClientLoggerImpl clientLogger;
	SynapseClientAsync mockSynapseClient;
	
	@Before
	public void setUp() throws Exception {
		mockSynapseClient = mock(SynapseClientAsync.class);
		clientLogger = new ClientLoggerImpl(mockSynapseClient);
	}
//
//	@Test
//	public void testErrorToRepositoryServices() {
//		String exceptionMessage = "syn1234";
//		ConflictException e = new ConflictException(exceptionMessage);
//		String errorMessage = "Unable to upload a file for some specific reason.";
//		clientLogger.errorToRepositoryServices(errorMessage, e);
//		
//		ArgumentCaptor<String> messageCaptor = ArgumentCaptor.forClass(String.class);
//		ArgumentCaptor<String> labelCaptor = ArgumentCaptor.forClass(String.class);
//		verify(mockSynapseClient).logErrorToRepositoryServices(messageCaptor.capture(), labelCaptor.capture(), any(AsyncCallback.class));
//		String message = messageCaptor.getValue();
//		String label = labelCaptor.getValue();
//		
//		//the label specific error info (found in the stack trace message)
//		assertFalse(label.contains(exceptionMessage));
//		//the message should contain the error message and stack trace message
//		assertTrue(message.contains(exceptionMessage));
//		assertTrue(message.contains(errorMessage));
//		assertTrue(label.contains(ConflictException.class.getName()));
//	}
//	
//	@Test
//	public void testErrorToRepositoryServicesNullException() {
//		String errorMessage = "Unable to upload a file for another specific reason.";
//		clientLogger.errorToRepositoryServices(errorMessage, null);
//		
//		ArgumentCaptor<String> messageCaptor = ArgumentCaptor.forClass(String.class);
//		ArgumentCaptor<String> labelCaptor = ArgumentCaptor.forClass(String.class);
//		verify(mockSynapseClient).logErrorToRepositoryServices(messageCaptor.capture(), labelCaptor.capture(), any(AsyncCallback.class));
//		String message = messageCaptor.getValue();
//		String label = labelCaptor.getValue();
//		
//		//the label should be empty
//		assertTrue(label != null && label.length() == 0);
//		//message should contain the error message
//		assertTrue(message.contains(errorMessage));
//	}

}

@@ -60,22 +60,28 @@
 org.
-junit.Assert.*
+mockito.Matchers.any
 ;%0Aim
@@ -113,17 +113,18 @@
 atchers.
-*
+eq
 ;%0Aimport
@@ -155,9 +155,54 @@
 ito.
-*
+mock;%0Aimport static org.mockito.Mockito.verify
 ;%0A%0Ai
@@ -252,43 +252,8 @@
 st;%0A
-import org.mockito.ArgumentCaptor;%0A
 impo
@@ -764,22 +764,16 @@
 %0A%09%7D%0A
-//%0A//
+%0A
 %09@Test%0A
-//
 %09pub
@@ -811,26 +811,24 @@
 ervices() %7B%0A
-//
 %09%09String exc
@@ -854,18 +854,16 @@
 n1234%22;%0A
-//
 %09%09Confli
@@ -919,18 +919,16 @@
 ssage);%0A
-//
 %09%09String
@@ -988,34 +988,32 @@
 cific reason.%22;%0A
-//
 %09%09clientLogger.e
@@ -1059,1575 +1059,162 @@
 e);%0A
-//
 %09%09%0A
-//%09%09ArgumentCaptor%3CString%3E messageCaptor = ArgumentCaptor.forClass(String.class);%0A//%09%09ArgumentCaptor%3CString%3E labelCaptor = ArgumentCaptor.forClass(String.class);%0A//%09%09verify(mockSynapseClient).logErrorToRepositoryServices(messageCaptor.capture(), labelCaptor.capture(), any(AsyncCallback.class));%0A//%09%09String message = messageCaptor.getValue();%0A//%09%09String label = labelCaptor.getValue();%0A//%09%09%0A//%09%09//the label specific error info (found in the stack trace message)%0A//%09%09assertFalse(label.contains(exceptionMessage));%0A//%09%09//the message should contain the error message and stack trace message%0A//%09%09assertTrue(message.contains(exceptionMessage));%0A//%09%09assertTrue(message.contains(errorMessage));%0A//%09%09assertTrue(label.contains(ConflictException.class.getName()));%0A//%09%7D%0A//%09%0A//%09@Test%0A//%09public void testErrorToRepositoryServicesNullException() %7B%0A//%09%09String errorMessage = %22Unable to upload a file for another specific reason.%22;%0A//%09%09clientLogger.errorToRepositoryServices(errorMessage, null);%0A//%09%09%0A//%09%09ArgumentCaptor%3CString%3E messageCaptor = ArgumentCaptor.forClass(String.class);%0A//%09%09ArgumentCaptor%3CString%3E labelCaptor = ArgumentCaptor.forClass(String.class);%0A//%09%09verify(mockSynapseClient).logErrorToRepositoryServices(messageCaptor.capture(), labelCaptor.capture(), any(AsyncCallback.class));%0A//%09%09String message = messageCaptor.getValue();%0A//%09%09String label = labelCaptor.getValue();%0A//%09%09%0A//%09%09//the label should be empty%0A//%09%09assertTrue(label != null && label.length() == 0);%0A//%09%09//message should contain the error message%0A//%09%09assertTrue(message.contains(errorMessage));%0A//%09%7D
+%09%09verify(mockSynapseClient).logErrorToRepositoryServices(eq(errorMessage), eq(exceptionMessage), eq(e.getStackTrace()), any(AsyncCallback.class));%0A%09%7D%0A%09
 %0A%0A%7D%0A

fix client logger test