ContentStoreFactory { public ContentStore create(DuracloudCredentialsForm dcf) throws ContentStoreException { return create(dcf, true); }  ContentStore create(DuracloudCredentialsForm dcf); ContentStore create(DuracloudCredentialsForm dcf, boolean retry);  }
@Test public void testCreate() throws ContentStoreException { final ContentStoreManager csm = EasyMock.createMock(ContentStoreManager.class); ContentStore cs = EasyMock.createMock(ContentStore.class); csm.login(EasyMock.isA(Credential.class)); EasyMock.expectLastCall().once(); EasyMock.expect(csm.getPrimaryContentStore()).andReturn(cs); ContentStoreFactory csf = new ContentStoreFactory() { @Override protected ContentStoreManager createContentStoreManager(String host, String port) { return csm; } }; EasyMock.replay(csm, cs); DuracloudCredentialsForm dcf = new DuracloudCredentialsForm(); dcf.setHost("test"); dcf.setUsername("username"); dcf.setPassword("password"); Assert.assertNotNull(csf.create(dcf)); EasyMock.verify(csm, cs); }
@Test public void testCreateFailure() throws ContentStoreException { final ContentStoreManager csm = EasyMock.createMock(ContentStoreManager.class); ContentStore cs = EasyMock.createMock(ContentStore.class); csm.login(EasyMock.isA(Credential.class)); EasyMock.expectLastCall().once(); EasyMock.expect(csm.getPrimaryContentStore()) .andThrow(new ContentStoreException("test exception")); ContentStoreFactory csf = new ContentStoreFactory() { @Override protected ContentStoreManager createContentStoreManager(String host, String port) { return csm; } }; EasyMock.replay(csm, cs); DuracloudCredentialsForm dcf = new DuracloudCredentialsForm(); dcf.setHost("test"); dcf.setUsername("username"); dcf.setPassword("password"); try { csf.create(dcf); Assert.assertTrue(false); } catch (ContentStoreException ex) { Assert.assertTrue(true); } EasyMock.verify(csm, cs); }