Convert CRLF (dos) to LF (unix)
Prior to this change, roughly 5% (~300 out of 6000+) of files under the source tree had CRLF line endings as opposed to the majority which have LF endings. This change normalizes these files to LF for consistency going forward. Command used: $ git ls-files | xargs file | grep CRLF | cut -d":" -f1 | xargs dos2unix Issue: SPR-5608
This commit is contained in:
@@ -1,105 +1,105 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.core;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Shepperd
|
||||
*/
|
||||
public class ExceptionDepthComparatorTests {
|
||||
|
||||
@Test
|
||||
public void targetBeforeSameDepth() throws Exception {
|
||||
Class<? extends Throwable> foundClass = findClosestMatch(TargetException.class, SameDepthException.class);
|
||||
assertEquals(TargetException.class, foundClass);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sameDepthBeforeTarget() throws Exception {
|
||||
Class<? extends Throwable> foundClass = findClosestMatch(SameDepthException.class, TargetException.class);
|
||||
assertEquals(TargetException.class, foundClass);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lowestDepthBeforeTarget() throws Exception {
|
||||
Class<? extends Throwable> foundClass = findClosestMatch(LowestDepthException.class, TargetException.class);
|
||||
assertEquals(TargetException.class, foundClass);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void targetBeforeLowestDepth() throws Exception {
|
||||
Class<? extends Throwable> foundClass = findClosestMatch(TargetException.class, LowestDepthException.class);
|
||||
assertEquals(TargetException.class, foundClass);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noDepthBeforeTarget() throws Exception {
|
||||
Class<? extends Throwable> foundClass = findClosestMatch(NoDepthException.class, TargetException.class);
|
||||
assertEquals(TargetException.class, foundClass);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noDepthBeforeHighestDepth() throws Exception {
|
||||
Class<? extends Throwable> foundClass = findClosestMatch(NoDepthException.class, HighestDepthException.class);
|
||||
assertEquals(HighestDepthException.class, foundClass);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void highestDepthBeforeNoDepth() throws Exception {
|
||||
Class<? extends Throwable> foundClass = findClosestMatch(HighestDepthException.class, NoDepthException.class);
|
||||
assertEquals(HighestDepthException.class, foundClass);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void highestDepthBeforeLowestDepth() throws Exception {
|
||||
Class<? extends Throwable> foundClass = findClosestMatch(HighestDepthException.class, LowestDepthException.class);
|
||||
assertEquals(LowestDepthException.class, foundClass);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lowestDepthBeforeHighestDepth() throws Exception {
|
||||
Class<? extends Throwable> foundClass = findClosestMatch(LowestDepthException.class, HighestDepthException.class);
|
||||
assertEquals(LowestDepthException.class, foundClass);
|
||||
}
|
||||
|
||||
private Class<? extends Throwable> findClosestMatch(Class<? extends Throwable>... classes) {
|
||||
return ExceptionDepthComparator.findClosestMatch(Arrays.asList(classes), new TargetException());
|
||||
}
|
||||
|
||||
|
||||
public class HighestDepthException extends Throwable {
|
||||
}
|
||||
|
||||
public class LowestDepthException extends HighestDepthException {
|
||||
}
|
||||
|
||||
public class TargetException extends LowestDepthException {
|
||||
}
|
||||
|
||||
public class SameDepthException extends LowestDepthException {
|
||||
}
|
||||
|
||||
public class NoDepthException extends TargetException {
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.core;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Shepperd
|
||||
*/
|
||||
public class ExceptionDepthComparatorTests {
|
||||
|
||||
@Test
|
||||
public void targetBeforeSameDepth() throws Exception {
|
||||
Class<? extends Throwable> foundClass = findClosestMatch(TargetException.class, SameDepthException.class);
|
||||
assertEquals(TargetException.class, foundClass);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sameDepthBeforeTarget() throws Exception {
|
||||
Class<? extends Throwable> foundClass = findClosestMatch(SameDepthException.class, TargetException.class);
|
||||
assertEquals(TargetException.class, foundClass);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lowestDepthBeforeTarget() throws Exception {
|
||||
Class<? extends Throwable> foundClass = findClosestMatch(LowestDepthException.class, TargetException.class);
|
||||
assertEquals(TargetException.class, foundClass);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void targetBeforeLowestDepth() throws Exception {
|
||||
Class<? extends Throwable> foundClass = findClosestMatch(TargetException.class, LowestDepthException.class);
|
||||
assertEquals(TargetException.class, foundClass);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noDepthBeforeTarget() throws Exception {
|
||||
Class<? extends Throwable> foundClass = findClosestMatch(NoDepthException.class, TargetException.class);
|
||||
assertEquals(TargetException.class, foundClass);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void noDepthBeforeHighestDepth() throws Exception {
|
||||
Class<? extends Throwable> foundClass = findClosestMatch(NoDepthException.class, HighestDepthException.class);
|
||||
assertEquals(HighestDepthException.class, foundClass);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void highestDepthBeforeNoDepth() throws Exception {
|
||||
Class<? extends Throwable> foundClass = findClosestMatch(HighestDepthException.class, NoDepthException.class);
|
||||
assertEquals(HighestDepthException.class, foundClass);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void highestDepthBeforeLowestDepth() throws Exception {
|
||||
Class<? extends Throwable> foundClass = findClosestMatch(HighestDepthException.class, LowestDepthException.class);
|
||||
assertEquals(LowestDepthException.class, foundClass);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lowestDepthBeforeHighestDepth() throws Exception {
|
||||
Class<? extends Throwable> foundClass = findClosestMatch(LowestDepthException.class, HighestDepthException.class);
|
||||
assertEquals(LowestDepthException.class, foundClass);
|
||||
}
|
||||
|
||||
private Class<? extends Throwable> findClosestMatch(Class<? extends Throwable>... classes) {
|
||||
return ExceptionDepthComparator.findClosestMatch(Arrays.asList(classes), new TargetException());
|
||||
}
|
||||
|
||||
|
||||
public class HighestDepthException extends Throwable {
|
||||
}
|
||||
|
||||
public class LowestDepthException extends HighestDepthException {
|
||||
}
|
||||
|
||||
public class TargetException extends LowestDepthException {
|
||||
}
|
||||
|
||||
public class SameDepthException extends LowestDepthException {
|
||||
}
|
||||
|
||||
public class NoDepthException extends TargetException {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,97 +1,97 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.core;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class GenericTypeResolverTests {
|
||||
|
||||
@Test
|
||||
public void testSimpleInterfaceType() {
|
||||
assertEquals(String.class, GenericTypeResolver.resolveTypeArgument(MySimpleInterfaceType.class, MyInterfaceType.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleCollectionInterfaceType() {
|
||||
assertEquals(Collection.class, GenericTypeResolver.resolveTypeArgument(MyCollectionInterfaceType.class, MyInterfaceType.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleSuperclassType() {
|
||||
assertEquals(String.class, GenericTypeResolver.resolveTypeArgument(MySimpleSuperclassType.class, MySuperclassType.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleCollectionSuperclassType() {
|
||||
assertEquals(Collection.class, GenericTypeResolver.resolveTypeArgument(MyCollectionSuperclassType.class, MySuperclassType.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodReturnType() {
|
||||
assertEquals(Integer.class, GenericTypeResolver.resolveReturnTypeArgument(ReflectionUtils.findMethod(MyTypeWithMethods.class, "integer"), MyInterfaceType.class));
|
||||
assertEquals(String.class, GenericTypeResolver.resolveReturnTypeArgument(ReflectionUtils.findMethod(MyTypeWithMethods.class, "string"), MyInterfaceType.class));
|
||||
assertEquals(null, GenericTypeResolver.resolveReturnTypeArgument(ReflectionUtils.findMethod(MyTypeWithMethods.class, "raw"), MyInterfaceType.class));
|
||||
assertEquals(null, GenericTypeResolver.resolveReturnTypeArgument(ReflectionUtils.findMethod(MyTypeWithMethods.class, "object"), MyInterfaceType.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullIfNotResolvable() {
|
||||
GenericClass<String> obj = new GenericClass<String>();
|
||||
assertNull(GenericTypeResolver.resolveTypeArgument(obj.getClass(), GenericClass.class));
|
||||
}
|
||||
|
||||
|
||||
public interface MyInterfaceType<T> {
|
||||
}
|
||||
|
||||
public class MySimpleInterfaceType implements MyInterfaceType<String> {
|
||||
}
|
||||
|
||||
public class MyCollectionInterfaceType implements MyInterfaceType<Collection<String>> {
|
||||
}
|
||||
|
||||
|
||||
public abstract class MySuperclassType<T> {
|
||||
}
|
||||
|
||||
public class MySimpleSuperclassType extends MySuperclassType<String> {
|
||||
}
|
||||
|
||||
public class MyCollectionSuperclassType extends MySuperclassType<Collection<String>> {
|
||||
}
|
||||
|
||||
public class MyTypeWithMethods {
|
||||
public MyInterfaceType<Integer> integer() { return null; }
|
||||
public MySimpleInterfaceType string() { return null; }
|
||||
public Object object() { return null; }
|
||||
@SuppressWarnings("rawtypes")
|
||||
public MyInterfaceType raw() { return null; }
|
||||
}
|
||||
|
||||
static class GenericClass<T> {
|
||||
}
|
||||
|
||||
}
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.core;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class GenericTypeResolverTests {
|
||||
|
||||
@Test
|
||||
public void testSimpleInterfaceType() {
|
||||
assertEquals(String.class, GenericTypeResolver.resolveTypeArgument(MySimpleInterfaceType.class, MyInterfaceType.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleCollectionInterfaceType() {
|
||||
assertEquals(Collection.class, GenericTypeResolver.resolveTypeArgument(MyCollectionInterfaceType.class, MyInterfaceType.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleSuperclassType() {
|
||||
assertEquals(String.class, GenericTypeResolver.resolveTypeArgument(MySimpleSuperclassType.class, MySuperclassType.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleCollectionSuperclassType() {
|
||||
assertEquals(Collection.class, GenericTypeResolver.resolveTypeArgument(MyCollectionSuperclassType.class, MySuperclassType.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodReturnType() {
|
||||
assertEquals(Integer.class, GenericTypeResolver.resolveReturnTypeArgument(ReflectionUtils.findMethod(MyTypeWithMethods.class, "integer"), MyInterfaceType.class));
|
||||
assertEquals(String.class, GenericTypeResolver.resolveReturnTypeArgument(ReflectionUtils.findMethod(MyTypeWithMethods.class, "string"), MyInterfaceType.class));
|
||||
assertEquals(null, GenericTypeResolver.resolveReturnTypeArgument(ReflectionUtils.findMethod(MyTypeWithMethods.class, "raw"), MyInterfaceType.class));
|
||||
assertEquals(null, GenericTypeResolver.resolveReturnTypeArgument(ReflectionUtils.findMethod(MyTypeWithMethods.class, "object"), MyInterfaceType.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullIfNotResolvable() {
|
||||
GenericClass<String> obj = new GenericClass<String>();
|
||||
assertNull(GenericTypeResolver.resolveTypeArgument(obj.getClass(), GenericClass.class));
|
||||
}
|
||||
|
||||
|
||||
public interface MyInterfaceType<T> {
|
||||
}
|
||||
|
||||
public class MySimpleInterfaceType implements MyInterfaceType<String> {
|
||||
}
|
||||
|
||||
public class MyCollectionInterfaceType implements MyInterfaceType<Collection<String>> {
|
||||
}
|
||||
|
||||
|
||||
public abstract class MySuperclassType<T> {
|
||||
}
|
||||
|
||||
public class MySimpleSuperclassType extends MySuperclassType<String> {
|
||||
}
|
||||
|
||||
public class MyCollectionSuperclassType extends MySuperclassType<Collection<String>> {
|
||||
}
|
||||
|
||||
public class MyTypeWithMethods {
|
||||
public MyInterfaceType<Integer> integer() { return null; }
|
||||
public MySimpleInterfaceType string() { return null; }
|
||||
public Object object() { return null; }
|
||||
@SuppressWarnings("rawtypes")
|
||||
public MyInterfaceType raw() { return null; }
|
||||
}
|
||||
|
||||
static class GenericClass<T> {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,79 +1,79 @@
|
||||
/*
|
||||
* Copyright 2006-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.core.type;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.UrlResource;
|
||||
import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
|
||||
import org.springframework.core.type.classreading.MetadataReader;
|
||||
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
||||
import org.springframework.core.type.classreading.SimpleMetadataReaderFactory;
|
||||
|
||||
/**
|
||||
* Unit test checking the behaviour of {@link CachingMetadataReaderFactory under load.
|
||||
* If the cache is not controller, this test should fail with an out of memory exception around entry
|
||||
* 5k.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public class CachingMetadataReaderLeakTest {
|
||||
|
||||
private static int ITEMS_LOAD = 9999;
|
||||
private MetadataReaderFactory mrf;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
mrf = new CachingMetadataReaderFactory();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSignificantLoad() throws Exception {
|
||||
// the biggest public class in the JDK (>60k)
|
||||
URL url = getClass().getResource("/java/awt/Component.class");
|
||||
assertThat(url, notNullValue());
|
||||
|
||||
// look at a LOT of items
|
||||
for (int i = 0; i < ITEMS_LOAD; i++) {
|
||||
Resource resource = new UrlResource(url) {
|
||||
private int counter = 0;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return (obj == this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return System.identityHashCode(this);
|
||||
}
|
||||
};
|
||||
|
||||
MetadataReader reader = mrf.getMetadataReader(resource);
|
||||
assertThat(reader, notNullValue());
|
||||
}
|
||||
|
||||
// useful for profiling to take snapshots
|
||||
//System.in.read();
|
||||
}
|
||||
}
|
||||
/*
|
||||
* Copyright 2006-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.core.type;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.UrlResource;
|
||||
import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
|
||||
import org.springframework.core.type.classreading.MetadataReader;
|
||||
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
||||
import org.springframework.core.type.classreading.SimpleMetadataReaderFactory;
|
||||
|
||||
/**
|
||||
* Unit test checking the behaviour of {@link CachingMetadataReaderFactory under load.
|
||||
* If the cache is not controller, this test should fail with an out of memory exception around entry
|
||||
* 5k.
|
||||
*
|
||||
* @author Costin Leau
|
||||
*/
|
||||
public class CachingMetadataReaderLeakTest {
|
||||
|
||||
private static int ITEMS_LOAD = 9999;
|
||||
private MetadataReaderFactory mrf;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
mrf = new CachingMetadataReaderFactory();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSignificantLoad() throws Exception {
|
||||
// the biggest public class in the JDK (>60k)
|
||||
URL url = getClass().getResource("/java/awt/Component.class");
|
||||
assertThat(url, notNullValue());
|
||||
|
||||
// look at a LOT of items
|
||||
for (int i = 0; i < ITEMS_LOAD; i++) {
|
||||
Resource resource = new UrlResource(url) {
|
||||
private int counter = 0;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return (obj == this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return System.identityHashCode(this);
|
||||
}
|
||||
};
|
||||
|
||||
MetadataReader reader = mrf.getMetadataReader(resource);
|
||||
assertThat(reader, notNullValue());
|
||||
}
|
||||
|
||||
// useful for profiling to take snapshots
|
||||
//System.in.read();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,98 +1,98 @@
|
||||
package org.springframework.util;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Test case for {@link CompositeIterator}.
|
||||
*
|
||||
* @author Erwin Vervaet
|
||||
*/
|
||||
public class CompositeIteratorTests extends TestCase {
|
||||
|
||||
public void testNoIterators() {
|
||||
CompositeIterator it = new CompositeIterator();
|
||||
assertFalse(it.hasNext());
|
||||
try {
|
||||
it.next();
|
||||
fail();
|
||||
} catch (NoSuchElementException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testSingleIterator() {
|
||||
CompositeIterator it = new CompositeIterator();
|
||||
it.add(Arrays.asList(new String[] { "0", "1" }).iterator());
|
||||
for (int i = 0; i < 2; i++) {
|
||||
assertTrue(it.hasNext());
|
||||
assertEquals(String.valueOf(i), it.next());
|
||||
}
|
||||
assertFalse(it.hasNext());
|
||||
try {
|
||||
it.next();
|
||||
fail();
|
||||
} catch (NoSuchElementException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testMultipleIterators() {
|
||||
CompositeIterator it = new CompositeIterator();
|
||||
it.add(Arrays.asList(new String[] { "0", "1" }).iterator());
|
||||
it.add(Arrays.asList(new String[] { "2" }).iterator());
|
||||
it.add(Arrays.asList(new String[] { "3", "4" }).iterator());
|
||||
for (int i = 0; i < 5; i++) {
|
||||
assertTrue(it.hasNext());
|
||||
assertEquals(String.valueOf(i), it.next());
|
||||
}
|
||||
assertFalse(it.hasNext());
|
||||
try {
|
||||
it.next();
|
||||
fail();
|
||||
} catch (NoSuchElementException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testInUse() {
|
||||
List list = Arrays.asList(new String[] { "0", "1" });
|
||||
CompositeIterator it = new CompositeIterator();
|
||||
it.add(list.iterator());
|
||||
it.hasNext();
|
||||
try {
|
||||
it.add(list.iterator());
|
||||
fail();
|
||||
} catch (IllegalStateException e) {
|
||||
// expected
|
||||
}
|
||||
it = new CompositeIterator();
|
||||
it.add(list.iterator());
|
||||
it.next();
|
||||
try {
|
||||
it.add(list.iterator());
|
||||
fail();
|
||||
} catch (IllegalStateException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testDuplicateIterators() {
|
||||
List list = Arrays.asList(new String[] { "0", "1" });
|
||||
Iterator iterator = list.iterator();
|
||||
CompositeIterator it = new CompositeIterator();
|
||||
it.add(iterator);
|
||||
it.add(list.iterator());
|
||||
try {
|
||||
it.add(iterator);
|
||||
fail();
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
package org.springframework.util;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Test case for {@link CompositeIterator}.
|
||||
*
|
||||
* @author Erwin Vervaet
|
||||
*/
|
||||
public class CompositeIteratorTests extends TestCase {
|
||||
|
||||
public void testNoIterators() {
|
||||
CompositeIterator it = new CompositeIterator();
|
||||
assertFalse(it.hasNext());
|
||||
try {
|
||||
it.next();
|
||||
fail();
|
||||
} catch (NoSuchElementException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testSingleIterator() {
|
||||
CompositeIterator it = new CompositeIterator();
|
||||
it.add(Arrays.asList(new String[] { "0", "1" }).iterator());
|
||||
for (int i = 0; i < 2; i++) {
|
||||
assertTrue(it.hasNext());
|
||||
assertEquals(String.valueOf(i), it.next());
|
||||
}
|
||||
assertFalse(it.hasNext());
|
||||
try {
|
||||
it.next();
|
||||
fail();
|
||||
} catch (NoSuchElementException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testMultipleIterators() {
|
||||
CompositeIterator it = new CompositeIterator();
|
||||
it.add(Arrays.asList(new String[] { "0", "1" }).iterator());
|
||||
it.add(Arrays.asList(new String[] { "2" }).iterator());
|
||||
it.add(Arrays.asList(new String[] { "3", "4" }).iterator());
|
||||
for (int i = 0; i < 5; i++) {
|
||||
assertTrue(it.hasNext());
|
||||
assertEquals(String.valueOf(i), it.next());
|
||||
}
|
||||
assertFalse(it.hasNext());
|
||||
try {
|
||||
it.next();
|
||||
fail();
|
||||
} catch (NoSuchElementException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testInUse() {
|
||||
List list = Arrays.asList(new String[] { "0", "1" });
|
||||
CompositeIterator it = new CompositeIterator();
|
||||
it.add(list.iterator());
|
||||
it.hasNext();
|
||||
try {
|
||||
it.add(list.iterator());
|
||||
fail();
|
||||
} catch (IllegalStateException e) {
|
||||
// expected
|
||||
}
|
||||
it = new CompositeIterator();
|
||||
it.add(list.iterator());
|
||||
it.next();
|
||||
try {
|
||||
it.add(list.iterator());
|
||||
fail();
|
||||
} catch (IllegalStateException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
public void testDuplicateIterators() {
|
||||
List list = Arrays.asList(new String[] { "0", "1" });
|
||||
Iterator iterator = list.iterator();
|
||||
CompositeIterator it = new CompositeIterator();
|
||||
it.add(iterator);
|
||||
it.add(list.iterator());
|
||||
try {
|
||||
it.add(iterator);
|
||||
fail();
|
||||
} catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user