ExecutorDao { public Executor fetchExecutor(final String host, final int port) throws ExecutorManagerException { try { final List<Executor> executors = this.dbOperator.query(FetchExecutorHandler.FETCH_EXECUTOR_BY_HOST_PORT, new FetchExecutorHandler(), host, port); if (executors.isEmpty()) { return null; } else { return executors.get(0); } } catch (final SQLException e) { throw new ExecutorManagerException(String.format( "Error fetching executor %s:%d", host, port), e); } } @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 testFetchMissingExecutorId() throws Exception { final Executor executor = this.executorDao.fetchExecutor(0); assertThat(executor).isEqualTo(null); }
@Test public void testFetchMissingExecutorHostPort() throws Exception { final Executor executor = this.executorDao.fetchExecutor("localhost", 12345); assertThat(executor).isEqualTo(null); }
@Test public void testSingleExecutorFetchById() throws Exception { final List<Executor> executors = addTestExecutors(); for (final Executor executor : executors) { final Executor fetchedExecutor = this.executorDao.fetchExecutor(executor.getId()); assertThat(executor).isEqualTo(fetchedExecutor); } }
@Test public void testSingleExecutorFetchHostPort() throws Exception { final List<Executor> executors = addTestExecutors(); for (final Executor executor : executors) { final Executor fetchedExecutor = this.executorDao.fetchExecutor(executor.getHost(), executor.getPort()); assertThat(executor).isEqualTo(fetchedExecutor); } }