try {
AdminCommandSupport mockCommand = EasyMock.createStrictMock(AdminCommandSupport.class);
mockCommand.setAdminService((AdminService) EasyMock.anyObject());
EasyMock.expectLastCall().andAnswer(new IAnswer<Object>() {
public Object answer() throws Throwable {
AdminServiceImpl svc = (AdminServiceImpl) EasyMock.getCurrentArguments()[0];
assertEquals(tempFile, svc.getStorageLocation());
admins.add(svc);
return null;
}
});
EasyMock.expect(mockCommand.execute(null)).andAnswer(new IAnswer<Object>() {
public Object answer() throws Throwable {
// The Admin Service should be initialized at this point.
// One way to find this out is by reading out the port number
AdminServiceImpl admin = admins.get(0);
Field sshField = AdminServiceImpl.class.getDeclaredField("defaultSshPortStart");
sshField.setAccessible(true);
assertEquals(1302, sshField.get(admin));
Field rmiRegistryField = AdminServiceImpl.class.getDeclaredField("defaultRmiRegistryPortStart");
rmiRegistryField.setAccessible(true);