@Test public void getEncryptedPassword_BasicTest() throws Exception { final TGTService tgtService = context.mock(TGTService.class); final BlockStorageUtilSvc blockStorageUtilSvc = context.mock(BlockStorageUtilSvc.class); context.checking( new Expectations() { { oneOf(blockStorageUtilSvc).decryptSCTargetPassword("foo"); will(returnValue("foo")); oneOf(blockStorageUtilSvc).getPartitionForLocalService(Storage.class); will(returnValue(null)); oneOf(blockStorageUtilSvc).encryptNodeTargetPassword("foo", null); will(returnValue("foo")); } }); try (TransactionResource tran = Entities.transactionFor(CHAPUserInfo.class)) { Entities.persist(new CHAPUserInfo("eucalyptus", "foo")); tran.commit(); } ISCSIManager iscsiManager = new ISCSIManager(tgtService, blockStorageUtilSvc); String foo = iscsiManager.getEncryptedPassword(); assertTrue("expected result to be 'foo' but was - " + foo, foo != null && "foo".equals(foo)); }