From a3e7848a30f2e949fb8de8a047f0be0a49c35222 Mon Sep 17 00:00:00 2001 From: Sam Brannen Date: Thu, 20 Aug 2015 15:49:33 +0200 Subject: [PATCH] Clean up warnings and tests in spring-core --- .../core/env/AbstractEnvironment.java | 6 +-- .../ListenableFutureCallbackRegistry.java | 1 - .../core/BridgeMethodResolverTests.java | 3 +- .../core/ExceptionDepthComparatorTests.java | 3 +- .../core/GenericTypeResolverTests.java | 6 +-- .../CollectionToCollectionConverterTests.java | 4 +- .../support/MapToMapConverterTests.java | 3 +- .../core/style/ToStringCreatorTests.java | 3 +- .../core/type/ClassloadingAssertions.java | 26 +++++----- .../util/AutoPopulatingListTests.java | 25 ++++++---- .../springframework/util/ClassUtilsTests.java | 3 +- .../util/Log4jConfigurerTests.java | 48 ++++++++++--------- .../util/MockLog4jAppender.java | 20 ++------ .../concurrent/ListenableFutureTaskTests.java | 3 +- .../SettableListenableFutureTests.java | 4 +- .../util/xml/SimpleNamespaceContextTests.java | 30 +++++------- 16 files changed, 92 insertions(+), 96 deletions(-) diff --git a/spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java b/spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java index b7918aee17d..6c5a71974f5 100644 --- a/spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java +++ b/spring-core/src/main/java/org/springframework/core/env/AbstractEnvironment.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -364,7 +364,7 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment { } @Override - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "rawtypes" }) public Map getSystemEnvironment() { if (suppressGetenvAccess()) { return Collections.emptyMap(); @@ -408,7 +408,7 @@ public abstract class AbstractEnvironment implements ConfigurableEnvironment { } @Override - @SuppressWarnings("unchecked") + @SuppressWarnings({ "unchecked", "rawtypes" }) public Map getSystemProperties() { try { return (Map) System.getProperties(); diff --git a/spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureCallbackRegistry.java b/spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureCallbackRegistry.java index 7526fb01dff..1c4be730da7 100644 --- a/spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureCallbackRegistry.java +++ b/spring-core/src/main/java/org/springframework/util/concurrent/ListenableFutureCallbackRegistry.java @@ -91,7 +91,6 @@ public class ListenableFutureCallbackRegistry { * @param callback the failure callback to add * @since 4.1 */ - @SuppressWarnings("unchecked") public void addFailureCallback(FailureCallback callback) { Assert.notNull(callback, "'callback' must not be null"); synchronized (this.mutex) { diff --git a/spring-core/src/test/java/org/springframework/core/BridgeMethodResolverTests.java b/spring-core/src/test/java/org/springframework/core/BridgeMethodResolverTests.java index bb23f760c30..24b71685b6e 100644 --- a/spring-core/src/test/java/org/springframework/core/BridgeMethodResolverTests.java +++ b/spring-core/src/test/java/org/springframework/core/BridgeMethodResolverTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -42,6 +42,7 @@ import static org.junit.Assert.*; * @author Juergen Hoeller * @author Chris Beams */ +@SuppressWarnings("rawtypes") public class BridgeMethodResolverTests { private static TypeVariable findTypeVariable(Class clazz, String name) { diff --git a/spring-core/src/test/java/org/springframework/core/ExceptionDepthComparatorTests.java b/spring-core/src/test/java/org/springframework/core/ExceptionDepthComparatorTests.java index 5de3f4b6ced..902fe0f4bbd 100644 --- a/spring-core/src/test/java/org/springframework/core/ExceptionDepthComparatorTests.java +++ b/spring-core/src/test/java/org/springframework/core/ExceptionDepthComparatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2015 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. @@ -26,6 +26,7 @@ import static org.junit.Assert.*; * @author Juergen Hoeller * @author Chris Shepperd */ +@SuppressWarnings("unchecked") public class ExceptionDepthComparatorTests { @Test diff --git a/spring-core/src/test/java/org/springframework/core/GenericTypeResolverTests.java b/spring-core/src/test/java/org/springframework/core/GenericTypeResolverTests.java index bd3bdfd3bc0..1fed0c5b196 100644 --- a/spring-core/src/test/java/org/springframework/core/GenericTypeResolverTests.java +++ b/spring-core/src/test/java/org/springframework/core/GenericTypeResolverTests.java @@ -36,6 +36,7 @@ import static org.springframework.util.ReflectionUtils.*; * @author Juergen Hoeller * @author Sam Brannen */ +@SuppressWarnings({ "unchecked", "rawtypes" }) public class GenericTypeResolverTests { @Test @@ -160,7 +161,7 @@ public class GenericTypeResolverTests { MethodParameter methodParameter = MethodParameter.forMethodOrConstructor( WithArrayBase.class.getDeclaredMethod("array", Object[].class), 0); Class resolved = GenericTypeResolver.resolveParameterType(methodParameter, WithArray.class); - assertThat(resolved, equalTo((Class) Object[].class)); + assertThat(resolved, equalTo((Class) Object[].class)); } @Test @@ -168,7 +169,7 @@ public class GenericTypeResolverTests { // SPR-11044 Class resolved = GenericTypeResolver.resolveReturnType( WithArrayBase.class.getDeclaredMethod("array", Object[].class), WithArray.class); - assertThat(resolved, equalTo((Class) Object[].class)); + assertThat(resolved, equalTo((Class) Object[].class)); } @Test @@ -214,7 +215,6 @@ public class GenericTypeResolverTests { return null; } - @SuppressWarnings("rawtypes") public MyInterfaceType raw() { return null; } diff --git a/spring-core/src/test/java/org/springframework/core/convert/support/CollectionToCollectionConverterTests.java b/spring-core/src/test/java/org/springframework/core/convert/support/CollectionToCollectionConverterTests.java index 1eb22e74d47..c65ba7d3d86 100644 --- a/spring-core/src/test/java/org/springframework/core/convert/support/CollectionToCollectionConverterTests.java +++ b/spring-core/src/test/java/org/springframework/core/convert/support/CollectionToCollectionConverterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -343,7 +343,7 @@ public class CollectionToCollectionConverterTests { public List strings; - public List list = Collections.emptyList(); + public List list = Collections.emptyList(); public Collection wildcardCollection = Collections.emptyList(); diff --git a/spring-core/src/test/java/org/springframework/core/convert/support/MapToMapConverterTests.java b/spring-core/src/test/java/org/springframework/core/convert/support/MapToMapConverterTests.java index 86c1cfbfefa..510f4f532c5 100644 --- a/spring-core/src/test/java/org/springframework/core/convert/support/MapToMapConverterTests.java +++ b/spring-core/src/test/java/org/springframework/core/convert/support/MapToMapConverterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -278,6 +278,7 @@ public class MapToMapConverterTests { public MultiValueMap multiValueMapTarget; + @SuppressWarnings("rawtypes") public Map notGenericMapSource; public EnumMap enumMap; diff --git a/spring-core/src/test/java/org/springframework/core/style/ToStringCreatorTests.java b/spring-core/src/test/java/org/springframework/core/style/ToStringCreatorTests.java index 381cc5a3bac..710f521ae7f 100644 --- a/spring-core/src/test/java/org/springframework/core/style/ToStringCreatorTests.java +++ b/spring-core/src/test/java/org/springframework/core/style/ToStringCreatorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2015 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. @@ -30,6 +30,7 @@ import org.springframework.util.ObjectUtils; /** * @author Keith Donald */ +@SuppressWarnings({ "rawtypes", "unchecked" }) public class ToStringCreatorTests extends TestCase { private SomeObject s1, s2, s3; diff --git a/spring-core/src/test/java/org/springframework/core/type/ClassloadingAssertions.java b/spring-core/src/test/java/org/springframework/core/type/ClassloadingAssertions.java index a9996e3334e..16a0e89662a 100644 --- a/spring-core/src/test/java/org/springframework/core/type/ClassloadingAssertions.java +++ b/spring-core/src/test/java/org/springframework/core/type/ClassloadingAssertions.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2007 the original author or authors. + * Copyright 2002-2015 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. @@ -17,29 +17,27 @@ package org.springframework.core.type; import java.lang.reflect.Method; -import junit.framework.TestCase; - import org.springframework.util.ClassUtils; import org.springframework.util.ReflectionUtils; +import static org.junit.Assert.*; + /** - * * @author Ramnivas Laddad - * + * @author Sam Brannen */ -public class ClassloadingAssertions { - public static boolean isClassLoaded(String className) { +abstract class ClassloadingAssertions { + + private static boolean isClassLoaded(String className) { ClassLoader cl = ClassUtils.getDefaultClassLoader(); - Method findLoadeClassMethod = ReflectionUtils.findMethod(cl.getClass(), "findLoadedClass", new Class[]{String.class}); - findLoadeClassMethod.setAccessible(true); - Class loadedClass = (Class)ReflectionUtils.invokeMethod(findLoadeClassMethod, cl, new Object[]{className}); + Method findLoadeClassMethod = ReflectionUtils.findMethod(cl.getClass(), "findLoadedClass", new Class[] { String.class }); + ReflectionUtils.makeAccessible(findLoadeClassMethod); + Class loadedClass = (Class) ReflectionUtils.invokeMethod(findLoadeClassMethod, cl, new Object[] { className }); return loadedClass != null; } - public static void assertClassLoaded(String className) { + public static void assertClassNotLoaded(String className) { + assertFalse("Class [" + className + "] should not have been loaded", isClassLoaded(className)); } - public static void assertClassNotLoaded(String className) { - TestCase.assertFalse("Class shouldn't have been loaded", isClassLoaded(className)); - } } \ No newline at end of file diff --git a/spring-core/src/test/java/org/springframework/util/AutoPopulatingListTests.java b/spring-core/src/test/java/org/springframework/util/AutoPopulatingListTests.java index 77e4600a0d2..ba0980b60a1 100644 --- a/spring-core/src/test/java/org/springframework/util/AutoPopulatingListTests.java +++ b/spring-core/src/test/java/org/springframework/util/AutoPopulatingListTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 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. @@ -18,29 +18,35 @@ package org.springframework.util; import java.util.LinkedList; -import junit.framework.TestCase; +import org.junit.Test; import org.springframework.tests.sample.objects.TestObject; +import static org.junit.Assert.*; + /** * @author Rob Harrop * @author Juergen Hoeller */ -public class AutoPopulatingListTests extends TestCase { +public class AutoPopulatingListTests { - public void testWithClass() throws Exception { + @Test + public void withClass() throws Exception { doTestWithClass(new AutoPopulatingList(TestObject.class)); } - public void testWithClassAndUserSuppliedBackingList() throws Exception { + @Test + public void withClassAndUserSuppliedBackingList() throws Exception { doTestWithClass(new AutoPopulatingList(new LinkedList(), TestObject.class)); } - public void testWithElementFactory() throws Exception { + @Test + public void withElementFactory() throws Exception { doTestWithElementFactory(new AutoPopulatingList(new MockElementFactory())); } - public void testWithElementFactoryAndUserSuppliedBackingList() throws Exception { + @Test + public void withElementFactoryAndUserSuppliedBackingList() throws Exception { doTestWithElementFactory(new AutoPopulatingList(new LinkedList(), new MockElementFactory())); } @@ -76,13 +82,14 @@ public class AutoPopulatingListTests extends TestCase { } } - public void testSerialization() throws Exception { + @Test + public void serialization() throws Exception { AutoPopulatingList list = new AutoPopulatingList(TestObject.class); assertEquals(list, SerializationTestUtils.serializeAndDeserialize(list)); } - private static class MockElementFactory implements AutoPopulatingList.ElementFactory { + private static class MockElementFactory implements AutoPopulatingList.ElementFactory { @Override public Object createElement(int index) { diff --git a/spring-core/src/test/java/org/springframework/util/ClassUtilsTests.java b/spring-core/src/test/java/org/springframework/util/ClassUtilsTests.java index 8625993dcee..32978f575a6 100644 --- a/spring-core/src/test/java/org/springframework/util/ClassUtilsTests.java +++ b/spring-core/src/test/java/org/springframework/util/ClassUtilsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 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. @@ -44,6 +44,7 @@ import static org.junit.Assert.*; * @author Rob Harrop * @author Rick Evans */ +@SuppressWarnings({ "rawtypes", "unchecked" }) public class ClassUtilsTests { private ClassLoader classLoader = getClass().getClassLoader(); diff --git a/spring-core/src/test/java/org/springframework/util/Log4jConfigurerTests.java b/spring-core/src/test/java/org/springframework/util/Log4jConfigurerTests.java index 90d40d7b5d6..52ec052d1b5 100644 --- a/spring-core/src/test/java/org/springframework/util/Log4jConfigurerTests.java +++ b/spring-core/src/test/java/org/springframework/util/Log4jConfigurerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2015 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. @@ -19,49 +19,62 @@ package org.springframework.util; import java.io.FileNotFoundException; import java.net.URL; -import junit.framework.TestCase; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.junit.Test; + +import static org.junit.Assert.*; /** * @author Alef Arendsen * @author Juergen Hoeller + * @author Sam Brannen */ -public class Log4jConfigurerTests extends TestCase { +public class Log4jConfigurerTests { - public void testInitLoggingWithClasspath() throws FileNotFoundException { + @Test + public void initLoggingWithClasspath() throws FileNotFoundException { doTestInitLogging("classpath:org/springframework/util/testlog4j.properties", false); } - public void testInitLoggingWithRelativeFilePath() throws FileNotFoundException { + @Test + public void initLoggingWithRelativeFilePath() throws FileNotFoundException { doTestInitLogging("src/test/resources/org/springframework/util/testlog4j.properties", false); } - public void testInitLoggingWithAbsoluteFilePath() throws FileNotFoundException { + @Test + public void initLoggingWithAbsoluteFilePath() throws FileNotFoundException { URL url = getClass().getResource("testlog4j.properties"); doTestInitLogging(url.toString(), false); } - public void testInitLoggingWithClasspathAndRefreshInterval() throws FileNotFoundException { + @Test + public void initLoggingWithClasspathAndRefreshInterval() throws FileNotFoundException { doTestInitLogging("classpath:org/springframework/util/testlog4j.properties", true); } - public void testInitLoggingWithRelativeFilePathAndRefreshInterval() throws FileNotFoundException { + @Test + public void initLoggingWithRelativeFilePathAndRefreshInterval() throws FileNotFoundException { doTestInitLogging("src/test/resources/org/springframework/util/testlog4j.properties", true); } - /* only works on Windows - public void testInitLoggingWithAbsoluteFilePathAndRefreshInterval() throws FileNotFoundException { + @Test + public void initLoggingWithAbsoluteFilePathAndRefreshInterval() throws FileNotFoundException { URL url = getClass().getResource("testlog4j.properties"); doTestInitLogging(url.getFile(), true); } - */ - public void testInitLoggingWithFileUrlAndRefreshInterval() throws FileNotFoundException { + @Test + public void initLoggingWithFileUrlAndRefreshInterval() throws FileNotFoundException { URL url = getClass().getResource("testlog4j.properties"); doTestInitLogging(url.toString(), true); } + @Test(expected = FileNotFoundException.class) + public void initLoggingWithRefreshIntervalAndFileNotFound() throws FileNotFoundException { + Log4jConfigurer.initLogging("test/org/springframework/util/bla.properties", 10); + } + private void doTestInitLogging(String location, boolean refreshInterval) throws FileNotFoundException { if (refreshInterval) { Log4jConfigurer.initLogging(location, 10); @@ -87,14 +100,5 @@ public class Log4jConfigurerTests extends TestCase { assertTrue(MockLog4jAppender.closeCalled); } - public void testInitLoggingWithRefreshIntervalAndFileNotFound() throws FileNotFoundException { - try { - Log4jConfigurer.initLogging("test/org/springframework/util/bla.properties", 10); - fail("Exception should have been thrown, file does not exist!"); - } - catch (FileNotFoundException ex) { - // OK - } - } - } + diff --git a/spring-core/src/test/java/org/springframework/util/MockLog4jAppender.java b/spring-core/src/test/java/org/springframework/util/MockLog4jAppender.java index e145195b6b2..5da40c8e228 100644 --- a/spring-core/src/test/java/org/springframework/util/MockLog4jAppender.java +++ b/spring-core/src/test/java/org/springframework/util/MockLog4jAppender.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2015 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. @@ -27,36 +27,24 @@ import org.apache.log4j.spi.LoggingEvent; */ public class MockLog4jAppender extends AppenderSkeleton { - public static final List loggingStrings = new ArrayList(); + public static final List loggingStrings = new ArrayList(); public static boolean closeCalled = false; - /* (non-Javadoc) - * @see org.apache.log4j.AppenderSkeleton#append(org.apache.log4j.spi.LoggingEvent) - */ + @Override protected void append(LoggingEvent evt) { - //System.out.println("Adding " + evt.getMessage()); - loggingStrings.add(evt.getMessage()); + loggingStrings.add(evt.getMessage().toString()); } - /* (non-Javadoc) - * @see org.apache.log4j.Appender#close() - */ @Override public void close() { closeCalled = true; } - /* (non-Javadoc) - * @see org.apache.log4j.Appender#requiresLayout() - */ @Override public boolean requiresLayout() { return false; } - - - } diff --git a/spring-core/src/test/java/org/springframework/util/concurrent/ListenableFutureTaskTests.java b/spring-core/src/test/java/org/springframework/util/concurrent/ListenableFutureTaskTests.java index ac2f0de2893..b868039a391 100644 --- a/spring-core/src/test/java/org/springframework/util/concurrent/ListenableFutureTaskTests.java +++ b/spring-core/src/test/java/org/springframework/util/concurrent/ListenableFutureTaskTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -28,6 +28,7 @@ import static org.mockito.Mockito.*; * @author Arjen Poutsma * @author Sebastien Deleuze */ +@SuppressWarnings("unchecked") public class ListenableFutureTaskTests { @Test diff --git a/spring-core/src/test/java/org/springframework/util/concurrent/SettableListenableFutureTests.java b/spring-core/src/test/java/org/springframework/util/concurrent/SettableListenableFutureTests.java index e14bc73e585..0e87d4e1568 100644 --- a/spring-core/src/test/java/org/springframework/util/concurrent/SettableListenableFutureTests.java +++ b/spring-core/src/test/java/org/springframework/util/concurrent/SettableListenableFutureTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2014 the original author or authors. + * Copyright 2002-2015 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. @@ -29,10 +29,10 @@ import static org.junit.Assert.*; import static org.mockito.Mockito.any; import static org.mockito.Mockito.*; - /** * @author Mattias Severson */ +@SuppressWarnings({ "rawtypes", "unchecked" }) public class SettableListenableFutureTests { private SettableListenableFuture settableListenableFuture; diff --git a/spring-core/src/test/java/org/springframework/util/xml/SimpleNamespaceContextTests.java b/spring-core/src/test/java/org/springframework/util/xml/SimpleNamespaceContextTests.java index e8b2c93e2c1..80759270d28 100644 --- a/spring-core/src/test/java/org/springframework/util/xml/SimpleNamespaceContextTests.java +++ b/spring-core/src/test/java/org/springframework/util/xml/SimpleNamespaceContextTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2009 the original author or authors. + * Copyright 2002-2015 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. @@ -13,26 +13,23 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.util.xml; import java.util.Collections; import java.util.Iterator; import javax.xml.XMLConstants; -import org.junit.Before; import org.junit.Test; import static org.junit.Assert.*; public class SimpleNamespaceContextTests { - private SimpleNamespaceContext context; + private final SimpleNamespaceContext context = new SimpleNamespaceContext() {{ + bindNamespaceUri("prefix", "namespaceURI"); + }}; - @Before - public void createContext() throws Exception { - context = new SimpleNamespaceContext(); - context.bindNamespaceUri("prefix", "namespaceURI"); - } @Test public void getNamespaceURI() { @@ -48,7 +45,6 @@ public class SimpleNamespaceContextTests { context.getNamespaceURI(XMLConstants.XML_NS_PREFIX)); assertEquals("Invalid namespaceURI for attribute prefix", XMLConstants.XMLNS_ATTRIBUTE_NS_URI, context.getNamespaceURI(XMLConstants.XMLNS_ATTRIBUTE)); - } @Test @@ -75,32 +71,32 @@ public class SimpleNamespaceContextTests { public void multiplePrefixes() { context.bindNamespaceUri("prefix1", "namespace"); context.bindNamespaceUri("prefix2", "namespace"); - Iterator iterator = context.getPrefixes("namespace"); + Iterator iterator = context.getPrefixes("namespace"); assertNotNull("getPrefixes returns null", iterator); assertTrue("iterator is empty", iterator.hasNext()); - String result = (String) iterator.next(); + String result = iterator.next(); assertTrue("Invalid prefix", result.equals("prefix1") || result.equals("prefix2")); assertTrue("iterator is empty", iterator.hasNext()); - result = (String) iterator.next(); + result = iterator.next(); assertTrue("Invalid prefix", result.equals("prefix1") || result.equals("prefix2")); assertFalse("iterator contains more than two values", iterator.hasNext()); } private void assertPrefixes(String namespaceUri, String prefix) { - Iterator iterator = context.getPrefixes(namespaceUri); + Iterator iterator = context.getPrefixes(namespaceUri); assertNotNull("getPrefixes returns null", iterator); assertTrue("iterator is empty", iterator.hasNext()); - String result = (String) iterator.next(); + String result = iterator.next(); assertEquals("Invalid prefix", prefix, result); assertFalse("iterator contains multiple values", iterator.hasNext()); } @Test public void getBoundPrefixes() throws Exception { - Iterator iterator = context.getBoundPrefixes(); + Iterator iterator = context.getBoundPrefixes(); assertNotNull("getPrefixes returns null", iterator); assertTrue("iterator is empty", iterator.hasNext()); - String result = (String) iterator.next(); + String result = iterator.next(); assertEquals("Invalid prefix", "prefix", result); assertFalse("iterator contains multiple values", iterator.hasNext()); } @@ -115,8 +111,6 @@ public class SimpleNamespaceContextTests { public void removeBinding() throws Exception { context.removeBinding("prefix"); assertNull("Invalid prefix for unbound namespace", context.getPrefix("prefix")); - - } }