### Question:
ArtemisBrokerManager { public void createQueue(String address, String name) { try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { createQueueInternal(session, address, name); } catch (ProvisioningException e) { throw e; } catch (Exception e) { throw new ProvisioningException( String.format("Failed to create queue '%s' with address '%s'", name, address), e); } } ArtemisBrokerManager(ServerLocator serverLocator, String username, String password); void createAddress(String name, ArtemisCommonProperties properties); void createQueue(String address, String name);  }### Answer:
@Test public void shouldCreateQueue() throws Exception { ArtemisBrokerManager manager = new ArtemisBrokerManager(mockServerLocator, null, null); manager.createQueue(address.toString(), queue.toString()); verify(mockServerLocator).createSessionFactory(); verify(mockClientSessionFactory).createSession(); verify(mockClientSession).createSharedQueue(address, MULTICAST, queue, true); }
@Test public void shouldCreateQueueWithCredentials() throws Exception { given(mockServerLocator.isPreAcknowledge()).willReturn(true); given(mockServerLocator.getAckBatchSize()).willReturn(1); ArtemisBrokerManager manager = new ArtemisBrokerManager(mockServerLocator, "user", "pass"); manager.createQueue(address.toString(), queue.toString()); verify(mockServerLocator).createSessionFactory(); verify(mockClientSessionFactory).createSession("user", "pass", true, false, false, true, 1); verify(mockClientSession).createSharedQueue(address, MULTICAST, queue, true); }
@Test public void shouldNotCreateQueueIfOneAlreadyExists() throws Exception { given(mockQueueQuery.getAddress()).willReturn(address); given(mockQueueQuery.isExists()).willReturn(true); ArtemisBrokerManager manager = new ArtemisBrokerManager(mockServerLocator, null, null); manager.createQueue(address.toString(), queue.toString()); verify(mockServerLocator).createSessionFactory(); verify(mockClientSessionFactory).createSession(); verify(mockClientSession, times(0)).createSharedQueue(any(), any(RoutingType.class), any(), anyBoolean()); }
@Test public void shouldFailToCreateQueue() throws Exception { given(mockServerLocator.createSessionFactory()).willThrow(new RuntimeException("test")); ArtemisBrokerManager manager = new ArtemisBrokerManager(mockServerLocator, null, null); try { manager.createQueue(address.toString(), queue.toString()); fail("Provisioning exception was expected"); } catch (ProvisioningException e) { String message = String.format("Failed to create queue '%s' with address '%s'", queue, address); assertThat(e.getMessage()).contains(message); } }
@Test public void shouldFailToCreateQueueIfOneAlreadyExistsUnderAnotherAddress() { SimpleString anotherAddress = toSimpleString("another-address-name"); given(mockQueueQuery.getAddress()).willReturn(anotherAddress); given(mockQueueQuery.isExists()).willReturn(true); ArtemisBrokerManager manager = new ArtemisBrokerManager(mockServerLocator, null, null); try { manager.createQueue(address.toString(), queue.toString()); fail("Provisioning exception was expected"); } catch (ProvisioningException e) { String message = String.format( "Failed to create queue '%s' with address '%s'. Queue already exists under another address '%s'", queue, address, anotherAddress); assertThat(e.getMessage()).contains(message); } }