String.indexOf() expressions can be replaced with a call to the String.contains() method available in Java 5 and newer.

This commit is contained in:
igor-suhorukov
2018-12-07 00:12:32 +03:00
committed by Juergen Hoeller
parent 81d77b9872
commit 93189a6733
18 changed files with 40 additions and 40 deletions

View File

@@ -40,7 +40,7 @@ public class OverloadedAdviceTests {
Throwable cause = ex.getRootCause();
assertTrue("Should be IllegalArgumentException", cause instanceof IllegalArgumentException);
assertTrue("invalidAbsoluteTypeName should be detected by AJ",
cause.getMessage().indexOf("invalidAbsoluteTypeName") != -1);
cause.getMessage().contains("invalidAbsoluteTypeName"));
}
}
@@ -53,7 +53,7 @@ public class OverloadedAdviceTests {
Throwable cause = ex.getRootCause();
assertTrue("Should be IllegalArgumentException", cause instanceof IllegalArgumentException);
assertTrue("Cannot resolve method 'myBeforeAdvice' to a unique method",
cause.getMessage().indexOf("Cannot resolve method 'myBeforeAdvice' to a unique method") != -1);
cause.getMessage().contains("Cannot resolve method 'myBeforeAdvice' to a unique method"));
}
}

View File

@@ -736,7 +736,7 @@ public abstract class AbstractAopProxyTests {
fail("Shouldn't be able to add introduction interceptor except via introduction advice");
}
catch (AopConfigException ex) {
assertTrue(ex.getMessage().indexOf("ntroduction") > -1);
assertTrue(ex.getMessage().contains("ntroduction"));
}
// Check it still works: proxy factory state shouldn't have been corrupted
ITestBean proxied = (ITestBean) createProxy(pc);
@@ -849,7 +849,7 @@ public abstract class AbstractAopProxyTests {
fail("Shouldn't be able to add interceptor when frozen");
}
catch (AopConfigException ex) {
assertTrue(ex.getMessage().indexOf("frozen") > -1);
assertTrue(ex.getMessage().contains("frozen"));
}
// Check it still works: proxy factory state shouldn't have been corrupted
assertEquals(target.getAge(), proxied.getAge());

View File

@@ -145,7 +145,7 @@ public class ProxyFactoryBeanTests {
catch (BeanCreationException ex) {
// Root cause of the problem must be an AOP exception
AopConfigException aex = (AopConfigException) ex.getCause();
assertTrue(aex.getMessage().indexOf("TargetSource") != -1);
assertTrue(aex.getMessage().contains("TargetSource"));
}
}

View File

@@ -482,7 +482,7 @@ public class XmlBeanFactoryTests {
}
catch (BeanDefinitionStoreException ex) {
// check exception message contains the name
assertTrue(ex.getMessage().indexOf("bogusParent") != -1);
assertTrue(ex.getMessage().contains("bogusParent"));
assertTrue(ex.getCause() instanceof NoSuchBeanDefinitionException);
}
}
@@ -678,7 +678,7 @@ public class XmlBeanFactoryTests {
fail();
}
catch (BeanCreationException ex) {
assertTrue(ex.getResourceDescription().indexOf("initializers.xml") != -1);
assertTrue(ex.getResourceDescription().contains("initializers.xml"));
assertEquals("init-method2", ex.getBeanName());
assertTrue(ex.getCause() instanceof IOException);
}
@@ -694,9 +694,9 @@ public class XmlBeanFactoryTests {
}
catch (FatalBeanException ex) {
// check message is helpful
assertTrue(ex.getMessage().indexOf("initializers.xml") != -1);
assertTrue(ex.getMessage().indexOf("init-method3") != -1);
assertTrue(ex.getMessage().indexOf("init") != -1);
assertTrue(ex.getMessage().contains("initializers.xml"));
assertTrue(ex.getMessage().contains("init-method3"));
assertTrue(ex.getMessage().contains("init"));
}
}
@@ -934,7 +934,7 @@ public class XmlBeanFactoryTests {
xbf.getBean("rod2Accessor");
}
catch (BeanCreationException ex) {
assertTrue(ex.toString().indexOf("touchy") != -1);
assertTrue(ex.toString().contains("touchy"));
ex.printStackTrace();
assertNull(ex.getRelatedCauses());
}
@@ -1115,7 +1115,7 @@ public class XmlBeanFactoryTests {
fail("Must have thrown a CannotLoadBeanClassException");
}
catch (CannotLoadBeanClassException ex) {
assertTrue(ex.getResourceDescription().indexOf("classNotFound.xml") != -1);
assertTrue(ex.getResourceDescription().contains("classNotFound.xml"));
assertTrue(ex.getCause() instanceof ClassNotFoundException);
}
}
@@ -1367,7 +1367,7 @@ public class XmlBeanFactoryTests {
}
catch (BeanDefinitionStoreException ex) {
// Check that the bogus method name was included in the error message
assertTrue("Bogus method name correctly reported", ex.getMessage().indexOf("bogusMethod") != -1);
assertTrue("Bogus method name correctly reported", ex.getMessage().contains("bogusMethod"));
}
}

