DiskSpaceCheckerBuilder { @SuppressWarnings("unchecked") public DiskSpaceChecker build() throws ClassNotFoundException, DiskSpaceCheckerException { final DiskSpaceChecker checker; switch (configuration.getCheckerType()) { case DiskSpaceConfiguration.ELASTICSEARCH_CHECKER: checker = buildElasticsearchChecker(environment); break; case DiskSpaceConfiguration.SOLR_LOCAL_CHECKER: checker = new SolrDiskSpaceChecker(); break; case DiskSpaceConfiguration.CLUSTER_CHECKER: checker = buildClusterChecker(environment, (List<String>) configuration.getConfiguration().get(ClusterDiskSpaceChecker.CLUSTER_SERVERS_CONFIG_OPTION)); break; default: checker = buildCustomChecker(configuration.getCheckerType()); } if (checker != null) { checker.configure(configuration.getConfiguration()); checker.setThreshold(DiskSpaceThreshold.parse(configuration.getThreshold())); if (checker.requiresHttpClient()) { checker.setHttpClient(client); } } return checker; } DiskSpaceCheckerBuilder(Environment environment, Client client, DiskSpaceConfiguration configuration); @SuppressWarnings("unchecked") DiskSpaceChecker build();  }
@Test public void buildsESChecker() throws Exception { configuration.setCheckerType(DiskSpaceConfiguration.ELASTICSEARCH_CHECKER); configuration.getConfiguration().put(ElasticsearchDiskSpaceChecker.CACHE_MS_CONFIG_OPTION, 5000); DiskSpaceChecker checker = builder.build(); assertThat(checker).isNotNull(); assertThat(checker).isInstanceOf(ElasticsearchDiskSpaceChecker.class); verify(healthChecks).register(isA(String.class), isA(ElasticsearchClientHealthCheck.class)); }
@Test public void buildsSolrChecker() throws Exception { configuration.setCheckerType(DiskSpaceConfiguration.SOLR_LOCAL_CHECKER); configuration.getConfiguration().put(SolrDiskSpaceChecker.DATA_DIR_CONFIG_OPTION, "/"); DiskSpaceChecker checker = builder.build(); assertThat(checker).isNotNull(); assertThat(checker).isInstanceOf(SolrDiskSpaceChecker.class); }
@Test(expected=java.lang.ClassNotFoundException.class) public void throwsClassNotFoundException() throws Exception { configuration.setCheckerType("uk.co.flax.NoSuchDiskSpaceChecker"); builder.build(); }
@Test(expected=uk.co.flax.harahachibu.services.DiskSpaceCheckerException.class) public void throwsExceptionWhenNoArgConstructorNotAvailable() throws Exception { configuration.setCheckerType("uk.co.flax.harahachibu.services.TestArgsDiskSpaceChecker"); builder.build(); }
@Test public void buildsCustomChecker() throws Exception { configuration.setCheckerType("uk.co.flax.harahachibu.services.TestDiskSpaceChecker"); DiskSpaceChecker checker = builder.build(); assertThat(checker).isNotNull(); assertThat(checker).isInstanceOf(TestDiskSpaceChecker.class); }