mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
DS-3762: Added test for Context.close() in try-with-resources block
This commit is contained in:
@@ -270,6 +270,45 @@ public class ContextTest extends AbstractUnitTest
|
||||
cleanupContext(instance);
|
||||
cleanupContext(newInstance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of close method, of class Context.
|
||||
*/
|
||||
@Test
|
||||
public void testClose() throws SQLException, AuthorizeException
|
||||
{
|
||||
new NonStrictExpectations(authorizeService.getClass())
|
||||
{{
|
||||
// Allow Admin permissions - needed to create a new EPerson
|
||||
authorizeService.isAdmin((Context) any); result = true;
|
||||
}};
|
||||
|
||||
String createdEmail = "susie@email.com";
|
||||
|
||||
// To test close() we need a new Context object in a try-with-resources block
|
||||
try(Context instance = new Context()) {
|
||||
|
||||
// Create a new EPerson (DO NOT COMMIT IT)
|
||||
EPerson newUser = ePersonService.create(instance);
|
||||
newUser.setFirstName(context, "Susan");
|
||||
newUser.setLastName(context, "Doe");
|
||||
newUser.setEmail(createdEmail);
|
||||
newUser.setCanLogIn(true);
|
||||
newUser.setLanguage(context, I18nUtil.getDefaultLocale().getLanguage());
|
||||
|
||||
}
|
||||
|
||||
// Open a new context, let's make sure that EPerson isn't there
|
||||
Context newInstance = new Context();
|
||||
EPerson found = ePersonService.findByEmail(newInstance, createdEmail);
|
||||
assertThat("testClose 0", found, nullValue());
|
||||
|
||||
// Cleanup our contexts
|
||||
cleanupContext(newInstance);
|
||||
|
||||
//Calling close on a finished context should not result in errors
|
||||
newInstance.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of abort method, of class Context.
|
||||
|
Reference in New Issue
Block a user