@Test
  public void test_run_no_temporary_blocks() throws Exception {
    when(accessControlListDao.getTemporaryBlocks(now))
        .thenReturn(Collections.<BlockEvents>emptyList());

    subject.run();

    verify(accessControlListDao, never())
        .savePermanentBlock(anyString(), any(LocalDate.class), anyInt(), anyString());
  }
  @Test
  public void test_run_temporary_blocks_already_denied() throws Exception {
    when(accessControlListDao.getTemporaryBlocks(now.minusDays(30)))
        .thenReturn(Arrays.asList(createBlockEvents(IPV4_PREFIX, 20)));
    when(ipResourceConfiguration.isDenied(any(InetAddress.class))).thenReturn(true);

    subject.run();

    verify(ipResourceConfiguration).isDenied(any(InetAddress.class));
    verify(accessControlListDao, never())
        .savePermanentBlock(anyString(), any(LocalDate.class), anyInt(), anyString());
  }
  private void test_run_temporary_block(final int times, String prefix) {
    when(accessControlListDao.getTemporaryBlocks(now.minusDays(30)))
        .thenReturn(Arrays.asList(createBlockEvents(prefix, times)));

    subject.run();

    if (times < 10) {
      verify(accessControlListDao, never())
          .savePermanentBlock(anyString(), any(LocalDate.class), anyInt(), anyString());
    } else {
      verify(accessControlListDao)
          .savePermanentBlock(
              eq(prefix),
              any(LocalDate.class),
              eq(QUERY_LIMIT),
              eq(
                  "Automatic permanent ban after "
                      + times
                      + " temporary blocks at "
                      + FormatHelper.dateToString(now)));
    }
  }