private ClusterException(Collection<? extends Throwable> exceptions) { super( exceptions.size() + " exceptions were thrown. The first exception is listed as a cause.", exceptions.iterator().next()); ArrayList<Throwable> temp = new ArrayList<>(); temp.addAll(exceptions); this.exceptions = Collections.unmodifiableCollection(temp); }
@Test public void httpHeaderNameCasingIsPreserved() throws Exception { final String headerName = "Header1"; response.addHeader(headerName, "value1"); Collection<String> responseHeaders = response.getHeaderNames(); assertNotNull(responseHeaders); assertEquals(1, responseHeaders.size()); assertEquals("HTTP header casing not being preserved", headerName, responseHeaders.iterator().next()); }
@Test public void cacheAnnotationOverride() { Collection<CacheOperation> ops = getOps(InterfaceCacheConfig.class, "interfaceCacheableOverride"); assertSame(1, ops.size()); CacheOperation cacheOperation = ops.iterator().next(); assertTrue(cacheOperation instanceof CacheableOperation); }
@Test @SuppressWarnings("rawtypes") public void convertEmptyStringToCollection() { Collection result = conversionService.convert("", Collection.class); assertEquals(0, result.size()); }
@Test public void testBuildCollectionFromMixtureOfReferencesAndValues() throws Exception { MixedCollectionBean jumble = (MixedCollectionBean) this.beanFactory.getBean("jumble"); assertTrue("Expected 3 elements, not " + jumble.getJumble().size(), jumble.getJumble().size() == 3); List l = (List) jumble.getJumble(); assertTrue(l.get(0).equals("literal")); Integer[] array1 = (Integer[]) l.get(1); assertTrue(array1[0].equals(new Integer(2))); assertTrue(array1[1].equals(new Integer(4))); int[] array2 = (int[]) l.get(2); assertTrue(array2[0] == 3); assertTrue(array2[1] == 5); }
@SafeVarargs private static <T> void assertCollectionIs(Collection<T> collection, T... elements) { for (T element : elements) { assertTrue("Did not find " + element, collection.contains(element)); } assertEquals("There are unexpected extra elements in the collection.", elements.length, collection.size()); }
/** * Test for {@link CustomBean} and an manually endpoint registered * with "myCustomEndpointId". The custom endpoint does not provide * any factory so it's registered with the default one */ public void testCustomConfiguration(ApplicationContext context) { JmsListenerContainerTestFactory defaultFactory = context.getBean("jmsListenerContainerFactory", JmsListenerContainerTestFactory.class); JmsListenerContainerTestFactory customFactory = context.getBean("customFactory", JmsListenerContainerTestFactory.class); assertEquals(1, defaultFactory.getListenerContainers().size()); assertEquals(1, customFactory.getListenerContainers().size()); JmsListenerEndpoint endpoint = defaultFactory.getListenerContainers().get(0).getEndpoint(); assertEquals("Wrong endpoint type", SimpleJmsListenerEndpoint.class, endpoint.getClass()); assertEquals("Wrong listener set in custom endpoint", context.getBean("simpleMessageListener"), ((SimpleJmsListenerEndpoint) endpoint).getMessageListener()); JmsListenerEndpointRegistry customRegistry = context.getBean("customRegistry", JmsListenerEndpointRegistry.class); assertEquals("Wrong number of containers in the registry", 2, customRegistry.getListenerContainerIds().size()); assertEquals("Wrong number of containers in the registry", 2, customRegistry.getListenerContainers().size()); assertNotNull("Container with custom id on the annotation should be found", customRegistry.getListenerContainer("listenerId")); assertNotNull("Container created with custom id should be found", customRegistry.getListenerContainer("myCustomEndpointId")); }
@Test public void testWhenTargetTypeIsExactlyTheCollectionInterfaceUsesFallbackCollectionType() throws Exception { CustomCollectionEditor editor = new CustomCollectionEditor(Collection.class); editor.setValue("0, 1, 2"); Collection<?> value = (Collection<?>) editor.getValue(); assertNotNull(value); assertEquals("There must be 1 element in the converted collection", 1, value.size()); assertEquals("0, 1, 2", value.iterator().next()); }
private String style(Collection<?> value) { StringBuilder result = new StringBuilder(value.size() * 8 + 16); result.append(getCollectionTypeString(value)).append('['); for (Iterator<?> i = value.iterator(); i.hasNext();) { result.append(style(i.next())); if (i.hasNext()) { result.append(',').append(' '); } } if (value.isEmpty()) { result.append(EMPTY); } result.append("]"); return result.toString(); }
@Test public void testMultipleCachingSource() { Collection<CacheOperation> ops = getOps("multipleCaching"); assertEquals(2, ops.size()); Iterator<CacheOperation> it = ops.iterator(); CacheOperation next = it.next(); assertTrue(next instanceof CacheableOperation); assertTrue(next.getCacheNames().contains("test")); assertEquals("#a", next.getKey()); next = it.next(); assertTrue(next instanceof CacheableOperation); assertTrue(next.getCacheNames().contains("test")); assertEquals("#b", next.getKey()); }
/** * Collect any {@link AsyncConfigurer} beans through autowiring. */ @Autowired(required = false) void setConfigurers(Collection<AsyncConfigurer> configurers) { if (CollectionUtils.isEmpty(configurers)) { return; } if (configurers.size() > 1) { throw new IllegalStateException("Only one AsyncConfigurer may exist"); } AsyncConfigurer configurer = configurers.iterator().next(); this.executor = configurer::getAsyncExecutor; this.exceptionHandler = configurer::getAsyncUncaughtExceptionHandler; }
boolean removeEntriesIf(Predicate<? super Entry<K, Collection<V>>> predicate) { Iterator<Entry<K, Collection<V>>> entryIterator = unfiltered.asMap().entrySet().iterator(); boolean changed = false; while (entryIterator.hasNext()) { Entry<K, Collection<V>> entry = entryIterator.next(); K key = entry.getKey(); Collection<V> collection = filterCollection(entry.getValue(), new ValuePredicate(key)); if (!collection.isEmpty() && predicate.apply(Maps.immutableEntry(key, collection))) { if (collection.size() == entry.getValue().size()) { entryIterator.remove(); } else { collection.clear(); } changed = true; } } return changed; }
@Test public void combine() { HeadersRequestCondition condition1 = new HeadersRequestCondition("foo=bar"); HeadersRequestCondition condition2 = new HeadersRequestCondition("foo=baz"); HeadersRequestCondition result = condition1.combine(condition2); Collection<HeaderExpression> conditions = result.getContent(); assertEquals(2, conditions.size()); }
static void checkEmpty(Collection<?> collection) { assertTrue(collection.isEmpty()); assertEquals(0, collection.size()); assertFalse(collection.iterator().hasNext()); assertThat(collection.toArray()).isEmpty(); assertThat(collection.toArray(new Object[0])).isEmpty(); if (collection instanceof Set) { new EqualsTester() .addEqualityGroup(ImmutableSet.of(), collection) .addEqualityGroup(ImmutableSet.of("")) .testEquals(); } else if (collection instanceof List) { new EqualsTester() .addEqualityGroup(ImmutableList.of(), collection) .addEqualityGroup(ImmutableList.of("")) .testEquals(); } } }