public LithoViewAssert containsTestKey(String testKey, OccurrenceCount count) { final Deque<TestItem> testItems = LithoViewTestHelper.findTestItems(actual, testKey); Java6Assertions.assertThat(testItems) .hasSize(count.times) .overridingErrorMessage( "Expected to find test key <%s> in LithoView <%s> %s, but %s.", testKey, actual, count, testItems.isEmpty() ? "couldn't find it" : String.format(Locale.ROOT, "saw it %d times instead", testItems.size())) .isNotNull(); return this; }
@Test public void loadFactoriesWithVertxClassloader() throws Exception { // This test is a bit more tricky as we need to load the ServiceHelper class from a custom classloader. ClassLoader custom = new URLClassLoader(new URL[]{ new File("target/classes").toURI().toURL(), new File("target/test-classes").toURI().toURL(), new File("target/externals").toURI().toURL(), }, null); Class serviceHelperClass = custom.loadClass(ServiceHelper.class.getName()); Class someFactoryClass = custom.loadClass(SomeFactory.class.getName()); assertThat(serviceHelperClass.getClassLoader()).isEqualTo(custom); assertThat(someFactoryClass.getClassLoader()).isEqualTo(custom); Method method = serviceHelperClass.getMethod("loadFactories", Class.class); Collection collection = (Collection) method.invoke(null, someFactoryClass); assertThat(collection).hasSize(1); }
@Test public void loadFactoriesWithClassloader() throws Exception { ClassLoader custom = new URLClassLoader(new URL[]{new File("target/externals").toURI().toURL()}); // Try without the custom classloader. Collection<SomeFactory> factories = ServiceHelper.loadFactories(SomeFactory.class); assertThat(factories) .isNotNull() .hasSize(0); // Try with the custom classloader factories = ServiceHelper.loadFactories(SomeFactory.class, custom); assertThat(factories) .isNotNull() .hasSize(1); assertThat(factories.iterator().next().classloader()).isEqualTo(custom); }
@Test public void loadFactoriesFromTCCL() throws Exception { ClassLoader custom = new URLClassLoader(new URL[]{new File("target/externals").toURI().toURL()}); // Try without the TCCL classloader. Collection<SomeFactory> factories = ServiceHelper.loadFactories(SomeFactory.class); assertThat(factories) .isNotNull() .hasSize(0); // Try with the TCCL classloader final ClassLoader originalTCCL = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(custom); factories = ServiceHelper.loadFactories(SomeFactory.class); assertThat(factories) .isNotNull() .hasSize(1); assertThat(factories.iterator().next().classloader()).isEqualTo(custom); } finally { Thread.currentThread().setContextClassLoader(originalTCCL); } }
@Test public void loadFactories() throws Exception { Collection<FakeFactory> factories = ServiceHelper.loadFactories(FakeFactory.class); assertThat(factories) .isNotNull() .hasSize(2); Collection<NotImplementedSPI> impl = ServiceHelper.loadFactories(NotImplementedSPI.class); assertThat(impl) .isNotNull() .hasSize(0); }
@Test public void evaluation_listeners_can_be_cleared() { EvaluationListener listener = new EvaluationListener() { @Override public EvaluationContinuation resultFound(FoundResult found) { return EvaluationContinuation.CONTINUE; } }; Configuration configuration1 = Configuration.builder().evaluationListener(listener).build(); Configuration configuration2 = configuration1.setEvaluationListeners(); assertThat(configuration1.getEvaluationListeners()).hasSize(1); assertThat(configuration2.getEvaluationListeners()).hasSize(0); } }
private void verifyErrors(int errorNumber, FieldModel... fields) { when(layoutSpecModel.getFields()).thenReturn(ImmutableList.of(fields)); Collection<SpecModelValidationError> validationErrors = FieldsValidation.validate(layoutSpecModel); assertThat(validationErrors).hasSize(errorNumber); for (SpecModelValidationError validationError : validationErrors) { assertThat(validationError.element).isSameAs(representedObject); assertThat(validationError.message) .isEqualTo(FIELD_TEST_NAME + " should be declared static and final."); } } }
@Test public void testMissingRequiredOption() throws Exception { String[] args = new String[]{"-a"}; TypedOption<String> b = new TypedOption<String>().setShortName("b").setLongName("bfile") .setSingleValued(true) .setDescription("set the value of [b]").setType(String.class).setRequired(true); cli.removeOption("b").addOption(b); try { cli.parse(Arrays.asList(args)); fail("exception expected"); } catch (MissingOptionException e) { assertThat(e.getExpected()).hasSize(1); } }
ArgumentCaptor.forClass(Collection.class); verify(OkDownload.with().callbackDispatcher()).endTasksWithCanceled(callCaptor.capture()); assertThat(callCaptor.getValue()).hasSize(12); for (DownloadCall call : mockReadyAsyncCalls) { verify(call, never()).cancel();
@Test public void testFieldExtraction() { final TypeElement element = compilationRule.getElements().getTypeElement(TwoFieldsClass.class.getCanonicalName()); ImmutableList<FieldModel> fieldModels = FieldsExtractor.extractFields(element); assertThat(fieldModels).hasSize(2); FieldSpec extractedIntField = fieldModels.get(0).field; assertThat(extractedIntField.name).isEqualTo("intField"); assertThat(extractedIntField.modifiers).hasSize(3); assertThat(extractedIntField.hasModifier(Modifier.PRIVATE)); assertThat(extractedIntField.hasModifier(Modifier.STATIC)); assertThat(extractedIntField.hasModifier(Modifier.FINAL)); FieldSpec extractedFloatField = fieldModels.get(1).field; assertThat(extractedFloatField.name).isEqualTo("floatField"); assertThat(extractedFloatField.modifiers).hasSize(1); assertThat(extractedFloatField.hasModifier(Modifier.STATIC)); }
@Test public void addHeader_getRequestHeaderFiles_meet() throws IOException { assertThat(connection.getRequestProperty("no-exist-key")).isNull(); DownloadOkHttp3Connection.Factory creator = new DownloadOkHttp3Connection.Factory(); DownloadOkHttp3Connection connection = (DownloadOkHttp3Connection) creator.create(URL); connection.addHeader("mock", "mock"); connection.addHeader("mock1", "mock2"); connection.addHeader("mock1", "mock3"); assertThat(connection.getRequestProperty("mock")).isEqualTo("mock"); Map<String, List<String>> headers = connection.getRequestProperties(); assertThat(headers.keySet()).hasSize(2).contains("mock", "mock1"); List<String> allValues = new ArrayList<>(); Collection<List<String>> valueList = headers.values(); for (List<String> values : valueList) { allValues.addAll(values); } assertThat(allValues).hasSize(3).contains("mock", "mock2", "mock3"); }
@Test public void testMissingRequiredOptions() throws CLIException { String[] args = new String[]{"-a"}; TypedOption<String> b = new TypedOption<String>().setShortName("b").setLongName("bfile").setSingleValued(true) .setDescription("set the value of [b]").setType(String.class).setRequired(true); TypedOption<Boolean> c = new TypedOption<Boolean>().setShortName("c").setLongName("copt").setSingleValued(false) .setDescription("turn [c] on or off").setType(Boolean.class).setRequired(true); cli.removeOption("b").addOption(b).removeOption("c").addOption(c); try { CommandLine evaluated = cli.parse(Arrays.asList(args)); fail("exception expected"); } catch (MissingOptionException e) { assertThat(e.getExpected()).hasSize(2); } }
assertThat(set).hasSize(1); set.remove(testElt1); assertThat(set) .doesNotContain(testElt4) .doesNotContain(testElt5) .hasSize(3) .isNotEmpty(); assertThat(checkIterator(set)).isTrue(); .contains(testElt3) .doesNotContain(testElt4) .hasSize(2); assertThat(checkIterator(set)).isTrue(); .contains(testElt3) .contains(testElt4) .hasSize(3); assertThat(checkIterator(set)).isTrue(); assertThat(set) .contains(testElt5) .hasSize(4); assertThat(checkIterator(set)).isTrue(); assertThat(set.remove(testElt5)).isTrue(); .contains(testElt3) .contains(testElt4) .hasSize(3);
@Test public void loadFactoriesWithVertxClassloader() throws Exception { // This test is a bit more tricky as we need to load the ServiceHelper class from a custom classloader. ClassLoader custom = new URLClassLoader(new URL[]{ new File("target/classes").toURI().toURL(), new File("target/test-classes").toURI().toURL(), new File("target/externals").toURI().toURL(), }, null); Class serviceHelperClass = custom.loadClass(ServiceHelper.class.getName()); Class someFactoryClass = custom.loadClass(SomeFactory.class.getName()); assertThat(serviceHelperClass.getClassLoader()).isEqualTo(custom); assertThat(someFactoryClass.getClassLoader()).isEqualTo(custom); Method method = serviceHelperClass.getMethod("loadFactories", Class.class); Collection collection = (Collection) method.invoke(null, someFactoryClass); assertThat(collection).hasSize(1); }
@Test public void loadFactoriesWithClassloader() throws Exception { ClassLoader custom = new URLClassLoader(new URL[]{new File("target/externals").toURI().toURL()}); // Try without the custom classloader. Collection<SomeFactory> factories = ServiceHelper.loadFactories(SomeFactory.class); assertThat(factories) .isNotNull() .hasSize(0); // Try with the custom classloader factories = ServiceHelper.loadFactories(SomeFactory.class, custom); assertThat(factories) .isNotNull() .hasSize(1); assertThat(factories.iterator().next().classloader()).isEqualTo(custom); }
@Test public void loadFactories() throws Exception { Collection<FakeFactory> factories = ServiceHelper.loadFactories(FakeFactory.class); assertThat(factories) .isNotNull() .hasSize(2); Collection<NotImplementedSPI> impl = ServiceHelper.loadFactories(NotImplementedSPI.class); assertThat(impl) .isNotNull() .hasSize(0); }
private void checkRangesPerHost(String keyspace, int replicationFactor) { List<TokenRange> allRangesWithReplicas = Lists.newArrayList(); // Get each host's ranges, the count should match the replication factor for (int i = 1; i <= 3; i++) { Host host = TestUtils.findHost(cluster(), i); Set<TokenRange> hostRanges = cluster().getMetadata().getTokenRanges(keyspace, host); // Special case: When using vnodes the tokens are not evenly assigned to each replica. if (!useVnodes) { assertThat(hostRanges).hasSize(replicationFactor * numTokens); } allRangesWithReplicas.addAll(hostRanges); } // Special case check for vnodes to ensure that total number of replicated ranges is correct. assertThat(allRangesWithReplicas).hasSize(3 * numTokens * replicationFactor); // Once we ignore duplicates, the number of ranges should match the number of nodes. Set<TokenRange> allRanges = new HashSet<TokenRange>(allRangesWithReplicas); assertThat(allRanges).hasSize(3 * numTokens); // And the ranges should cover the whole ring and no ranges intersect. assertThat(cluster()).hasValidTokenRanges(keyspace); }
@Test public void testMissingRequiredOption() throws Exception { String[] args = new String[]{"-a"}; TypedOption<String> b = new TypedOption<String>().setShortName("b").setLongName("bfile") .setSingleValued(true) .setDescription("set the value of [b]").setType(String.class).setRequired(true); cli.removeOption("b").addOption(b); try { cli.parse(Arrays.asList(args)); fail("exception expected"); } catch (MissingOptionException e) { assertThat(e.getExpected()).hasSize(1); } }
@Test public void testMissingRequiredOptions() throws CLIException { String[] args = new String[]{"-a"}; TypedOption<String> b = new TypedOption<String>().setShortName("b").setLongName("bfile").setSingleValued(true) .setDescription("set the value of [b]").setType(String.class).setRequired(true); TypedOption<Boolean> c = new TypedOption<Boolean>().setShortName("c").setLongName("copt").setSingleValued(false) .setDescription("turn [c] on or off").setType(Boolean.class).setRequired(true); cli.removeOption("b").addOption(b).removeOption("c").addOption(c); try { CommandLine evaluated = cli.parse(Arrays.asList(args)); fail("exception expected"); } catch (MissingOptionException e) { assertThat(e.getExpected()).hasSize(2); } }