package org.sagebionetworks.web.unitclient.widget.entity.team;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.when;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import org.sagebionetworks.web.client.SynapseJavascriptClient;
import org.sagebionetworks.web.client.security.AuthenticationController;
import org.sagebionetworks.web.client.widget.entity.renderer.TeamMemberCountWidget;
import org.sagebionetworks.web.client.widget.team.BigTeamBadge;
import org.sagebionetworks.web.client.widget.team.BigTeamBadgeView;

@RunWith(MockitoJUnitRunner.class)
public class BigTeamBadgeTest {
	@Mock
	AuthenticationController mockAuthenticationController;
	@Mock
	BigTeamBadgeView mockView;
	@Mock
	SynapseJavascriptClient mockJsClient;
	@Mock
	TeamMemberCountWidget mockTeamMemberCountWidget;

	BigTeamBadge presenter;

	@Before
	public void setUp() throws Exception {
		presenter = new BigTeamBadge(mockView, mockJsClient, mockAuthenticationController, mockTeamMemberCountWidget);
	}

	@Test
	public void testGetTeamEmail() {
		boolean canSendEmail = true;
		when(mockAuthenticationController.isLoggedIn()).thenReturn(true);
		assertEquals("basic@synapse.org", presenter.getTeamEmail("basic", canSendEmail));
		assertEquals("StandardCaseHere@synapse.org", presenter.getTeamEmail("Standard Case Here", canSendEmail));
		assertEquals("unlikelycase@synapse.org", presenter.getTeamEmail(" \n\r unlikely\t case ", canSendEmail));
		assertEquals("Another_UnlikelyCase@synapse.org", presenter.getTeamEmail(" %^$##* Another_Unlikely\t &*#$)(!!@~Case ", canSendEmail));

		canSendEmail = false;
		assertEquals("", presenter.getTeamEmail("basic", canSendEmail));

		canSendEmail = true;
		when(mockAuthenticationController.isLoggedIn()).thenReturn(false);
		assertEquals("", presenter.getTeamEmail("basic", canSendEmail));
	}

}

@@ -102,16 +102,102 @@
 Equals;%0A
+import static org.mockito.Matchers.any;%0Aimport static org.mockito.Matchers.anyString;%0A
 import s
@@ -377,24 +377,80 @@
 UnitRunner;%0A
+import org.sagebionetworks.web.client.SynapseJSNIUtils;%0A
 import org.s
@@ -788,16 +788,130 @@
 dgeView;
+%0Aimport org.sagebionetworks.web.test.helper.AsyncMockStubber;%0Aimport com.google.gwt.user.client.rpc.AsyncCallback;
 %0A%0A@RunWi
@@ -1122,16 +1122,56 @@
 %0A%09@Mock%0A
+%09SynapseJSNIUtils mockJsniUtils;%0A%09@Mock%0A
 %09TeamMem
@@ -1238,16 +1238,85 @@
 senter;%0A
+%09public static final String TEAM_ICON_URL = %22http://team.icon.png%22;%0A%09
 %0A%09@Befor
@@ -1411,16 +1411,31 @@
 sClient,
+ mockJsniUtils,
  mockAut
@@ -1485,16 +1485,150 @@
 idget);%0A
+%09%09AsyncMockStubber.callSuccessWith(TEAM_ICON_URL).when(mockJsClient).getTeamPicturePreviewURL(anyString(), any(AsyncCallback.class));%0A
 %09%7D%0A%0A%09@Te

fix existing tests