### Question:
ArtemisBrokerManager { public void createAddress(String name, ArtemisCommonProperties properties) { logger.debug("Creating address '{}'", name); SimpleString nameString = SimpleString.toSimpleString(name); try (ClientSessionFactory sessionFactory = serverLocator.createSessionFactory(); ClientSession session = getClientSession(sessionFactory)) { session.start(); if (!session.addressQuery(nameString).isExists()) { session.createAddress(nameString, RoutingType.MULTICAST, true); if (properties.isModifyAddressSettings()) { configureAddress(session, name, properties); } } else { logger.debug("Address '{}' already exists, ignoring", name); } session.stop(); } catch (Exception e) { throw new ProvisioningException(String.format("Failed to create address '%s'", name), e); } } ArtemisBrokerManager(ServerLocator serverLocator, String username, String password); void createAddress(String name, ArtemisCommonProperties properties); void createQueue(String address, String name);  }### Answer:
@Test public void shouldCreateAddress() throws Exception { ArtemisBrokerManager manager = new ArtemisBrokerManager(mockServerLocator, null, null); manager.createAddress(address.toString(), artemisCommonProperties); verify(mockServerLocator).createSessionFactory(); verify(mockClientSessionFactory).createSession(); verify(mockClientSession).start(); verify(mockClientSession).createAddress(address, MULTICAST, true); verify(mockClientSession).stop(); verify(mockClientSession, times(0)).queueQuery(any(SimpleString.class)); verify(mockClientSession, times(0)).createMessage(anyBoolean()); }
@Test public void shouldCreateAddressWithCredentials() throws Exception { given(mockServerLocator.isPreAcknowledge()).willReturn(true); given(mockServerLocator.getAckBatchSize()).willReturn(1); ArtemisBrokerManager manager = new ArtemisBrokerManager(mockServerLocator, "user", "pass"); manager.createAddress(address.toString(), artemisCommonProperties); verify(mockServerLocator).createSessionFactory(); verify(mockClientSessionFactory).createSession("user", "pass", true, false, false, true, 1); verify(mockClientSession).start(); verify(mockClientSession).createAddress(address, MULTICAST, true); verify(mockClientSession).stop(); verify(mockClientSession, times(0)).queueQuery(any(SimpleString.class)); verify(mockClientSession, times(0)).createMessage(anyBoolean()); }
@Test public void shouldNotCreateAddressIfOneExists() throws Exception { given(mockAddressQuery.isExists()).willReturn(true); ArtemisBrokerManager manager = new ArtemisBrokerManager(mockServerLocator, null, null); manager.createAddress(address.toString(), artemisCommonProperties); verify(mockServerLocator).createSessionFactory(); verify(mockClientSessionFactory).createSession(); verify(mockClientSession).start(); verify(mockClientSession).stop(); verify(mockClientSession, times(0)).createAddress(any(), any(RoutingType.class), anyBoolean()); verify(mockClientSession, times(0)).queueQuery(any(SimpleString.class)); verify(mockClientSession, times(0)).createMessage(anyBoolean()); }
@Test public void shouldFailToCreateAddress() throws Exception { given(mockServerLocator.createSessionFactory()).willThrow(new RuntimeException("test")); ArtemisBrokerManager manager = new ArtemisBrokerManager(mockServerLocator, null, null); try { manager.createAddress(address.toString(), artemisCommonProperties); fail("Provisioning exception was expected"); } catch (ProvisioningException e) { String message = String.format("Failed to create address '%s'", address); assertThat(e.getMessage()).contains(message); } }