diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceImplUnitTest.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceImplUnitTest.java index 5ce8e9da44..69e5d91b09 100644 --- a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceImplUnitTest.java +++ b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/classification/ClassificationServiceImplUnitTest.java @@ -23,9 +23,7 @@ import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; -import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -44,6 +42,9 @@ import org.apache.log4j.spi.LoggingEvent; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; /** * Unit tests for {@link ClassificationServiceImpl}. @@ -90,23 +91,18 @@ public class ClassificationServiceImplUnitTest return levels; } - private ClassificationServiceImpl classificationServiceImpl; + @InjectMocks private ClassificationServiceImpl classificationServiceImpl; - private AttributeService mockedAttributeService = mock(AttributeService.class); - private AuthenticationUtil mockedAuthenticationUtil; - private ClassificationServiceDAO mockClassificationServiceDAO = mock(ClassificationServiceDAO.class); + @Mock private AttributeService mockedAttributeService; + @Mock private AuthenticationUtil mockedAuthenticationUtil; + @Mock private ClassificationServiceDAO mockClassificationServiceDAO; /** Using a mock appender in the class logger so that we can verify some of the logging requirements. */ - private Appender mockAppender = mock(Appender.class); + @Mock private Appender mockAppender; @Before public void setUp() { - reset(mockClassificationServiceDAO, mockedAttributeService, mockAppender); - mockedAuthenticationUtil = MockAuthenticationUtilHelper.create(); - - classificationServiceImpl = new ClassificationServiceImpl(); - classificationServiceImpl.setAttributeService(mockedAttributeService); - classificationServiceImpl.setClassificationServiceDAO(mockClassificationServiceDAO); - classificationServiceImpl.setAuthenticationUtil(mockedAuthenticationUtil); + MockitoAnnotations.initMocks(this); + MockAuthenticationUtilHelper.setup(mockedAuthenticationUtil); } @Test public void defaultLevelsConfigurationVanillaSystem() diff --git a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/test/util/MockAuthenticationUtilHelper.java b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/test/util/MockAuthenticationUtilHelper.java index 0f934d248d..37a7045103 100644 --- a/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/test/util/MockAuthenticationUtilHelper.java +++ b/rm-server/unit-test/java/org/alfresco/module/org_alfresco_module_rm/test/util/MockAuthenticationUtilHelper.java @@ -23,7 +23,6 @@ import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; import org.alfresco.module.org_alfresco_module_rm.util.AuthenticationUtil; @@ -32,54 +31,20 @@ import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; /** - * A helper to create or initialise mock {@link AuthenticationUtil}s. + * A helper to initialise a mock {@link AuthenticationUtil}. * * @author tpage */ public class MockAuthenticationUtilHelper { - /** - * Create a Mockito mock AuthenticationUtil that executes all methods assuming the user has permission. - * If the mock is asked for details about the user then it assumes the user is "admin". - * - * @return The new mock. - */ - public static AuthenticationUtil create() - { - AuthenticationUtil mockAuthenticationUtil = mock(AuthenticationUtil.class); - - setup(mockAuthenticationUtil); - - return mockAuthenticationUtil; - } - - /** - * Create a Mockito mock AuthenticationUtil that executes all methods assuming the user has permission. - * - * @param adminUserName The name of the default admin user. - * @param fullyAuthenticatedUser The name of the user that last authenticated. - * @param systemUserName The name of the system user. - * @return The new mock. - */ - public static AuthenticationUtil create(String adminUserName, String fullyAuthenticatedUser, String systemUserName) - { - AuthenticationUtil mockAuthenticationUtil = mock(AuthenticationUtil.class); - - setup(mockAuthenticationUtil, adminUserName, fullyAuthenticatedUser, systemUserName); - - return mockAuthenticationUtil; - } - /** * Set up a Mockito mock AuthenticationUtil so that it executes all methods assuming the user has * permissions. If the mock is asked for details about the user then it assumes the user is "admin". - *

- * TODO: Change this method to private and this class to be a factory. * * @param mockAuthenticationUtil The mock to initialise. */ @SuppressWarnings("unchecked") - protected static void setup(AuthenticationUtil mockAuthenticationUtil) + public static void setup(AuthenticationUtil mockAuthenticationUtil) { setup(mockAuthenticationUtil, "admin", "admin", "admin"); } @@ -87,8 +52,6 @@ public class MockAuthenticationUtilHelper /** * Set up a Mockito mock AuthenticationUtil so that it executes all methods assuming the user has * permissions. - *

- * TODO: Change this method to private and this class to be a factory. * * @param mockAuthenticationUtil The mock to initialise. * @param adminUserName The name of the default admin user. @@ -96,7 +59,7 @@ public class MockAuthenticationUtilHelper * @param systemUserName The name of the system user. */ @SuppressWarnings("unchecked") - protected static void setup(AuthenticationUtil mockAuthenticationUtil, String adminUserName, + public static void setup(AuthenticationUtil mockAuthenticationUtil, String adminUserName, String fullyAuthenticatedUser, String systemUserName) { reset(mockAuthenticationUtil);