Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Refactor test for notnull parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng authored and seanf committed Oct 1, 2013
1 parent dac3f53 commit 6afeb23
Showing 1 changed file with 15 additions and 11 deletions.
Expand Up @@ -5,6 +5,8 @@
import java.util.List;
import java.util.Map;

import javax.validation.constraints.NotNull;

import org.hamcrest.Matchers;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
Expand Down Expand Up @@ -62,7 +64,7 @@ public class GetTranslationHistoryHandlerTest

private GetTranslationHistoryAction action;
private TransUnitId transUnitId = new TransUnitId(1L);
@Mock
@Mock
private HLocale hLocale;
private LocaleId localeId = new LocaleId("en-US");
@Mock
Expand Down Expand Up @@ -100,7 +102,7 @@ public void invalidLocaleWillThrowException() throws ActionException
// Then:
verify(identity).checkLoggedIn();
}

@Test
public void canGetEmptyHistoryForTextFlowWithNoTranslation() throws ActionException
{
Expand Down Expand Up @@ -129,8 +131,8 @@ public void canGetHistoryAndCurrentTranslation() throws ActionException
HTextFlow hTextFlow = createHTextFlow();
// two history items
HashMap<Integer, HTextFlowTargetHistory> history = Maps.newHashMap();
history.put(0, createHistory(createTarget(new Date(), "smith", 0, null)));
history.put(1, createHistory(createTarget(new Date(), "john", 1, null)));
history.put(0, createHistory(createTarget(new Date(), "smith", 0, Maps.<Integer, HTextFlowTargetHistory>newHashMap())));
history.put(1, createHistory(createTarget(new Date(), "john", 1, Maps.<Integer, HTextFlowTargetHistory>newHashMap())));
HTextFlowTarget currentTranslation = createTarget(new Date(), "admin", 2, history);
hTextFlow.getTargets().put(hLocale.getId(), currentTranslation);

Expand All @@ -155,7 +157,9 @@ public void canGetCurrentTranslationWithoutLastModifiedBy() throws ActionExcepti
when(localeService.validateLocaleByProjectIteration(localeId, "rhel", "7.0")).thenReturn(hLocale);
when(hLocale.getId()).thenReturn(2L);
HTextFlow hTextFlow = createHTextFlow();
HTextFlowTarget currentTranslation = createTarget(new Date(), null, 0, null);
HTextFlowTarget currentTranslation =
createTarget(new Date(), null, 0,
new HashMap<Integer, HTextFlowTargetHistory>());
currentTranslation.setLastModifiedBy(null);
hTextFlow.getTargets().put(hLocale.getId(), currentTranslation);

Expand All @@ -180,7 +184,9 @@ public void canStripObsoleteTargetContentBasedOnCurrentNPlural() throws ActionEx
when(localeService.validateLocaleByProjectIteration(localeId, "rhel", "7.0")).thenReturn(hLocale);
when(hLocale.getId()).thenReturn(2L);
HTextFlow hTextFlow = createHTextFlow();
HTextFlowTarget currentTranslation = createTarget(new Date(), null, 0, null);
HTextFlowTarget currentTranslation =
createTarget(new Date(), null, 0,
new HashMap<Integer, HTextFlowTargetHistory>());
currentTranslation.setLastModifiedBy(null);
hTextFlow.getTargets().put(hLocale.getId(), currentTranslation);

Expand All @@ -206,18 +212,16 @@ private static HTextFlow createHTextFlow()
return hTextFlow;
}

private static HTextFlowTarget createTarget(Date lastChanged, String lastModifiedPerson, Integer versionNum, Map<Integer, HTextFlowTargetHistory> historyMap)
private static HTextFlowTarget createTarget(Date lastChanged,
String lastModifiedPerson, Integer versionNum,
@NotNull Map<Integer, HTextFlowTargetHistory> historyMap)
{
HTextFlowTarget target = new HTextFlowTarget();
target.setLastChanged(lastChanged);
HPerson person = new HPerson();
person.setName(lastModifiedPerson);
target.setLastModifiedBy(person);
target.setVersionNum(versionNum);
if(historyMap == null)
{
historyMap = Maps.newHashMap();
}
target.setHistory(historyMap);
target.setContents("a", "b");
return target;
Expand Down

0 comments on commit 6afeb23

Please sign in to comment.