Publisher { public boolean connect(String uri, String exchange, String exchangeType) { assertIsSupportedExchangeType(exchangeType); this.uri = uri; this.exchange = exchange; try { factory.setUri(uri); } catch (URISyntaxException e) { e.printStackTrace(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } catch (KeyManagementException e) { e.printStackTrace(); } try { Log.info("Connect to publish/subscribe server: " + toString()); connection = factory.newConnection(); channel = connection.createChannel(); channel.exchangeDeclare(exchange, exchangeType,true); } catch (IOException | TimeoutException e) { Log.error("Unable to connect to publish/subscribe server: " + toString()); e.printStackTrace(); return false; } return true; } @Inject  Publisher(ConnectionFactory factory); boolean connect(String uri, String exchange, String exchangeType); boolean publish(String message); boolean publish(String message, String routingKey); void close(); String toString();  }
@Test(expected = IllegalArgumentException.class) public void testExchangeType_DIRECT () { publisher.connect(URI, EXCHANGE, BuiltinExchangeType.DIRECT.getType()); }
@Test(expected = IllegalArgumentException.class) public void testExchangeType_HEADERS () { publisher.connect(URI, EXCHANGE, BuiltinExchangeType.HEADERS.getType()); }