ExecutorDao { Executor addExecutor(final String host, final int port) throws ExecutorManagerException { if (fetchExecutor(host, port) != null) { throw new ExecutorManagerException(String.format( "Executor %s:%d already exist", host, port)); } addExecutorHelper(host, port); return fetchExecutor(host, port); } @Inject  ExecutorDao(final DatabaseOperator dbOperator); Executor fetchExecutor(final String host, final int port); Executor fetchExecutor(final int executorId); void updateExecutor(final Executor executor);  }
@Test public void testDuplicateAddExecutor() throws Exception { final String host = "localhost"; final int port = 12345; this.executorDao.addExecutor(host, port); assertThatThrownBy(() -> this.executorDao.addExecutor(host, port)) .isInstanceOf(ExecutorManagerException.class) .hasMessageContaining("already exist"); }