View File

@@ -29,7 +29,7 @@ public class BeanThatBroadcasts implements ApplicationContextAware {
@Override
public void setApplicationContext(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
if (applicationContext.getDisplayName().indexOf("listener") != -1) {
if (applicationContext.getDisplayName().contains("listener")) {
applicationContext.getBean("listener");
}
}

View File

@@ -65,7 +65,7 @@ public class PropertyResourceConfigurerIntegrationTests {
if (userDir.startsWith("/")) {
userDir = userDir.substring(1);
}
assertTrue(ex.getMessage().indexOf(userDir) != -1);
assertTrue(ex.getMessage().contains(userDir));
}
}

View File

@@ -109,8 +109,8 @@ public class StaticMessageSourceTests extends AbstractApplicationContextTests {
// Now msg better be as expected
assertTrue("2nd search within MsgFormat cache returned expected message for Locale.US",
sac.getMessage("message.format.example1", arguments, Locale.US).indexOf(
"there was \"a disturbance in the Force\" on planet 7.") != -1);
sac.getMessage("message.format.example1", arguments, Locale.US).
contains("there was \"a disturbance in the Force\" on planet 7."));
Object[] newArguments = {
new Integer(8), new Date(System.currentTimeMillis()),
@@ -119,8 +119,8 @@ public class StaticMessageSourceTests extends AbstractApplicationContextTests {
// Now msg better be as expected even with different args
assertTrue("2nd search within MsgFormat cache with different args returned expected message for Locale.US",
sac.getMessage("message.format.example1", newArguments, Locale.US)
.indexOf("there was \"a disturbance in the Force\" on planet 8.") != -1);
sac.getMessage("message.format.example1", newArguments, Locale.US).
contains("there was \"a disturbance in the Force\" on planet 8."));
}
/**
@@ -142,13 +142,13 @@ public class StaticMessageSourceTests extends AbstractApplicationContextTests {
minutes of the time might not be the same.
*/
assertTrue("msg from staticMsgSource for Locale.US substituting args for placeholders is as expected",
sac.getMessage("message.format.example1", arguments, Locale.US)
.indexOf("there was \"a disturbance in the Force\" on planet 7.") != -1);
sac.getMessage("message.format.example1", arguments, Locale.US).
contains("there was \"a disturbance in the Force\" on planet 7."));
// Try with Locale.UK
assertTrue("msg from staticMsgSource for Locale.UK substituting args for placeholders is as expected",
sac.getMessage("message.format.example1", arguments, Locale.UK)
.indexOf("there was \"a disturbance in the Force\" on station number 7.") != -1);
sac.getMessage("message.format.example1", arguments, Locale.UK).
contains("there was \"a disturbance in the Force\" on station number 7."));
// Try with Locale.US - Use a different test msg that requires no args
assertTrue("msg from staticMsgSource for Locale.US that requires no args is as expected",

View File

@@ -396,7 +396,7 @@ public class JndiObjectFactoryBeanTests {
fail("Should have thrown NamingException");
}
catch (NamingException ex) {
assertTrue(ex.getMessage().indexOf("org.springframework.tests.sample.beans.DerivedTestBean") != -1);
assertTrue(ex.getMessage().contains("org.springframework.tests.sample.beans.DerivedTestBean"));
}
}