mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-07-31 17:39:05 +00:00
Use mock in unit test for ClearanceLevelManager.
Although I'm not sure exactly why this unit test failed on the Sonar build, it seems sensible to remove the dependency on another class by using a mock. +review RM git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/modules/recordsmanagement/HEAD@105192 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -71,6 +71,8 @@ public class ClassificationServiceBootstrap extends AbstractLifecycleBean implem
|
|||||||
/** Set the object from which configuration options will be read. */
|
/** Set the object from which configuration options will be read. */
|
||||||
public void setClassificationServiceDAO(ClassificationServiceDAO classificationServiceDAO) { this.classificationServiceDAO = classificationServiceDAO; }
|
public void setClassificationServiceDAO(ClassificationServiceDAO classificationServiceDAO) { this.classificationServiceDAO = classificationServiceDAO; }
|
||||||
public void setAttributeService(AttributeService attributeService) { this.attributeService = attributeService; }
|
public void setAttributeService(AttributeService attributeService) { this.attributeService = attributeService; }
|
||||||
|
/** Used in unit tests. */
|
||||||
|
protected void setClearanceLevelManager(ClearanceLevelManager clearanceLevelManager) { this.clearanceLevelManager = clearanceLevelManager; }
|
||||||
|
|
||||||
public ClassificationLevelManager getClassificationLevelManager() { return classificationLevelManager; }
|
public ClassificationLevelManager getClassificationLevelManager() { return classificationLevelManager; }
|
||||||
public ClassificationReasonManager getClassificationReasonManager() { return classificationReasonManager; }
|
public ClassificationReasonManager getClassificationReasonManager() { return classificationReasonManager; }
|
||||||
|
@@ -24,6 +24,7 @@ import static org.junit.Assert.assertTrue;
|
|||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Matchers.anyString;
|
import static org.mockito.Matchers.anyString;
|
||||||
import static org.mockito.Matchers.eq;
|
import static org.mockito.Matchers.eq;
|
||||||
|
import static org.mockito.Mockito.doNothing;
|
||||||
import static org.mockito.Mockito.never;
|
import static org.mockito.Mockito.never;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
@@ -98,14 +99,18 @@ public class ClassificationServiceBootstrapUnitTest
|
|||||||
@Mock ClassificationServiceDAO mockClassificationServiceDAO;
|
@Mock ClassificationServiceDAO mockClassificationServiceDAO;
|
||||||
@Mock AttributeService mockAttributeService;
|
@Mock AttributeService mockAttributeService;
|
||||||
@Mock AuthenticationUtil mockAuthenticationUtil;
|
@Mock AuthenticationUtil mockAuthenticationUtil;
|
||||||
|
@Mock ClearanceLevelManager mockClearanceLevelManager;
|
||||||
/** Using a mock appender in the class logger so that we can verify some of the logging requirements. */
|
/** Using a mock appender in the class logger so that we can verify some of the logging requirements. */
|
||||||
@Mock Appender mockAppender;
|
@Mock Appender mockAppender;
|
||||||
@Captor ArgumentCaptor<LoggingEvent> loggingEventCaptor;
|
@Captor ArgumentCaptor<LoggingEvent> loggingEventCaptor;
|
||||||
|
@Captor ArgumentCaptor<List<ClearanceLevel>> clearanceLevelCaptor;
|
||||||
|
|
||||||
@Before public void setUp()
|
@Before public void setUp()
|
||||||
{
|
{
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
MockAuthenticationUtilHelper.setup(mockAuthenticationUtil);
|
MockAuthenticationUtilHelper.setup(mockAuthenticationUtil);
|
||||||
|
// This seems to be necessary because the ClearanceLevelManager isn't a constructor argument.
|
||||||
|
classificationServiceBootstrap.setClearanceLevelManager(mockClearanceLevelManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test public void defaultLevelsConfigurationVanillaSystem()
|
@Test public void defaultLevelsConfigurationVanillaSystem()
|
||||||
@@ -223,11 +228,12 @@ public class ClassificationServiceBootstrapUnitTest
|
|||||||
ClassificationLevel topSecret = new ClassificationLevel("1", "TopSecret");
|
ClassificationLevel topSecret = new ClassificationLevel("1", "TopSecret");
|
||||||
ClassificationLevel secret = new ClassificationLevel("2", "Secret");
|
ClassificationLevel secret = new ClassificationLevel("2", "Secret");
|
||||||
ImmutableList<ClassificationLevel> classificationLevels = ImmutableList.of(topSecret, secret, ClassificationLevelManager.UNCLASSIFIED);
|
ImmutableList<ClassificationLevel> classificationLevels = ImmutableList.of(topSecret, secret, ClassificationLevelManager.UNCLASSIFIED);
|
||||||
|
doNothing().when(mockClearanceLevelManager).setClearanceLevels(clearanceLevelCaptor.capture());
|
||||||
|
|
||||||
// Call the method under test.
|
// Call the method under test.
|
||||||
classificationServiceBootstrap.initConfiguredClearanceLevels(classificationLevels);
|
classificationServiceBootstrap.initConfiguredClearanceLevels(classificationLevels);
|
||||||
|
|
||||||
List<ClearanceLevel> clearanceLevels = classificationServiceBootstrap.getClearanceLevelManager().getClearanceLevels();
|
List<ClearanceLevel> clearanceLevels = clearanceLevelCaptor.getValue();
|
||||||
assertEquals("There should be one clearance level for each classification level.", classificationLevels.size(), clearanceLevels.size());
|
assertEquals("There should be one clearance level for each classification level.", classificationLevels.size(), clearanceLevels.size());
|
||||||
assertEquals("TopSecret", clearanceLevels.get(0).getDisplayLabel());
|
assertEquals("TopSecret", clearanceLevels.get(0).getDisplayLabel());
|
||||||
assertEquals("Secret", clearanceLevels.get(1).getDisplayLabel());
|
assertEquals("Secret", clearanceLevels.get(1).getDisplayLabel());
|
||||||
|
Reference in New Issue
Block a user