Created
March 6, 2012 22:13
-
-
Save thecarlhall/1989349 to your computer and use it in GitHub Desktop.
Unit Test Mocks for JCR, Sparse Sessions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private javax.jcr.Session jcrSession; | |
private org.sakaiproject.nakamura.api.lite.Repository repository; | |
private org.sakaiproject.nakamura.api.lite.Session session; | |
// Create an in-memory repository to work with | |
repository = new BaseMemoryRepository().getRepository(); | |
// mock a jcr session but also include SessionAdaptable for easier mocking to a sparse session | |
jcrSession = mock(javax.jcr.Session.class, Mockito.withSettings().extraInterfaces(SessionAdaptable.class)); | |
// mock the session to return the sparse session | |
repository.loginAdministrative().getAuthorizableManager().createUser("someUser"); | |
session = repository.loginAdministrative("someUser"); | |
Mockito.when(((SessionAdaptable) jcrSession).getSession()).thenReturn(session); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment