Consistent formatting

This commit is contained in:
Juergen Hoeller 2016-03-24 19:22:49 +01:00
parent 2cdb0cf690
commit 517ebd1d3e
101 changed files with 681 additions and 509 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 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.
@ -101,7 +101,7 @@ public class AspectJAfterReturningAdvice extends AbstractAspectJAdvice
else if (Object.class == type && void.class == method.getReturnType()) {
return true;
}
else{
else {
return ClassUtils.isAssignable(type, method.getReturnType());
}
}

View File

@ -307,7 +307,8 @@ public class AspectJAdviceParameterNameDiscovererTests {
try {
discoverer.getParameterNames(m);
fail("Expecting " + exceptionType.getName() + " with message '" + message + "'");
} catch (RuntimeException expected) {
}
catch (RuntimeException expected) {
assertEquals("Expecting exception of type " + exceptionType.getName(),
exceptionType, expected.getClass());
assertEquals("Exception message does not match expected", message, expected.getMessage());

View File

@ -215,7 +215,8 @@ public final class MethodInvocationProceedingJoinPointTests {
itb.setSpouse(new TestBean());
try {
itb.unreliableFileOperation();
} catch (IOException ex) {
}
catch (IOException ex) {
// we don't realy care...
}
}

View File

@ -1,3 +1,19 @@
/*
* Copyright 2002-2016 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.aop.aspectj;
import java.lang.annotation.Documented;
@ -97,12 +113,14 @@ public class TrickyAspectJPointcutExpressionTests {
try {
bean.sayHello();
fail("Expected exception");
} catch (TestException e) {
assertEquals(message, e.getMessage());
}
catch (TestException ex) {
assertEquals(message, ex.getMessage());
}
assertEquals(1, logAdvice.getCountThrows());
}
public static class SimpleThrowawayClassLoader extends OverridingClassLoader {
/**
@ -115,15 +133,16 @@ public class TrickyAspectJPointcutExpressionTests {
}
@SuppressWarnings("serial")
public static class TestException extends RuntimeException {
public TestException(String string) {
super(string);
}
}
@Target({ ElementType.METHOD, ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
@Documented
@ -131,18 +150,23 @@ public class TrickyAspectJPointcutExpressionTests {
public static @interface Log {
}
public static interface TestService {
public String sayHello();
}
@Log
public static class TestServiceImpl implements TestService {
@Override
public String sayHello() {
throw new TestException("TestServiceImpl");
}
}
public class LogUserAdvice implements MethodBeforeAdvice, ThrowsAdvice {
private int countBefore = 0;
@ -154,9 +178,9 @@ public class TrickyAspectJPointcutExpressionTests {
countBefore++;
}
public void afterThrowing(Exception e) throws Throwable {
public void afterThrowing(Exception ex) throws Throwable {
countThrows++;
throw e;
throw ex;
}
public int getCountBefore() {
@ -171,7 +195,6 @@ public class TrickyAspectJPointcutExpressionTests {
countThrows = 0;
countBefore = 0;
}
}
}

View File

@ -61,7 +61,8 @@ public final class DebugInterceptorTests {
try {
interceptor.invoke(methodInvocation);
fail("Must have propagated the IllegalArgumentException.");
} catch (IllegalArgumentException expected) {
}
catch (IllegalArgumentException expected) {
}
checkCallCountTotal(interceptor);

View File

@ -60,7 +60,8 @@ public final class SimpleTraceInterceptorTests {
try {
interceptor.invokeUnderTrace(mi, log);
fail("Must have propagated the IllegalArgumentException.");
} catch (IllegalArgumentException expected) {
}
catch (IllegalArgumentException expected) {
}
verify(log).trace(anyString());

View File

@ -154,7 +154,8 @@ public class ThreadLocalTargetSourceTests {
// try second time
try {
source.getTarget();
} catch(NullPointerException ex) {
}
catch (NullPointerException ex) {
fail("Should not throw NPE");
}
}

View File

@ -210,7 +210,8 @@ public class AnnotationAsyncExecutionAspectTests {
public synchronized void waitForCompletion() {
try {
wait(WAIT_TIME);
} catch (InterruptedException e) {
}
catch (InterruptedException ex) {
fail("Didn't finish the async job in " + WAIT_TIME + " milliseconds");
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2016 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.
@ -204,7 +204,7 @@ public class FieldRetrievingFactoryBean
// instance field
return this.fieldObject.get(this.targetObject);
}
else{
else {
// class field
return this.fieldObject.get(null);
}

View File

@ -81,19 +81,22 @@ public final class ServiceLocatorFactoryBeanTests {
TestServiceLocator factory = (TestServiceLocator) bf.getBean("factory");
factory.getTestService();
fail("Must fail on more than one matching type");
} catch (NoSuchBeanDefinitionException ex) { /* expected */ }
}
catch (NoSuchBeanDefinitionException ex) { /* expected */ }
try {
TestServiceLocator2 factory = (TestServiceLocator2) bf.getBean("factory2");
factory.getTestService(null);
fail("Must fail on more than one matching type");
} catch (NoSuchBeanDefinitionException ex) { /* expected */ }
}
catch (NoSuchBeanDefinitionException ex) { /* expected */ }
try {
TestService2Locator factory = (TestService2Locator) bf.getBean("factory3");
factory.getTestService();
fail("Must fail on no matching types");
} catch (NoSuchBeanDefinitionException ex) { /* expected */ }
}
catch (NoSuchBeanDefinitionException ex) { /* expected */ }
}
@Test
@ -138,7 +141,8 @@ public final class ServiceLocatorFactoryBeanTests {
TestService2Locator factory3 = (TestService2Locator) bf.getBean("factory3");
factory3.getTestService();
fail("Must fail on no matching type");
} catch (CustomServiceLocatorException3 ex) { /* expected */ }
}
catch (CustomServiceLocatorException3 ex) { /* expected */ }
}
@Test
@ -160,7 +164,8 @@ public final class ServiceLocatorFactoryBeanTests {
try {
factory.getTestService("bogusTestService");
fail("Illegal operation allowed");
} catch (NoSuchBeanDefinitionException ex) { /* expected */ }
}
catch (NoSuchBeanDefinitionException ex) { /* expected */ }
}
@Ignore @Test // worked when using an ApplicationContext (see commented), fails when using BeanFactory
@ -275,7 +280,8 @@ public final class ServiceLocatorFactoryBeanTests {
try {
ServiceLocatorFactoryBean factory = new ServiceLocatorFactoryBean();
factory.setBeanFactory(beanFactory);
} catch (FatalBeanException ex) {
}
catch (FatalBeanException ex) {
// expected
}
}

View File

@ -324,7 +324,8 @@ public class CallbacksSecurityTests {
try {
acc.checkPermission(new PropertyPermission("*", "read"));
fail("Acc should not have any permissions");
} catch (SecurityException se) {
}
catch (SecurityException se) {
// expected
}
@ -342,7 +343,8 @@ public class CallbacksSecurityTests {
}
}, acc);
fail("expected security exception");
} catch (Exception ex) {
}
catch (Exception ex) {
}
final Class<ConstructorBean> cl = ConstructorBean.class;
@ -356,7 +358,8 @@ public class CallbacksSecurityTests {
}
}, acc);
fail("expected security exception");
} catch (Exception ex) {
}
catch (Exception ex) {
}
}
@ -365,7 +368,8 @@ public class CallbacksSecurityTests {
try {
beanFactory.getBean("spring-init");
fail("expected security exception");
} catch (BeanCreationException ex) {
}
catch (BeanCreationException ex) {
assertTrue(ex.getCause() instanceof SecurityException);
}
}
@ -375,7 +379,8 @@ public class CallbacksSecurityTests {
try {
beanFactory.getBean("custom-init");
fail("expected security exception");
} catch (BeanCreationException ex) {
}
catch (BeanCreationException ex) {
assertTrue(ex.getCause() instanceof SecurityException);
}
}
@ -399,7 +404,8 @@ public class CallbacksSecurityTests {
try {
beanFactory.getBean("spring-factory");
fail("expected security exception");
} catch (BeanCreationException ex) {
}
catch (BeanCreationException ex) {
assertTrue(ex.getCause() instanceof SecurityException);
}
@ -416,7 +422,8 @@ public class CallbacksSecurityTests {
try {
beanFactory.getBean("custom-static-factory-method");
fail("expected security exception");
} catch (BeanCreationException ex) {
}
catch (BeanCreationException ex) {
assertTrue(ex.getMostSpecificCause() instanceof SecurityException);
}
}
@ -426,7 +433,8 @@ public class CallbacksSecurityTests {
try {
beanFactory.getBean("custom-factory-method");
fail("expected security exception");
} catch (BeanCreationException ex) {
}
catch (BeanCreationException ex) {
assertTrue(ex.getMostSpecificCause() instanceof SecurityException);
}
}
@ -436,7 +444,8 @@ public class CallbacksSecurityTests {
try {
beanFactory.getBean("privileged-static-factory-method");
fail("expected security exception");
} catch (BeanCreationException ex) {
}
catch (BeanCreationException ex) {
assertTrue(ex.getMostSpecificCause() instanceof SecurityException);
}
}
@ -446,7 +455,8 @@ public class CallbacksSecurityTests {
try {
beanFactory.getBean("constructor");
fail("expected security exception");
} catch (BeanCreationException ex) {
}
catch (BeanCreationException ex) {
// expected
assertTrue(ex.getMostSpecificCause() instanceof SecurityException);
}
@ -472,7 +482,8 @@ public class CallbacksSecurityTests {
try {
beanFactory.getBean("property-injection");
fail("expected security exception");
} catch (BeanCreationException ex) {
}
catch (BeanCreationException ex) {
assertTrue(ex.getMessage().contains("security"));
}

View File

@ -48,7 +48,8 @@ public class DuplicateBeanIdTests {
try {
reader.loadBeanDefinitions(new ClassPathResource("DuplicateBeanIdTests-sameLevel-context.xml", this.getClass()));
fail("expected parsing exception due to duplicate ids in same nesting level");
} catch (Exception ex) {
}
catch (Exception ex) {
// expected
}
}

View File

@ -485,7 +485,8 @@ public class CustomEditorTests {
CustomNumberEditor editor = new CustomNumberEditor(Short.class, true);
editor.setAsText(String.valueOf(Short.MAX_VALUE + 1));
fail(Short.MAX_VALUE + 1 + " is greater than max value");
} catch (NumberFormatException ex) {
}
catch (NumberFormatException ex) {
// expected
}
}

View File

@ -70,7 +70,7 @@ public class CollectingReaderEventListener implements ReaderEventListener {
@Override
public void aliasRegistered(AliasDefinition aliasDefinition) {
List aliases = (List) this.aliasMap.get(aliasDefinition.getBeanName());
if(aliases == null) {
if (aliases == null) {
aliases = new ArrayList();
this.aliasMap.put(aliasDefinition.getBeanName(), aliases);
}

View File

@ -186,7 +186,9 @@ class PrecedenceTestAspect implements BeanNameAware, Ordered {
try {
ret = ((Integer)pjp.proceed()).intValue();
}
catch(Throwable t) { throw new RuntimeException(t); }
catch (Throwable t) {
throw new RuntimeException(t);
}
this.collaborator.aroundAdviceOne(this.name);
return ret;
}
@ -197,7 +199,9 @@ class PrecedenceTestAspect implements BeanNameAware, Ordered {
try {
ret = ((Integer)pjp.proceed()).intValue();
}
catch(Throwable t) {throw new RuntimeException(t);}
catch (Throwable t) {
throw new RuntimeException(t);
}
this.collaborator.aroundAdviceTwo(this.name);
return ret;
}

View File

@ -513,11 +513,13 @@ class RetryAspect {
try {
o = jp.proceed();
this.commitCalls++;
} catch (RetryableException e) {
this.rollbackCalls++;
throw e;
}
} catch (RetryableException re) {
catch (RetryableException re) {
this.rollbackCalls++;
throw re;
}
}
catch (RetryableException re) {
retry = true;
}
}

View File

@ -1,5 +1,5 @@
/**
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2016 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,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.aop.aspectj.autoproxy.spr3064;
import java.lang.annotation.Retention;
@ -35,6 +36,7 @@ public final class SPR3064Tests {
private Service service;
@Test
public void testServiceIsAdvised() {
ClassPathXmlApplicationContext ctx =
@ -46,7 +48,7 @@ public final class SPR3064Tests {
this.service.serveMe();
fail("service operation has not been advised by transaction interceptor");
}
catch(RuntimeException ex) {
catch (RuntimeException ex) {
assertEquals("advice invoked",ex.getMessage());
}
}
@ -56,7 +58,6 @@ public final class SPR3064Tests {
@Retention(RetentionPolicy.RUNTIME)
@interface Transaction {
}
@ -68,14 +69,12 @@ class TransactionInterceptor {
throw new RuntimeException("advice invoked");
//return pjp.proceed();
}
}
interface Service {
void serveMe();
}
@ -85,5 +84,4 @@ class ServiceImpl implements Service {
@Transaction
public void serveMe() {
}
}

View File

@ -400,7 +400,8 @@ public abstract class AbstractAopProxyTests {
public Object invoke(MethodInvocation invocation) throws Throwable {
if (!context) {
assertNoInvocationContext();
} else {
}
else {
assertNotNull("have context", ExposeInvocationInterceptor.currentInvocation());
}
return s;

View File

@ -354,7 +354,8 @@ public abstract class AbstractCacheAnnotationTests {
try {
service.throwCheckedSync(arg);
fail("Excepted exception");
} catch (Exception ex) {
}
catch (Exception ex) {
ex.printStackTrace();
assertEquals("Wrong exception type", IOException.class, ex.getClass());
assertEquals(arg, ex.getMessage());
@ -365,7 +366,8 @@ public abstract class AbstractCacheAnnotationTests {
try {
service.throwUncheckedSync(Long.valueOf(1));
fail("Excepted exception");
} catch (RuntimeException ex) {
}
catch (RuntimeException ex) {
assertEquals("Wrong exception type", UnsupportedOperationException.class, ex.getClass());
assertEquals("1", ex.getMessage());
}

View File

@ -35,7 +35,10 @@ public class CacheAdviceParserTests {
try {
new GenericXmlApplicationContext("/org/springframework/cache/config/cache-advice-invalid.xml");
fail("Should have failed to load context, one advise define both a key and a key generator");
} catch (BeanDefinitionStoreException e) { // TODO better exception handling
}
catch (BeanDefinitionStoreException ex) {
// TODO better exception handling
}
}
}

View File

@ -72,7 +72,7 @@ public class PropertySourceAnnotationTests {
do {
name = iterator.next().getName();
}
while(iterator.hasNext());
while (iterator.hasNext());
assertThat(name, is("p1"));
}

View File

@ -117,7 +117,7 @@ public class ConfigurationClassProcessingTests {
BeanFactory factory = initBeanFactory(ConfigWithBeanWithAliases.class);
assertSame(factory.getBean("name1"), ConfigWithBeanWithAliases.testBean);
String[] aliases = factory.getAliases("name1");
for(String alias : aliases)
for (String alias : aliases)
assertSame(factory.getBean(alias), ConfigWithBeanWithAliases.testBean);
// method name should not be registered

View File

@ -37,7 +37,7 @@ public class Spr10546Tests {
@After
public void closeContext() {
if(context != null) {
if (context != null) {
context.close();
}
}

View File

@ -53,7 +53,8 @@ public class FactoryBeanAccessTests {
try {
assertEquals(Boat.class.getName(), expr.getValue(context));
fail("Expected BeanIsNotAFactoryException");
} catch (BeanIsNotAFactoryException binafe) {
}
catch (BeanIsNotAFactoryException binafe) {
// success
}

View File

@ -85,9 +85,11 @@ public class SerializableBeanFactoryMemoryLeakTests {
ctx.refresh();
assertThat(serializableFactoryCount(), equalTo(1));
ctx.close();
} catch (BeanCreationException ex) {
}
catch (BeanCreationException ex) {
// ignore - this is expected on refresh() for failure case tests
} finally {
}
finally {
assertThat(serializableFactoryCount(), equalTo(0));
}
}

View File

@ -196,7 +196,8 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
// now start the connector
try {
connector.start();
} catch (BindException ex) {
}
catch (BindException ex) {
System.out.println("Skipping remainder of JMX LazyConnectionToRemote test because binding to local port ["
+ port + "] failed: " + ex.getMessage());
return;
@ -206,13 +207,15 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
try {
assertEquals("Rob Harrop", bean.getName());
assertEquals(100, bean.getAge());
} finally {
}
finally {
connector.stop();
}
try {
bean.getName();
} catch (JmxException ex) {
}
catch (JmxException ex) {
// expected
}
@ -223,7 +226,8 @@ public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
try {
assertEquals("Rob Harrop", bean.getName());
assertEquals(100, bean.getAge());
} finally {
}
finally {
connector.stop();
}
}

View File

@ -63,7 +63,8 @@ public class RemoteMBeanClientInterceptorTests extends MBeanClientInterceptorTes
this.connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(getServiceUrl(), null, getServer());
try {
this.connectorServer.start();
} catch (BindException ex) {
}
catch (BindException ex) {
System.out.println("Skipping remote JMX tests because binding to local port ["
+ SERVICE_PORT + "] failed: " + ex.getMessage());
runTests = false;

View File

@ -172,7 +172,8 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
if (notification instanceof AttributeChangeNotification) {
AttributeChangeNotification changeNotification = (AttributeChangeNotification) notification;
return "Name".equals(changeNotification.getAttributeName());
} else {
}
else {
return false;
}
}
@ -200,7 +201,8 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
try {
new NotificationListenerBean().afterPropertiesSet();
fail("Must have thrown an IllegalArgumentException (no NotificationListener supplied)");
} catch (IllegalArgumentException expected) {
}
catch (IllegalArgumentException expected) {
}
}
@ -463,7 +465,8 @@ public class NotificationListenerTests extends AbstractMBeanServerTests {
if (currentCount != null) {
int count = currentCount.intValue() + 1;
this.attributeCounts.put(attributeName, new Integer(count));
} else {
}
else {
this.attributeCounts.put(attributeName, new Integer(1));
}

View File

@ -67,7 +67,8 @@ public class ConnectorServerFactoryBeanTests extends AbstractMBeanServerTests {
try {
checkServerConnection(getServer());
} finally {
}
finally {
bean.destroy();
}
}
@ -84,7 +85,8 @@ public class ConnectorServerFactoryBeanTests extends AbstractMBeanServerTests {
try {
checkServerConnection(getServer());
} finally {
}
finally {
bean.destroy();
}
}
@ -102,7 +104,8 @@ public class ConnectorServerFactoryBeanTests extends AbstractMBeanServerTests {
// Try to get the connector bean.
ObjectInstance instance = getServer().getObjectInstance(ObjectName.getInstance(OBJECT_NAME));
assertNotNull("ObjectInstance should not be null", instance);
} finally {
}
finally {
bean.destroy();
}
}
@ -116,9 +119,11 @@ public class ConnectorServerFactoryBeanTests extends AbstractMBeanServerTests {
// Try to get the connector bean.
getServer().getObjectInstance(ObjectName.getInstance(OBJECT_NAME));
fail("Instance should not be found");
} catch (InstanceNotFoundException ex) {
}
catch (InstanceNotFoundException ex) {
// expected
} finally {
}
finally {
bean.destroy();
}
}

View File

@ -74,10 +74,12 @@ public class MBeanServerConnectionFactoryBeanTests extends AbstractMBeanServerTe
// perform simple MBean count test
assertEquals("MBean count should be the same", getServer().getMBeanCount(), connection.getMBeanCount());
} finally {
}
finally {
bean.destroy();
}
} finally {
}
finally {
connectorServer.stop();
}
}
@ -104,7 +106,8 @@ public class MBeanServerConnectionFactoryBeanTests extends AbstractMBeanServerTe
connector = getConnectorServer();
connector.start();
assertEquals("Incorrect MBean count", getServer().getMBeanCount(), connection.getMBeanCount());
} finally {
}
finally {
bean.destroy();
if (connector != null) {
connector.stop();

View File

@ -30,7 +30,6 @@ import java.rmi.UnknownHostException;
import java.rmi.UnmarshalException;
import org.aopalliance.intercept.MethodInvocation;
import org.junit.Test;
import org.springframework.remoting.RemoteAccessException;
@ -342,7 +341,7 @@ public class RmiSupportTests {
client.afterPropertiesSet();
fail("url isn't set, expected IllegalArgumentException");
}
catch(IllegalArgumentException e){
catch (IllegalArgumentException ex){
// expected
}
}

View File

@ -41,15 +41,19 @@ public class LazyScheduledTasksBeanDefinitionParserTests {
while (!task.executed) {
try {
Thread.sleep(10);
} catch (Exception e) { /* Do Nothing */ }
}
catch (Exception ex) { /* Do Nothing */ }
}
}
static class Task {
volatile boolean executed = false;
public void doWork() {
executed = true;
}
}
}

View File

@ -58,7 +58,8 @@ public final class AdvisedJRubyScriptFactoryTests {
assertEquals(0, advice.getCalls());
bean.getMessage();
assertEquals(1, advice.getCalls());
} finally {
}
finally {
ctx.close();
}
}
@ -76,7 +77,8 @@ public final class AdvisedJRubyScriptFactoryTests {
assertEquals(0, advice.getCalls());
bean.getMessage();
assertEquals(1, advice.getCalls());
} finally {
}
finally {
ctx.close();
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 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.
@ -127,7 +127,7 @@ public abstract class DigestUtils {
((UpdateMessageDigestInputStream) inputStream).updateMessageDigest(messageDigest);
return messageDigest.digest();
}
else{
else {
return messageDigest.digest(StreamUtils.copyToByteArray(inputStream));
}
}

View File

@ -198,7 +198,7 @@ public class MimeType implements Comparable<MimeType>, Serializable {
* @see <a href="http://tools.ietf.org/html/rfc2616#section-2.2">HTTP 1.1, section 2.2</a>
*/
private void checkToken(String token) {
for (int i=0; i < token.length(); i++ ) {
for (int i = 0; i < token.length(); i++ ) {
char ch = token.charAt(i);
if (!TOKEN.get(ch)) {
throw new IllegalArgumentException("Invalid token character '" + ch + "' in token \"" + token + "\"");

View File

@ -130,7 +130,7 @@ public class GenericTypeResolverTests {
Type t = null;
Type x = null;
for (Map.Entry<TypeVariable, Type> entry : map.entrySet()) {
if(entry.getKey().toString().equals("T")) {
if (entry.getKey().toString().equals("T")) {
t = entry.getValue();
}
else {

View File

@ -111,7 +111,8 @@ public class PropertySourceTests {
equalTo(String.format("%s [name='%s']",
ps.getClass().getSimpleName(),
name)));
} finally {
}
finally {
logger.setLevel(original);
}
}

View File

@ -35,7 +35,8 @@ public class ClassMetadataReadingVisitorMemberClassTests
MetadataReader reader =
new SimpleMetadataReaderFactory().getMetadataReader(clazz.getName());
return reader.getAnnotationMetadata();
} catch (IOException ex) {
}
catch (IOException ex) {
throw new IllegalStateException(ex);
}
}

View File

@ -51,7 +51,7 @@ public class Matchers {
@Override
public boolean matches(Object item) {
Throwable cause = null;
if(item != null && item instanceof Throwable) {
if (item != null && item instanceof Throwable) {
cause = ((Throwable)item).getCause();
}
return matcher.matches(cause);

View File

@ -93,7 +93,8 @@ public enum TestGroup {
for (String group : value.split(",")) {
try {
groups.add(valueOf(group.trim().toUpperCase()));
} catch (IllegalArgumentException e) {
}
catch (IllegalArgumentException ex) {
throw new IllegalArgumentException(format(
"Unable to find test group '%s' when parsing testGroups value: '%s'. " +
"Available groups include: [%s]", group.trim(), value,

View File

@ -74,9 +74,9 @@ public class AutoPopulatingListTests {
private void doTestWithElementFactory(AutoPopulatingList<Object> list) {
doTestWithClass(list);
for(int x = 0; x < list.size(); x++) {
for (int x = 0; x < list.size(); x++) {
Object element = list.get(x);
if(element instanceof TestObject) {
if (element instanceof TestObject) {
assertEquals(x, ((TestObject) element).getAge());
}
}

View File

@ -179,7 +179,7 @@ public class FastByteArrayOutputStreamTests {
public void updateMessageDigestManyBuffers() throws Exception {
StringBuilder builder = new StringBuilder("\"0");
// filling at least one 256 buffer
for( int i=0; i < 30; i++) {
for ( int i = 0; i < 30; i++) {
this.os.write(helloBytes);
}
InputStream inputStream = this.os.getInputStream();

View File

@ -54,7 +54,7 @@ public class ResizableByteArrayOutputStreamTests {
@Test
public void autoGrow() {
assertEquals(INITIAL_CAPACITY, this.baos.capacity());
for(int i = 0; i < 129; i++) {
for (int i = 0; i < 129; i++) {
this.baos.write(0);
}
assertEquals(256, this.baos.capacity());

View File

@ -169,7 +169,8 @@ public class SettableListenableFutureTests {
try {
Thread.sleep(20L);
settableListenableFuture.set(string);
} catch (InterruptedException ex) {
}
catch (InterruptedException ex) {
throw new RuntimeException(ex);
}
}
@ -183,7 +184,8 @@ public class SettableListenableFutureTests {
try {
settableListenableFuture.get(1L, TimeUnit.MILLISECONDS);
fail("Expected TimeoutException");
} catch (TimeoutException ex) {
}
catch (TimeoutException ex) {
// expected
}
}
@ -197,7 +199,8 @@ public class SettableListenableFutureTests {
try {
Thread.sleep(20L);
settableListenableFuture.set(string);
} catch (InterruptedException ex) {
}
catch (InterruptedException ex) {
throw new RuntimeException(ex);
}
}
@ -278,7 +281,8 @@ public class SettableListenableFutureTests {
try {
Thread.sleep(20L);
settableListenableFuture.cancel(true);
} catch (InterruptedException ex) {
}
catch (InterruptedException ex) {
throw new RuntimeException(ex);
}
}
@ -286,7 +290,8 @@ public class SettableListenableFutureTests {
try {
settableListenableFuture.get(100L, TimeUnit.MILLISECONDS);
fail("Expected CancellationException");
} catch (CancellationException ex) {
}
catch (CancellationException ex) {
// expected
}
}

View File

@ -194,8 +194,8 @@ public abstract class AbstractStaxXMLReaderTestCase {
private static class SkipLocatorArgumentsAdapter implements InvocationArgumentsAdapter {
@Override
public Object[] adaptArguments(Object[] arguments) {
for(int i=0; i<arguments.length; i++) {
if(arguments[i] instanceof Locator) {
for (int i = 0; i < arguments.length; i++) {
if (arguments[i] instanceof Locator) {
arguments[i] = null;
}
}
@ -206,7 +206,7 @@ public abstract class AbstractStaxXMLReaderTestCase {
private static class CharArrayToStringAdapter implements InvocationArgumentsAdapter {
@Override
public Object[] adaptArguments(Object[] arguments) {
if(arguments.length == 3 && arguments[0] instanceof char[]
if (arguments.length == 3 && arguments[0] instanceof char[]
&& arguments[1] instanceof Integer && arguments[2] instanceof Integer) {
return new Object[] {new String((char[]) arguments[0], (Integer) arguments[1], (Integer) arguments[2])};
}
@ -218,7 +218,7 @@ public abstract class AbstractStaxXMLReaderTestCase {
@Override
public Object[] adaptArguments(Object[] arguments) {
for (int i = 0; i < arguments.length; i++) {
if(arguments[i] instanceof Attributes) {
if (arguments[i] instanceof Attributes) {
arguments[i] = new PartialAttributes((Attributes) arguments[i]);
}
};

View File

@ -918,7 +918,7 @@ public class CodeFlow implements Opcodes {
*/
public static boolean isReferenceTypeArray(String arraytype) {
int length = arraytype.length();
for (int i=0;i<length;i++) {
for (int i = 0; i < length; i++) {
char ch = arraytype.charAt(i);
if (ch == '[') continue;
return ch=='L';

View File

@ -71,7 +71,8 @@ public class EvaluationTests extends AbstractExpressionTests {
try {
o = parser.parseExpression("list2[3]").getValue(new StandardEvaluationContext(testClass));
fail();
} catch (EvaluationException ee) {
}
catch (EvaluationException ee) {
ee.printStackTrace();
// success!
}
@ -241,7 +242,8 @@ public class EvaluationTests extends AbstractExpressionTests {
try {
new SpelExpressionParser().parseExpression("placeOfBirth.foo.");
fail("Should have failed to parse");
} catch (ParseException e) {
}
catch (ParseException e) {
assertTrue(e instanceof SpelParseException);
SpelParseException spe = (SpelParseException) e;
assertEquals(SpelMessage.OOD, spe.getMessageCode());
@ -265,7 +267,8 @@ public class EvaluationTests extends AbstractExpressionTests {
try {
new SpelExpressionParser().parseRaw("placeOfBirth.23");
fail();
} catch (SpelParseException spe) {
}
catch (SpelParseException spe) {
assertEquals(spe.getMessageCode(), SpelMessage.UNEXPECTED_DATA_AFTER_DOT);
assertEquals("23", spe.getInserts()[0]);
}
@ -554,7 +557,8 @@ public class EvaluationTests extends AbstractExpressionTests {
try {
assertFalse(parser.parseExpression("T(List)!=null").getValue(context, Boolean.class));
fail("should have failed to find List");
} catch (EvaluationException ee) {
}
catch (EvaluationException ee) {
// success - List not found
}
((StandardTypeLocator) context.getTypeLocator()).registerImport("java.util");
@ -633,7 +637,8 @@ public class EvaluationTests extends AbstractExpressionTests {
try {
context.registerMethodFilter(String.class, filter);
fail("should have failed");
} catch (IllegalStateException ise) {
}
catch (IllegalStateException ise) {
assertEquals(
"Method filter cannot be set as the reflective method resolver is not in use",
ise.getMessage());
@ -738,7 +743,8 @@ public class EvaluationTests extends AbstractExpressionTests {
try {
e.getValue(ctx,String.class);
fail();
} catch (SpelEvaluationException see) {
}
catch (SpelEvaluationException see) {
assertEquals(SpelMessage.COLLECTION_INDEX_OUT_OF_BOUNDS,see.getMessageCode());
}
}
@ -754,7 +760,8 @@ public class EvaluationTests extends AbstractExpressionTests {
expression = parser.parseExpression("foo[3]");
try {
expression.setValue(ctx, "3");
} catch(SpelEvaluationException see) {
}
catch (SpelEvaluationException see) {
assertEquals(SpelMessage.UNABLE_TO_GROW_COLLECTION, see.getMessageCode());
assertThat(instance.getFoo().size(), equalTo(3));
}
@ -771,7 +778,8 @@ public class EvaluationTests extends AbstractExpressionTests {
try {
e.getValue(ctx,Integer.class);
fail();
} catch (SpelEvaluationException see) {
}
catch (SpelEvaluationException see) {
assertEquals(SpelMessage.NOT_ASSIGNABLE,see.getMessageCode());
}
}
@ -894,7 +902,8 @@ public class EvaluationTests extends AbstractExpressionTests {
try {
e.getValue(ctx,Double.TYPE);
fail();
} catch (SpelEvaluationException see) {
}
catch (SpelEvaluationException see) {
assertEquals(SpelMessage.OPERAND_NOT_INCREMENTABLE,see.getMessageCode());
}
@ -902,7 +911,8 @@ public class EvaluationTests extends AbstractExpressionTests {
try {
e.getValue(ctx,Double.TYPE);
fail();
} catch (SpelEvaluationException see) {
}
catch (SpelEvaluationException see) {
assertEquals(SpelMessage.OPERAND_NOT_INCREMENTABLE,see.getMessageCode());
}
}
@ -917,14 +927,16 @@ public class EvaluationTests extends AbstractExpressionTests {
Expression e = parser.parseExpression("++1");
e.getValue(ctx,Integer.class);
fail();
} catch (SpelEvaluationException see) {
}
catch (SpelEvaluationException see) {
assertEquals(SpelMessage.NOT_ASSIGNABLE,see.getMessageCode());
}
try {
Expression e = parser.parseExpression("1++");
e.getValue(ctx,Integer.class);
fail();
} catch (SpelEvaluationException see) {
}
catch (SpelEvaluationException see) {
assertEquals(SpelMessage.NOT_ASSIGNABLE,see.getMessageCode());
}
}
@ -938,7 +950,8 @@ public class EvaluationTests extends AbstractExpressionTests {
try {
e.getValue(ctx,Integer.class);
fail();
} catch (SpelEvaluationException see) {
}
catch (SpelEvaluationException see) {
assertEquals(SpelMessage.NOT_ASSIGNABLE,see.getMessageCode());
}
}
@ -1060,7 +1073,8 @@ public class EvaluationTests extends AbstractExpressionTests {
try {
e.getValue(ctx,Double.TYPE);
fail();
} catch (SpelEvaluationException see) {
}
catch (SpelEvaluationException see) {
assertEquals(SpelMessage.OPERAND_NOT_DECREMENTABLE,see.getMessageCode());
}
@ -1068,7 +1082,8 @@ public class EvaluationTests extends AbstractExpressionTests {
try {
e.getValue(ctx,Double.TYPE);
fail();
} catch (SpelEvaluationException see) {
}
catch (SpelEvaluationException see) {
assertEquals(SpelMessage.OPERAND_NOT_DECREMENTABLE,see.getMessageCode());
}
}
@ -1083,14 +1098,16 @@ public class EvaluationTests extends AbstractExpressionTests {
Expression e = parser.parseExpression("--1");
e.getValue(ctx,Integer.class);
fail();
} catch (SpelEvaluationException see) {
}
catch (SpelEvaluationException see) {
assertEquals(SpelMessage.NOT_ASSIGNABLE,see.getMessageCode());
}
try {
Expression e = parser.parseExpression("1--");
e.getValue(ctx,Integer.class);
fail();
} catch (SpelEvaluationException see) {
}
catch (SpelEvaluationException see) {
assertEquals(SpelMessage.NOT_ASSIGNABLE,see.getMessageCode());
}
}
@ -1123,36 +1140,6 @@ public class EvaluationTests extends AbstractExpressionTests {
}
private void expectFail(ExpressionParser parser, EvaluationContext eContext, String expressionString, SpelMessage messageCode) {
try {
Expression e = parser.parseExpression(expressionString);
SpelUtilities.printAbstractSyntaxTree(System.out, e);
e.getValue(eContext);
fail();
} catch (SpelEvaluationException see) {
see.printStackTrace();
assertEquals(messageCode,see.getMessageCode());
}
}
private void expectFailNotAssignable(ExpressionParser parser, EvaluationContext eContext, String expressionString) {
expectFail(parser,eContext,expressionString,SpelMessage.NOT_ASSIGNABLE);
}
private void expectFailSetValueNotSupported(ExpressionParser parser, EvaluationContext eContext, String expressionString) {
expectFail(parser,eContext,expressionString,SpelMessage.SETVALUE_NOT_SUPPORTED);
}
private void expectFailNotIncrementable(ExpressionParser parser, EvaluationContext eContext, String expressionString) {
expectFail(parser,eContext,expressionString,SpelMessage.OPERAND_NOT_INCREMENTABLE);
}
private void expectFailNotDecrementable(ExpressionParser parser, EvaluationContext eContext, String expressionString) {
expectFail(parser,eContext,expressionString,SpelMessage.OPERAND_NOT_DECREMENTABLE);
}
// Verify how all the nodes behave with assignment (++, --, =)
@Test
public void incrementAllNodeTypes() throws SecurityException, NoSuchMethodException {
@ -1456,9 +1443,39 @@ public class EvaluationTests extends AbstractExpressionTests {
r = e.getValue(ctx,Integer.TYPE);
assertEquals(100,r);
assertEquals(100,helper.iii);
}
private void expectFail(ExpressionParser parser, EvaluationContext eContext, String expressionString, SpelMessage messageCode) {
try {
Expression e = parser.parseExpression(expressionString);
SpelUtilities.printAbstractSyntaxTree(System.out, e);
e.getValue(eContext);
fail();
}
catch (SpelEvaluationException see) {
see.printStackTrace();
assertEquals(messageCode,see.getMessageCode());
}
}
private void expectFailNotAssignable(ExpressionParser parser, EvaluationContext eContext, String expressionString) {
expectFail(parser,eContext,expressionString,SpelMessage.NOT_ASSIGNABLE);
}
private void expectFailSetValueNotSupported(ExpressionParser parser, EvaluationContext eContext, String expressionString) {
expectFail(parser,eContext,expressionString,SpelMessage.SETVALUE_NOT_SUPPORTED);
}
private void expectFailNotIncrementable(ExpressionParser parser, EvaluationContext eContext, String expressionString) {
expectFail(parser,eContext,expressionString,SpelMessage.OPERAND_NOT_INCREMENTABLE);
}
private void expectFailNotDecrementable(ExpressionParser parser, EvaluationContext eContext, String expressionString) {
expectFail(parser,eContext,expressionString,SpelMessage.OPERAND_NOT_DECREMENTABLE);
}
static class MyBeanResolver implements BeanResolver {
@Override
@ -1472,5 +1489,4 @@ public class EvaluationTests extends AbstractExpressionTests {
}
}

View File

@ -79,10 +79,12 @@ public class ExpressionLanguageScenarioTests extends AbstractExpressionTests {
assertEquals("hello world", value);
assertEquals(String.class, value.getClass());
} catch (EvaluationException ee) {
}
catch (EvaluationException ee) {
ee.printStackTrace();
fail("Unexpected Exception: " + ee.getMessage());
} catch (ParseException pe) {
}
catch (ParseException pe) {
pe.printStackTrace();
fail("Unexpected Exception: " + pe.getMessage());
}
@ -186,10 +188,12 @@ public class ExpressionLanguageScenarioTests extends AbstractExpressionTests {
Object value = expr.getValue(ctx);
assertEquals("hellohello", value);
} catch (EvaluationException ee) {
}
catch (EvaluationException ee) {
ee.printStackTrace();
fail("Unexpected Exception: " + ee.getMessage());
} catch (ParseException pe) {
}
catch (ParseException pe) {
pe.printStackTrace();
fail("Unexpected Exception: " + pe.getMessage());
}
@ -213,7 +217,8 @@ public class ExpressionLanguageScenarioTests extends AbstractExpressionTests {
try {
expr.setValue(ctx, Color.blue);
fail("Should not be allowed to set oranges to be blue !");
} catch (SpelEvaluationException ee) {
}
catch (SpelEvaluationException ee) {
assertEquals(ee.getMessageCode(), SpelMessage.PROPERTY_OR_FIELD_NOT_WRITABLE_ON_NULL);
}
}

View File

@ -140,7 +140,8 @@ public class ExpressionStateTests extends AbstractExpressionTests {
try {
state.popActiveContextObject();
fail("stack should be empty...");
} catch (EmptyStackException ese) {
}
catch (EmptyStackException ese) {
// success
}
@ -221,7 +222,8 @@ public class ExpressionStateTests extends AbstractExpressionTests {
try {
state.operate(Operation.ADD,1,2);
fail("should have failed");
} catch (EvaluationException ee) {
}
catch (EvaluationException ee) {
SpelEvaluationException sEx = (SpelEvaluationException)ee;
assertEquals(SpelMessage.OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES,sEx.getMessageCode());
}
@ -229,7 +231,8 @@ public class ExpressionStateTests extends AbstractExpressionTests {
try {
state.operate(Operation.ADD,null,null);
fail("should have failed");
} catch (EvaluationException ee) {
}
catch (EvaluationException ee) {
SpelEvaluationException sEx = (SpelEvaluationException)ee;
assertEquals(SpelMessage.OPERATOR_NOT_SUPPORTED_BETWEEN_TYPES,sEx.getMessageCode());
}
@ -249,7 +252,8 @@ public class ExpressionStateTests extends AbstractExpressionTests {
try {
state.findType("someMadeUpName");
fail("Should have failed to find it");
} catch (EvaluationException ee) {
}
catch (EvaluationException ee) {
SpelEvaluationException sEx = (SpelEvaluationException)ee;
assertEquals(SpelMessage.TYPE_NOT_FOUND,sEx.getMessageCode());
}

View File

@ -191,8 +191,9 @@ public class IndexingTests {
expression = parser.parseExpression("property[0]");
try {
expression.setValue(this, "4");
} catch (EvaluationException e) {
assertTrue(e.getMessage().startsWith("EL1053E"));
}
catch (EvaluationException ex) {
assertTrue(ex.getMessage().startsWith("EL1053E"));
}
}
@ -251,8 +252,9 @@ public class IndexingTests {
expression = parser.parseExpression("property[0]");
try {
assertEquals("bar", expression.getValue(this));
} catch (EvaluationException e) {
assertTrue(e.getMessage().startsWith("EL1027E"));
}
catch (EvaluationException ex) {
assertTrue(ex.getMessage().startsWith("EL1027E"));
}
}
@ -268,8 +270,9 @@ public class IndexingTests {
expression = parser.parseExpression("property[0]");
try {
assertEquals("bar", expression.getValue(this));
} catch (EvaluationException e) {
assertTrue(e.getMessage().startsWith("EL1053E"));
}
catch (EvaluationException ex) {
assertTrue(ex.getMessage().startsWith("EL1053E"));
}
}
@ -285,8 +288,9 @@ public class IndexingTests {
expression = parser.parseExpression("property2[0]");
try {
assertEquals("bar", expression.getValue(this));
} catch (EvaluationException e) {
assertTrue(e.getMessage().startsWith("EL1053E"));
}
catch (EvaluationException ex) {
assertTrue(ex.getMessage().startsWith("EL1053E"));
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2016 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.
@ -33,29 +33,6 @@ import static org.junit.Assert.*;
*/
public class OperatorOverloaderTests extends AbstractExpressionTests {
static class StringAndBooleanAddition implements OperatorOverloader {
@Override
public Object operate(Operation operation, Object leftOperand, Object rightOperand) throws EvaluationException {
if (operation==Operation.ADD) {
return ((String)leftOperand)+((Boolean)rightOperand).toString();
} else {
return leftOperand;
}
}
@Override
public boolean overridesOperation(Operation operation, Object leftOperand, Object rightOperand)
throws EvaluationException {
if (leftOperand instanceof String && rightOperand instanceof Boolean) {
return true;
}
return false;
}
}
@Test
public void testSimpleOperations() throws Exception {
// no built in support for this:
@ -73,4 +50,28 @@ public class OperatorOverloaderTests extends AbstractExpressionTests {
expr = (SpelExpression)parser.parseExpression("'abc'+null");
assertEquals("abcnull",expr.getValue(eContext));
}
static class StringAndBooleanAddition implements OperatorOverloader {
@Override
public Object operate(Operation operation, Object leftOperand, Object rightOperand) throws EvaluationException {
if (operation==Operation.ADD) {
return ((String)leftOperand)+((Boolean)rightOperand).toString();
}
else {
return leftOperand;
}
}
@Override
public boolean overridesOperation(Operation operation, Object leftOperand, Object rightOperand) throws EvaluationException {
if (leftOperand instanceof String && rightOperand instanceof Boolean) {
return true;
}
return false;
}
}
}

View File

@ -462,7 +462,8 @@ public class ParsingTests {
fail("Parsed exception was null");
}
assertEquals("String form of AST does not match expected output", expectedStringFormOfAST, e.toStringAST());
} catch (ParseException ee) {
}
catch (ParseException ee) {
ee.printStackTrace();
fail("Unexpected Exception: " + ee.getMessage());
}

View File

@ -78,15 +78,17 @@ public class PropertyAccessTests extends AbstractExpressionTests {
try {
expr.getValue(context);
fail("Should have failed - default property resolver cannot resolve on null");
} catch (Exception e) {
checkException(e,SpelMessage.PROPERTY_OR_FIELD_NOT_READABLE_ON_NULL);
}
catch (Exception ex) {
checkException(ex, SpelMessage.PROPERTY_OR_FIELD_NOT_READABLE_ON_NULL);
}
assertFalse(expr.isWritable(context));
try {
expr.setValue(context,"abc");
fail("Should have failed - default property resolver cannot resolve on null");
} catch (Exception e) {
checkException(e,SpelMessage.PROPERTY_OR_FIELD_NOT_WRITABLE_ON_NULL);
}
catch (Exception ex) {
checkException(ex, SpelMessage.PROPERTY_OR_FIELD_NOT_WRITABLE_ON_NULL);
}
}
@ -94,7 +96,8 @@ public class PropertyAccessTests extends AbstractExpressionTests {
if (e instanceof SpelEvaluationException) {
SpelMessage sm = ((SpelEvaluationException)e).getMessageCode();
assertEquals("Expected exception type did not occur",expectedMessage,sm);
} else {
}
else {
fail("Should be a SpelException "+e);
}
}
@ -127,7 +130,8 @@ public class PropertyAccessTests extends AbstractExpressionTests {
try {
expr.setValue(ctx, "not allowed");
fail("Should not have been allowed");
} catch (EvaluationException e) {
}
catch (EvaluationException ex) {
// success - message will be: EL1063E:(pos 20): A problem occurred whilst attempting to set the property
// 'flibbles': 'Cannot set flibbles to an object of type 'class java.lang.String''
// System.out.println(e.getMessage());
@ -171,38 +175,42 @@ public class PropertyAccessTests extends AbstractExpressionTests {
@Override
public Class<?>[] getSpecificTargetClasses() {
return new Class[] { String.class };
return new Class[] {String.class};
}
@Override
public boolean canRead(EvaluationContext context, Object target, String name) throws AccessException {
if (!(target instanceof String))
if (!(target instanceof String)) {
throw new RuntimeException("Assertion Failed! target should be String");
}
return (name.equals("flibbles"));
}
@Override
public boolean canWrite(EvaluationContext context, Object target, String name) throws AccessException {
if (!(target instanceof String))
if (!(target instanceof String)) {
throw new RuntimeException("Assertion Failed! target should be String");
}
return (name.equals("flibbles"));
}
@Override
public TypedValue read(EvaluationContext context, Object target, String name) throws AccessException {
if (!name.equals("flibbles"))
if (!name.equals("flibbles")) {
throw new RuntimeException("Assertion Failed! name should be flibbles");
}
return new TypedValue(flibbles);
}
@Override
public void write(EvaluationContext context, Object target, String name, Object newValue)
throws AccessException {
if (!name.equals("flibbles"))
public void write(EvaluationContext context, Object target, String name, Object newValue) throws AccessException {
if (!name.equals("flibbles")) {
throw new RuntimeException("Assertion Failed! name should be flibbles");
}
try {
flibbles = (Integer) context.getTypeConverter().convertValue(newValue, TypeDescriptor.forObject(newValue), TypeDescriptor.valueOf(Integer.class));
}catch (EvaluationException e) {
}
catch (EvaluationException ex) {
throw new AccessException("Cannot set flibbles to an object of type '" + newValue.getClass() + "'");
}
}

View File

@ -61,7 +61,8 @@ public class ScenariosForSpringSecurity extends AbstractExpressionTests {
value = expr.getValue(ctx,Boolean.class);
assertTrue(value);
} catch (EvaluationException ee) {
}
catch (EvaluationException ee) {
ee.printStackTrace();
fail("Unexpected SpelException: " + ee.getMessage());
}
@ -160,10 +161,10 @@ public class ScenariosForSpringSecurity extends AbstractExpressionTests {
public String[] getRoles() { return new String[]{"NONE"}; }
public boolean hasAnyRole(String... roles) {
if (roles==null) return true;
if (roles == null) return true;
String[] myRoles = getRoles();
for (int i=0;i<myRoles.length;i++) {
for (int j=0;j<roles.length;j++) {
for (int i = 0; i < myRoles.length; i++) {
for (int j = 0; j < roles.length; j++) {
if (myRoles[i].equals(roles[j])) return true;
}
}

View File

@ -428,7 +428,8 @@ public class SelectionAndProjectionTests {
for (int i = 0; i < 3; i++) {
if (i == 1) {
array[i] = new IntegerTestBean(5.9f);
} else {
}
else {
array[i] = new IntegerTestBean(i + 5);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 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.
@ -39,6 +39,7 @@ public class SetValueTests extends AbstractExpressionTests {
private final static boolean DEBUG = false;
@Test
public void testSetProperty() {
setValue("wonNobelPrize", true);
@ -90,7 +91,8 @@ public class SetValueTests extends AbstractExpressionTests {
try {
assertFalse("Should not be writable!",e.isWritable(lContext));
fail("Should have had an error because wibble does not really exist");
} catch (SpelEvaluationException see) {
}
catch (SpelEvaluationException see) {
// org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 15): Property or field 'wibble' cannot be found on object of type 'org.springframework.expression.spel.testresources.ArrayContainer' - maybe not public?
// at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:225)
// success!
@ -110,7 +112,8 @@ public class SetValueTests extends AbstractExpressionTests {
try {
assertFalse("Should not be writable!",e.isWritable(lContext));
fail("Should have had an error because wibble does not really exist");
} catch (SpelEvaluationException see) {
}
catch (SpelEvaluationException see) {
// success!
}
@ -119,7 +122,8 @@ public class SetValueTests extends AbstractExpressionTests {
try {
assertFalse("Should not be writable!",e.isWritable(lContext));
fail("Should have had an error because wibble does not really exist");
} catch (SpelEvaluationException see) {
}
catch (SpelEvaluationException see) {
// success!
}
}
@ -247,10 +251,12 @@ public class SetValueTests extends AbstractExpressionTests {
StandardEvaluationContext lContext = TestScenarioCreator.getTestEvaluationContext();
e.setValue(lContext, value);
fail("expected an error");
} catch (ParseException pe) {
}
catch (ParseException pe) {
pe.printStackTrace();
fail("Unexpected Exception: " + pe.getMessage());
} catch (EvaluationException ee) {
}
catch (EvaluationException ee) {
// success!
}
}
@ -268,10 +274,12 @@ public class SetValueTests extends AbstractExpressionTests {
assertTrue("Expression is not writeable but should be", e.isWritable(lContext));
e.setValue(lContext, value);
assertEquals("Retrieved value was not equal to set value", value, e.getValue(lContext,value.getClass()));
} catch (EvaluationException ee) {
}
catch (EvaluationException ee) {
ee.printStackTrace();
fail("Unexpected Exception: " + ee.getMessage());
} catch (ParseException pe) {
}
catch (ParseException pe) {
pe.printStackTrace();
fail("Unexpected Exception: " + pe.getMessage());
}
@ -299,12 +307,15 @@ public class SetValueTests extends AbstractExpressionTests {
fail("Not the same: ["+a+"] type="+a.getClass()+" ["+b+"] type="+b.getClass());
// assertEquals("Retrieved value was not equal to set value", expectedValue, e.getValue(lContext));
}
} catch (EvaluationException ee) {
}
catch (EvaluationException ee) {
ee.printStackTrace();
fail("Unexpected Exception: " + ee.getMessage());
} catch (ParseException pe) {
}
catch (ParseException pe) {
pe.printStackTrace();
fail("Unexpected Exception: " + pe.getMessage());
}
}
}

View File

@ -4267,7 +4267,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
// // time it interpreted
// long stime = System.currentTimeMillis();
// for (int i=0;i<100000;i++) {
// for (int i = 0;i<100000;i++) {
// v = expression.getValue(ctx,holder);
// }
// System.out.println((System.currentTimeMillis()-stime));
@ -4278,7 +4278,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
//
// // time it compiled
// stime = System.currentTimeMillis();
// for (int i=0;i<100000;i++) {
// for (int i = 0;i<100000;i++) {
// v = expression.getValue(ctx,holder);
// }
// System.out.println((System.currentTimeMillis()-stime));
@ -5014,7 +5014,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests {
public void reset() {
i = 0;
_i=0;
_i = 0;
s = null;
_s = null;
field = null;

View File

@ -1,5 +1,5 @@
/*
* Copyright 2015 the original author or authors.
* Copyright 2002-2016 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.
@ -79,80 +79,80 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
assertEquals(2d,o);
System.out.println("Performance check for SpEL expression: '(T(Integer).valueOf(payload).doubleValue())/18D'");
long stime = System.currentTimeMillis();
for (int i=0;i<1000000;i++) {
for (int i = 0; i < 1000000; i++) {
o = expression.getValue(nh);
}
System.out.println("One million iterations: "+(System.currentTimeMillis()-stime)+"ms");
System.out.println("One million iterations: " + (System.currentTimeMillis()-stime) + "ms");
stime = System.currentTimeMillis();
for (int i=0;i<1000000;i++) {
for (int i = 0; i < 1000000; i++) {
o = expression.getValue(nh);
}
System.out.println("One million iterations: "+(System.currentTimeMillis()-stime)+"ms");
System.out.println("One million iterations: " + (System.currentTimeMillis()-stime) + "ms");
stime = System.currentTimeMillis();
for (int i=0;i<1000000;i++) {
for (int i = 0; i < 1000000; i++) {
o = expression.getValue(nh);
}
System.out.println("One million iterations: "+(System.currentTimeMillis()-stime)+"ms");
System.out.println("One million iterations: " + (System.currentTimeMillis()-stime) + "ms");
compile(expression);
System.out.println("Now compiled:");
o = expression.getValue(nh);
assertEquals(2d, o);
stime = System.currentTimeMillis();
for (int i=0;i<1000000;i++) {
for (int i = 0; i < 1000000; i++) {
o = expression.getValue(nh);
}
System.out.println("One million iterations: "+(System.currentTimeMillis()-stime)+"ms");
System.out.println("One million iterations: " + (System.currentTimeMillis()-stime) + "ms");
stime = System.currentTimeMillis();
for (int i=0;i<1000000;i++) {
for (int i = 0; i < 1000000; i++) {
o = expression.getValue(nh);
}
System.out.println("One million iterations: "+(System.currentTimeMillis()-stime)+"ms");
System.out.println("One million iterations: " + (System.currentTimeMillis()-stime) + "ms");
stime = System.currentTimeMillis();
for (int i=0;i<1000000;i++) {
for (int i = 0; i < 1000000; i++) {
o = expression.getValue(nh);
}
System.out.println("One million iterations: "+(System.currentTimeMillis()-stime)+"ms");
System.out.println("One million iterations: " + (System.currentTimeMillis()-stime) + "ms");
expression = parser.parseExpression("payload/18D");
o = expression.getValue(nh);
assertEquals(2d,o);
System.out.println("Performance check for SpEL expression: 'payload/18D'");
stime = System.currentTimeMillis();
for (int i=0;i<1000000;i++) {
for (int i = 0; i < 1000000; i++) {
o = expression.getValue(nh);
}
System.out.println("One million iterations: "+(System.currentTimeMillis()-stime)+"ms");
System.out.println("One million iterations: " + (System.currentTimeMillis()-stime) + "ms");
stime = System.currentTimeMillis();
for (int i=0;i<1000000;i++) {
for (int i = 0; i < 1000000; i++) {
o = expression.getValue(nh);
}
System.out.println("One million iterations: "+(System.currentTimeMillis()-stime)+"ms");
System.out.println("One million iterations: " + (System.currentTimeMillis()-stime) + "ms");
stime = System.currentTimeMillis();
for (int i=0;i<1000000;i++) {
for (int i = 0; i < 1000000; i++) {
o = expression.getValue(nh);
}
System.out.println("One million iterations: "+(System.currentTimeMillis()-stime)+"ms");
System.out.println("One million iterations: " + (System.currentTimeMillis()-stime) + "ms");
compile(expression);
System.out.println("Now compiled:");
o = expression.getValue(nh);
assertEquals(2d, o);
stime = System.currentTimeMillis();
for (int i=0;i<1000000;i++) {
for (int i = 0; i < 1000000; i++) {
o = expression.getValue(nh);
}
System.out.println("One million iterations: "+(System.currentTimeMillis()-stime)+"ms");
System.out.println("One million iterations: " + (System.currentTimeMillis()-stime) + "ms");
stime = System.currentTimeMillis();
for (int i=0;i<1000000;i++) {
for (int i = 0; i < 1000000; i++) {
o = expression.getValue(nh);
}
System.out.println("One million iterations: "+(System.currentTimeMillis()-stime)+"ms");
System.out.println("One million iterations: " + (System.currentTimeMillis()-stime) + "ms");
stime = System.currentTimeMillis();
for (int i=0;i<1000000;i++) {
for (int i = 0; i < 1000000; i++) {
o = expression.getValue(nh);
}
System.out.println("One million iterations: "+(System.currentTimeMillis()-stime)+"ms");
System.out.println("One million iterations: " + (System.currentTimeMillis()-stime) + "ms");
}
@Test
@ -162,40 +162,40 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
assertEquals("bc",o);
System.out.println("Performance check for SpEL expression: '{'abcde','ijklm'}[0].substring({1,3,4}[0],{1,3,4}[1])'");
long stime = System.currentTimeMillis();
for (int i=0;i<1000000;i++) {
for (int i = 0; i < 1000000; i++) {
o = expression.getValue();
}
System.out.println("One million iterations: "+(System.currentTimeMillis()-stime)+"ms");
System.out.println("One million iterations: " + (System.currentTimeMillis()-stime) + "ms");
stime = System.currentTimeMillis();
for (int i=0;i<1000000;i++) {
for (int i = 0; i < 1000000; i++) {
o = expression.getValue();
}
System.out.println("One million iterations: "+(System.currentTimeMillis()-stime)+"ms");
System.out.println("One million iterations: " + (System.currentTimeMillis()-stime) + "ms");
stime = System.currentTimeMillis();
for (int i=0;i<1000000;i++) {
for (int i = 0; i < 1000000; i++) {
o = expression.getValue();
}
System.out.println("One million iterations: "+(System.currentTimeMillis()-stime)+"ms");
System.out.println("One million iterations: " + (System.currentTimeMillis()-stime) + "ms");
compile(expression);
System.out.println("Now compiled:");
o = expression.getValue();
assertEquals("bc", o);
stime = System.currentTimeMillis();
for (int i=0;i<1000000;i++) {
for (int i = 0; i < 1000000; i++) {
o = expression.getValue();
}
System.out.println("One million iterations: "+(System.currentTimeMillis()-stime)+"ms");
System.out.println("One million iterations: " + (System.currentTimeMillis()-stime) + "ms");
stime = System.currentTimeMillis();
for (int i=0;i<1000000;i++) {
for (int i = 0; i < 1000000; i++) {
o = expression.getValue();
}
System.out.println("One million iterations: "+(System.currentTimeMillis()-stime)+"ms");
System.out.println("One million iterations: " + (System.currentTimeMillis()-stime) + "ms");
stime = System.currentTimeMillis();
for (int i=0;i<1000000;i++) {
for (int i = 0; i < 1000000; i++) {
o = expression.getValue();
}
System.out.println("One million iterations: "+(System.currentTimeMillis()-stime)+"ms");
System.out.println("One million iterations: " + (System.currentTimeMillis()-stime) + "ms");
}
@Test
@ -205,40 +205,40 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
assertEquals("jk",o);
System.out.println("Performance check for SpEL expression: '{'abcde','ijklm'}[0].substring({1,3,4}[0],{1,3,4}[1])'");
long stime = System.currentTimeMillis();
for (int i=0;i<1000000;i++) {
for (int i = 0; i < 1000000; i++) {
o = expression.getValue();
}
System.out.println("One million iterations: "+(System.currentTimeMillis()-stime)+"ms");
System.out.println("One million iterations: " + (System.currentTimeMillis()-stime) + "ms");
stime = System.currentTimeMillis();
for (int i=0;i<1000000;i++) {
for (int i = 0; i < 1000000; i++) {
o = expression.getValue();
}
System.out.println("One million iterations: "+(System.currentTimeMillis()-stime)+"ms");
System.out.println("One million iterations: " + (System.currentTimeMillis()-stime) + "ms");
stime = System.currentTimeMillis();
for (int i=0;i<1000000;i++) {
for (int i = 0; i < 1000000; i++) {
o = expression.getValue();
}
System.out.println("One million iterations: "+(System.currentTimeMillis()-stime)+"ms");
System.out.println("One million iterations: " + (System.currentTimeMillis()-stime) + "ms");
compile(expression);
System.out.println("Now compiled:");
o = expression.getValue();
assertEquals("jk", o);
stime = System.currentTimeMillis();
for (int i=0;i<1000000;i++) {
for (int i = 0; i < 1000000; i++) {
o = expression.getValue();
}
System.out.println("One million iterations: "+(System.currentTimeMillis()-stime)+"ms");
System.out.println("One million iterations: " + (System.currentTimeMillis()-stime) + "ms");
stime = System.currentTimeMillis();
for (int i=0;i<1000000;i++) {
for (int i = 0; i < 1000000; i++) {
o = expression.getValue();
}
System.out.println("One million iterations: "+(System.currentTimeMillis()-stime)+"ms");
System.out.println("One million iterations: " + (System.currentTimeMillis()-stime) + "ms");
stime = System.currentTimeMillis();
for (int i=0;i<1000000;i++) {
for (int i = 0; i < 1000000; i++) {
o = expression.getValue();
}
System.out.println("One million iterations: "+(System.currentTimeMillis()-stime)+"ms");
System.out.println("One million iterations: " + (System.currentTimeMillis()-stime) + "ms");
}
@ -251,40 +251,40 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
System.out.println("Performance check for SpEL expression: 'hello' + getWorld() + ' spring'");
long stime = System.currentTimeMillis();
for (int i=0;i<1000000;i++) {
for (int i = 0; i < 1000000; i++) {
o = expression.getValue(g);
}
System.out.println("One million iterations: "+(System.currentTimeMillis()-stime)+"ms");
System.out.println("One million iterations: " + (System.currentTimeMillis()-stime) + "ms");
stime = System.currentTimeMillis();
for (int i=0;i<1000000;i++) {
for (int i = 0; i < 1000000; i++) {
o = expression.getValue(g);
}
System.out.println("One million iterations: "+(System.currentTimeMillis()-stime)+"ms");
System.out.println("One million iterations: " + (System.currentTimeMillis()-stime) + "ms");
stime = System.currentTimeMillis();
for (int i=0;i<1000000;i++) {
for (int i = 0; i < 1000000; i++) {
o = expression.getValue(g);
}
System.out.println("One million iterations: "+(System.currentTimeMillis()-stime)+"ms");
System.out.println("One million iterations: " + (System.currentTimeMillis()-stime) + "ms");
compile(expression);
System.out.println("Now compiled:");
o = expression.getValue(g);
assertEquals("helloworld spring", o);
stime = System.currentTimeMillis();
for (int i=0;i<1000000;i++) {
for (int i = 0; i < 1000000; i++) {
o = expression.getValue(g);
}
System.out.println("One million iterations: "+(System.currentTimeMillis()-stime)+"ms");
System.out.println("One million iterations: " + (System.currentTimeMillis()-stime) + "ms");
stime = System.currentTimeMillis();
for (int i=0;i<1000000;i++) {
for (int i = 0; i < 1000000; i++) {
o = expression.getValue(g);
}
System.out.println("One million iterations: "+(System.currentTimeMillis()-stime)+"ms");
System.out.println("One million iterations: " + (System.currentTimeMillis()-stime) + "ms");
stime = System.currentTimeMillis();
for (int i=0;i<1000000;i++) {
for (int i = 0; i < 1000000; i++) {
o = expression.getValue(g);
}
System.out.println("One million iterations: "+(System.currentTimeMillis()-stime)+"ms");
System.out.println("One million iterations: " + (System.currentTimeMillis()-stime) + "ms");
}
public static class Greeter {
@ -301,15 +301,15 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
long iTotal = 0,cTotal = 0;
// warmup
for (int i=0;i<count;i++) {
b = expression.getValue(payload,Boolean.TYPE);
for (int i = 0; i < count; i++) {
b = expression.getValue(payload, Boolean.TYPE);
}
log("timing interpreted: ");
for (int iter=0;iter<iterations;iter++) {
for (int i = 0; i < iterations; i++) {
long stime = System.currentTimeMillis();
for (int i=0;i<count;i++) {
b = expression.getValue(payload,Boolean.TYPE);
for (int j = 0; j < count; j++) {
b = expression.getValue(payload, Boolean.TYPE);
}
long etime = System.currentTimeMillis();
long interpretedSpeed = (etime - stime);
@ -320,12 +320,12 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
compile(expression);
boolean bc = false;
expression.getValue(payload,Boolean.TYPE);
expression.getValue(payload, Boolean.TYPE);
log("timing compiled: ");
for (int iter=0;iter<iterations;iter++) {
for (int i = 0; i < iterations; i++) {
long stime = System.currentTimeMillis();
for (int i=0;i<count;i++) {
bc = expression.getValue(payload,Boolean.TYPE);
for (int j = 0; j < count; j++) {
bc = expression.getValue(payload, Boolean.TYPE);
}
long etime = System.currentTimeMillis();
long compiledSpeed = (etime - stime);
@ -340,11 +340,11 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
assertFalse(b);
// Verify the same result for compiled vs interpreted
assertEquals(b,bc);
assertEquals(b, bc);
// Verify if the input changes, the result changes
payload.DR[0].DRFixedSection.duration = 0.04d;
bc = expression.getValue(payload,Boolean.TYPE);
bc = expression.getValue(payload, Boolean.TYPE);
assertTrue(bc);
}
@ -364,15 +364,15 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
Expression expression = parser.parseExpression("hello()");
// warmup
for (int i=0;i<count;i++) {
interpretedResult = expression.getValue(testdata,String.class);
for (int i = 0; i < count; i++) {
interpretedResult = expression.getValue(testdata, String.class);
}
log("timing interpreted: ");
for (int iter=0;iter<iterations;iter++) {
for (int i = 0; i < iterations; i++) {
stime = System.currentTimeMillis();
for (int i=0;i<count;i++) {
interpretedResult = expression.getValue(testdata,String.class);
for (int j = 0; j < count; j++) {
interpretedResult = expression.getValue(testdata, String.class);
}
etime = System.currentTimeMillis();
long interpretedSpeed = (etime - stime);
@ -384,11 +384,11 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
compile(expression);
log("timing compiled: ");
expression.getValue(testdata,String.class);
for (int iter=0;iter<iterations;iter++) {
expression.getValue(testdata, String.class);
for (int i = 0; i < iterations; i++) {
stime = System.currentTimeMillis();
for (int i=0;i<count;i++) {
compiledResult = expression.getValue(testdata,String.class);
for (int j = 0; j < count; j++) {
compiledResult = expression.getValue(testdata, String.class);
}
etime = System.currentTimeMillis();
long compiledSpeed = (etime - stime);
@ -438,15 +438,15 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
Expression expression = parser.parseExpression("name");
// warmup
for (int i=0;i<count;i++) {
expression.getValue(testdata,String.class);
for (int i = 0; i < count; i++) {
expression.getValue(testdata, String.class);
}
log("timing interpreted: ");
for (int iter=0;iter<iterations;iter++) {
for (int i = 0; i < iterations; i++) {
stime = System.currentTimeMillis();
for (int i=0;i<count;i++) {
interpretedResult = expression.getValue(testdata,String.class);
for (int j = 0; j < count; j++) {
interpretedResult = expression.getValue(testdata, String.class);
}
etime = System.currentTimeMillis();
long interpretedSpeed = (etime - stime);
@ -458,11 +458,11 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
compile(expression);
log("timing compiled: ");
expression.getValue(testdata,String.class);
for (int iter=0;iter<iterations;iter++) {
expression.getValue(testdata, String.class);
for (int i = 0; i < iterations; i++) {
stime = System.currentTimeMillis();
for (int i=0;i<count;i++) {
compiledResult = expression.getValue(testdata,String.class);
for (int j = 0; j < count; j++) {
compiledResult = expression.getValue(testdata, String.class);
}
etime = System.currentTimeMillis();
long compiledSpeed = (etime - stime);
@ -485,15 +485,15 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
Expression expression = parser.parseExpression("foo.bar.boo");
// warmup
for (int i=0;i<count;i++) {
expression.getValue(testdata,String.class);
for (int i = 0; i < count; i++) {
expression.getValue(testdata, String.class);
}
log("timing interpreted: ");
for (int iter=0;iter<iterations;iter++) {
for (int i = 0; i < iterations; i++) {
stime = System.currentTimeMillis();
for (int i=0;i<count;i++) {
interpretedResult = expression.getValue(testdata,String.class);
for (int j = 0; j < count; j++) {
interpretedResult = expression.getValue(testdata, String.class);
}
etime = System.currentTimeMillis();
long interpretedSpeed = (etime - stime);
@ -505,11 +505,11 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
compile(expression);
log("timing compiled: ");
expression.getValue(testdata,String.class);
for (int iter=0;iter<iterations;iter++) {
expression.getValue(testdata, String.class);
for (int i = 0; i < iterations; i++) {
stime = System.currentTimeMillis();
for (int i=0;i<count;i++) {
compiledResult = expression.getValue(testdata,String.class);
for (int j = 0; j < count; j++) {
compiledResult = expression.getValue(testdata, String.class);
}
etime = System.currentTimeMillis();
long compiledSpeed = (etime - stime);
@ -531,14 +531,14 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
Expression expression = parser.parseExpression("foo.baz.boo");
// warmup
for (int i=0;i<count;i++) {
expression.getValue(testdata,String.class);
for (int i = 0; i < count; i++) {
expression.getValue(testdata, String.class);
}
log("timing interpreted: ");
for (int iter=0;iter<iterations;iter++) {
for (int i = 0; i < iterations; i++) {
stime = System.currentTimeMillis();
for (int i=0;i<count;i++) {
interpretedResult = expression.getValue(testdata,String.class);
for (int j = 0; j < count; j++) {
interpretedResult = expression.getValue(testdata, String.class);
}
etime = System.currentTimeMillis();
long interpretedSpeed = (etime - stime);
@ -550,11 +550,11 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
compile(expression);
log("timing compiled: ");
expression.getValue(testdata,String.class);
for (int iter=0;iter<iterations;iter++) {
expression.getValue(testdata, String.class);
for (int i = 0; i < iterations; i++) {
stime = System.currentTimeMillis();
for (int i=0;i<count;i++) {
compiledResult = expression.getValue(testdata,String.class);
for (int j = 0; j < count; j++) {
compiledResult = expression.getValue(testdata, String.class);
}
etime = System.currentTimeMillis();
long compiledSpeed = (etime - stime);
@ -576,42 +576,42 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
Expression expression = parser.parseExpression("foo.bay().boo");
// warmup
for (int i=0;i<count;i++) {
expression.getValue(testdata,String.class);
for (int i = 0; i < count; i++) {
expression.getValue(testdata, String.class);
}
log("timing interpreted: ");
for (int iter=0;iter<iterations;iter++) {
for (int i = 0; i < iterations; i++) {
stime = System.currentTimeMillis();
for (int i=0;i<count;i++) {
interpretedResult = expression.getValue(testdata,String.class);
for (int j = 0; j < count; j++) {
interpretedResult = expression.getValue(testdata, String.class);
}
etime = System.currentTimeMillis();
long interpretedSpeed = (etime - stime);
interpretedTotal+=interpretedSpeed;
log(interpretedSpeed+"ms ");
interpretedTotal += interpretedSpeed;
log(interpretedSpeed + "ms ");
}
logln();
compile(expression);
log("timing compiled: ");
expression.getValue(testdata,String.class);
for (int iter=0;iter<iterations;iter++) {
expression.getValue(testdata, String.class);
for (int i = 0; i < iterations; i++) {
stime = System.currentTimeMillis();
for (int i=0;i<count;i++) {
compiledResult = expression.getValue(testdata,String.class);
for (int j = 0; j < count; j++) {
compiledResult = expression.getValue(testdata, String.class);
}
etime = System.currentTimeMillis();
long compiledSpeed = (etime - stime);
compiledTotal+=compiledSpeed;
log(compiledSpeed+"ms ");
compiledTotal += compiledSpeed;
log(compiledSpeed + "ms ");
}
logln();
assertEquals(interpretedResult,compiledResult);
reportPerformance("nested reference (mixed field/method)",interpretedTotal, compiledTotal);
reportPerformance("nested reference (mixed field/method)", interpretedTotal, compiledTotal);
}
@Test
@ -623,15 +623,15 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
Expression expression = parser.parseExpression("name2");
// warmup
for (int i=0;i<count;i++) {
expression.getValue(testdata,String.class);
for (int i = 0;i < count; i++) {
expression.getValue(testdata, String.class);
}
log("timing interpreted: ");
for (int iter=0;iter<iterations;iter++) {
for (int i = 0; i < iterations; i++) {
stime = System.currentTimeMillis();
for (int i=0;i<count;i++) {
interpretedResult = expression.getValue(testdata,String.class);
for (int j = 0; j < count; j++) {
interpretedResult = expression.getValue(testdata, String.class);
}
etime = System.currentTimeMillis();
long interpretedSpeed = (etime - stime);
@ -644,11 +644,11 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
compile(expression);
log("timing compiled: ");
expression.getValue(testdata,String.class);
for (int iter=0;iter<iterations;iter++) {
expression.getValue(testdata, String.class);
for (int i = 0; i < iterations; i++) {
stime = System.currentTimeMillis();
for (int i=0;i<count;i++) {
compiledResult = expression.getValue(testdata,String.class);
for (int j = 0; j < count; j++) {
compiledResult = expression.getValue(testdata, String.class);
}
etime = System.currentTimeMillis();
long compiledSpeed = (etime - stime);
@ -672,7 +672,7 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
double averageInterpreted = interpretedTotal/(iterations);
double averageCompiled = compiledTotal/(iterations);
double ratio = (averageCompiled/averageInterpreted)*100.0d;
logln(">>"+title+": average for "+count+": compiled="+averageCompiled+"ms interpreted="+averageInterpreted+"ms: compiled takes "+((int)ratio)+"% of the interpreted time");
logln(">>"+title+": average for "+count+": compiled="+averageCompiled+"ms interpreted="+averageInterpreted+"ms: compiled takes " + ((int)ratio)+"% of the interpreted time");
if (averageCompiled>averageInterpreted) {
fail("Compiled version took longer than interpreted! CompiledSpeed=~"+averageCompiled+
"ms InterpretedSpeed="+averageInterpreted+"ms");
@ -690,7 +690,8 @@ public class SpelCompilationPerformanceTests extends AbstractExpressionTests {
if (noisyTests) {
if (message!=null && message.length>0) {
System.out.println(message[0]);
} else {
}
else {
System.out.println();
}
}

View File

@ -1968,7 +1968,8 @@ public class SpelReproTests extends AbstractExpressionTests {
try {
expr = new SpelExpressionParser().parseRaw("&@foo");
fail("Illegal syntax, error expected");
} catch (SpelParseException spe) {
}
catch (SpelParseException spe) {
assertEquals(SpelMessage.INVALID_BEAN_REFERENCE,spe.getMessageCode());
assertEquals(0,spe.getPosition());
}
@ -1976,7 +1977,8 @@ public class SpelReproTests extends AbstractExpressionTests {
try {
expr = new SpelExpressionParser().parseRaw("@&foo");
fail("Illegal syntax, error expected");
} catch (SpelParseException spe) {
}
catch (SpelParseException spe) {
assertEquals(SpelMessage.INVALID_BEAN_REFERENCE,spe.getMessageCode());
assertEquals(0,spe.getPosition());
}

View File

@ -49,7 +49,8 @@ public class StandardTypeLocatorTests {
try {
locator.findType("URL");
fail("Should have failed");
} catch (EvaluationException ee) {
}
catch (EvaluationException ee) {
SpelEvaluationException sEx = (SpelEvaluationException)ee;
assertEquals(SpelMessage.TYPE_NOT_FOUND,sEx.getMessageCode());
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2016 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.
@ -78,7 +78,8 @@ public class VariableAndFunctionTests extends AbstractExpressionTests {
@SuppressWarnings("unused")
Object v = parser.parseRaw("#notStatic()").getValue(ctx);
fail("Should have failed with exception - cannot call non static method that way");
} catch (SpelEvaluationException se) {
}
catch (SpelEvaluationException se) {
if (se.getMessageCode() != SpelMessage.FUNCTION_MUST_BE_STATIC) {
se.printStackTrace();
fail("Should have failed a message about the function needing to be static, not: "
@ -86,6 +87,8 @@ public class VariableAndFunctionTests extends AbstractExpressionTests {
}
}
}
// this method is used by the test above
public void nonStatic() {
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2016 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.
@ -116,9 +116,10 @@ public class SpelParserTests {
SpelExpressionParser parser = new SpelExpressionParser();
parser.parseRaw("new String");
fail();
} catch (ParseException e) {
assertTrue(e instanceof SpelParseException);
SpelParseException spe = (SpelParseException) e;
}
catch (ParseException ex) {
assertTrue(ex instanceof SpelParseException);
SpelParseException spe = (SpelParseException) ex;
assertEquals(SpelMessage.MISSING_CONSTRUCTOR_ARGS, spe.getMessageCode());
assertEquals(10, spe.getPosition());
}
@ -127,9 +128,10 @@ public class SpelParserTests {
SpelExpressionParser parser = new SpelExpressionParser();
parser.parseRaw("new String(3,");
fail();
} catch (ParseException e) {
assertTrue(e instanceof SpelParseException);
SpelParseException spe = (SpelParseException) e;
}
catch (ParseException ex) {
assertTrue(ex instanceof SpelParseException);
SpelParseException spe = (SpelParseException) ex;
assertEquals(SpelMessage.RUN_OUT_OF_ARGUMENTS, spe.getMessageCode());
assertEquals(10, spe.getPosition());
}
@ -138,9 +140,10 @@ public class SpelParserTests {
SpelExpressionParser parser = new SpelExpressionParser();
parser.parseRaw("new String(3");
fail();
} catch (ParseException e) {
assertTrue(e instanceof SpelParseException);
SpelParseException spe = (SpelParseException) e;
}
catch (ParseException ex) {
assertTrue(ex instanceof SpelParseException);
SpelParseException spe = (SpelParseException) ex;
assertEquals(SpelMessage.RUN_OUT_OF_ARGUMENTS, spe.getMessageCode());
assertEquals(10, spe.getPosition());
}
@ -149,9 +152,10 @@ public class SpelParserTests {
SpelExpressionParser parser = new SpelExpressionParser();
parser.parseRaw("new String(");
fail();
} catch (ParseException e) {
assertTrue(e instanceof SpelParseException);
SpelParseException spe = (SpelParseException) e;
}
catch (ParseException ex) {
assertTrue(ex instanceof SpelParseException);
SpelParseException spe = (SpelParseException) ex;
assertEquals(SpelMessage.RUN_OUT_OF_ARGUMENTS, spe.getMessageCode());
assertEquals(10, spe.getPosition());
}
@ -160,9 +164,10 @@ public class SpelParserTests {
SpelExpressionParser parser = new SpelExpressionParser();
parser.parseRaw("\"abc");
fail();
} catch (ParseException e) {
assertTrue(e instanceof SpelParseException);
SpelParseException spe = (SpelParseException) e;
}
catch (ParseException ex) {
assertTrue(ex instanceof SpelParseException);
SpelParseException spe = (SpelParseException) ex;
assertEquals(SpelMessage.NON_TERMINATING_DOUBLE_QUOTED_STRING, spe.getMessageCode());
assertEquals(0, spe.getPosition());
}
@ -171,9 +176,10 @@ public class SpelParserTests {
SpelExpressionParser parser = new SpelExpressionParser();
parser.parseRaw("'abc");
fail();
} catch (ParseException e) {
assertTrue(e instanceof SpelParseException);
SpelParseException spe = (SpelParseException) e;
}
catch (ParseException ex) {
assertTrue(ex instanceof SpelParseException);
SpelParseException spe = (SpelParseException) ex;
assertEquals(SpelMessage.NON_TERMINATING_QUOTED_STRING, spe.getMessageCode());
assertEquals(0, spe.getPosition());
}
@ -274,7 +280,8 @@ public class SpelParserTests {
try {
new SpelExpressionParser().parseRaw("\"double quote: \\\"\\\".\"");
fail("Should have failed");
} catch (SpelParseException spe) {
}
catch (SpelParseException spe) {
assertEquals(17, spe.getPosition());
assertEquals(SpelMessage.UNEXPECTED_ESCAPE_CHAR, spe.getMessageCode());
}
@ -401,9 +408,10 @@ public class SpelParserTests {
Object o = expr.getValue();
assertEquals(value, o);
assertEquals(type, o.getClass());
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
catch (Exception ex) {
ex.printStackTrace();
fail(ex.getMessage());
}
}
@ -412,9 +420,10 @@ public class SpelParserTests {
SpelExpressionParser parser = new SpelExpressionParser();
parser.parseRaw(expression);
fail();
} catch (ParseException e) {
assertTrue(e instanceof SpelParseException);
SpelParseException spe = (SpelParseException) e;
}
catch (ParseException ex) {
assertTrue(ex instanceof SpelParseException);
SpelParseException spe = (SpelParseException) ex;
assertEquals(expectedMessage, spe.getMessageCode());
}
}

View File

@ -1042,7 +1042,8 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
result[i] = rowsAffected.get(i);
}
return result;
} finally {
}
finally {
if (pss instanceof ParameterDisposer) {
((ParameterDisposer) pss).cleanupParameters();
}

View File

@ -150,7 +150,8 @@ public class JdbcTemplateQueryTests {
this.thrown.expect(IncorrectResultSizeDataAccessException.class);
try {
this.template.queryForObject(sql, String.class);
} finally {
}
finally {
verify(this.resultSet).close();
verify(this.statement).close();
}

View File

@ -292,13 +292,14 @@ public class DataSourceJtaTransactionTests {
assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());
verify(userTransaction, times(6)).begin();
verify(transactionManager, times(5)).resume(transaction);
if(rollback) {
if (rollback) {
verify(userTransaction, times(5)).commit();
verify(userTransaction).rollback();
} else {
}
else {
verify(userTransaction, times(6)).commit();
}
if(accessAfterResume && !openOuterConnection) {
if (accessAfterResume && !openOuterConnection) {
verify(connection, times(7)).close();
}
else {
@ -528,7 +529,7 @@ public class DataSourceJtaTransactionTests {
assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());
verify(userTransaction).begin();
if(suspendException) {
if (suspendException) {
verify(userTransaction).rollback();
}

View File

@ -152,7 +152,7 @@ public class DataSourceTransactionManagerTests {
assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(dsToUse));
assertTrue("Synchronization not active", !TransactionSynchronizationManager.isSynchronizationActive());
if(autoCommit && (!lazyConnection || createStatement)) {
if (autoCommit && (!lazyConnection || createStatement)) {
InOrder ordered = inOrder(con);
ordered.verify(con).setAutoCommit(false);
ordered.verify(con).commit();
@ -244,7 +244,7 @@ public class DataSourceTransactionManagerTests {
assertTrue("Hasn't thread connection", !TransactionSynchronizationManager.hasResource(ds));
assertTrue("Synchronization not active", !TransactionSynchronizationManager.isSynchronizationActive());
if(autoCommit && (!lazyConnection || createStatement)) {
if (autoCommit && (!lazyConnection || createStatement)) {
InOrder ordered = inOrder(con);
ordered.verify(con).setAutoCommit(false);
ordered.verify(con).rollback();

View File

@ -63,10 +63,11 @@ public class BeanFactoryDataSourceLookupTests {
BeanFactoryDataSourceLookup lookup = new BeanFactoryDataSourceLookup(beanFactory);
lookup.getDataSource(DATASOURCE_BEAN_NAME);
fail("should have thrown DataSourceLookupFailureException");
} catch (DataSourceLookupFailureException ex) { /* expected */ }
}
catch (DataSourceLookupFailureException ex) { /* expected */ }
}
@Test(expected=IllegalStateException.class)
@Test(expected = IllegalStateException.class)
public void testLookupWhereBeanFactoryHasNotBeenSupplied() throws Exception {
BeanFactoryDataSourceLookup lookup = new BeanFactoryDataSourceLookup();
lookup.getDataSource(DATASOURCE_BEAN_NAME);

View File

@ -81,7 +81,7 @@ public class StoredProcedureTests {
@After
public void verifyClosed() throws Exception {
if(verifyClosedAfter) {
if (verifyClosedAfter) {
verify(callableStatement).close();
verify(connection, atLeastOnce()).close();
}

View File

@ -205,7 +205,8 @@ public class ResultSetWrappingRowSetTests {
if (arg instanceof String) {
given(rset.findColumn((String) arg)).willReturn(1);
given(rsetMethod.invoke(rset, 1)).willReturn(ret).willThrow(new SQLException("test"));
} else {
}
else {
given(rsetMethod.invoke(rset, arg)).willReturn(ret).willThrow(new SQLException("test"));
}
rowsetMethod.invoke(rowset, arg);

View File

@ -307,7 +307,8 @@ public class MessageListenerAdapterTests {
try {
adapter.onMessage(sentTextMessage, session);
fail("expected CouldNotSendReplyException with InvalidDestinationException");
} catch(ReplyFailureException ex) {
}
catch (ReplyFailureException ex) {
assertEquals(InvalidDestinationException.class, ex.getCause().getClass());
}
@ -345,7 +346,8 @@ public class MessageListenerAdapterTests {
try {
adapter.onMessage(sentTextMessage, session);
fail("expected CouldNotSendReplyException with JMSException");
} catch(ReplyFailureException ex) {
}
catch (ReplyFailureException ex) {
assertEquals(JMSException.class, ex.getCause().getClass());
}
@ -371,7 +373,8 @@ public class MessageListenerAdapterTests {
try {
adapter.onMessage(message, session);
fail("expected ListenerExecutionFailedException");
} catch(ListenerExecutionFailedException ex) { /* expected */ }
}
catch (ListenerExecutionFailedException ex) { /* expected */ }
}
@Test
@ -425,7 +428,8 @@ public class MessageListenerAdapterTests {
try {
adapter.onMessage(sentTextMessage, session);
fail("expected CouldNotSendReplyException with MessageConversionException");
} catch(ReplyFailureException ex) {
}
catch (ReplyFailureException ex) {
assertEquals(MessageConversionException.class, ex.getCause().getClass());
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2016 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.
@ -45,7 +45,7 @@ import static org.mockito.BDDMockito.*;
* @author Rick Evans
* @since 18.09.2004
*/
public final class SimpleMessageConverterTests {
public class SimpleMessageConverterTests {
@Test
public void testStringConversion() throws JMSException {
@ -124,19 +124,18 @@ public final class SimpleMessageConverterTests {
assertEquals(content, converter.fromMessage(msg));
}
@Test(expected=MessageConversionException.class)
@Test(expected = MessageConversionException.class)
public void testToMessageThrowsExceptionIfGivenNullObjectToConvert() throws Exception {
new SimpleMessageConverter().toMessage(null, null);
}
@Test(expected=MessageConversionException.class)
@Test(expected = MessageConversionException.class)
public void testToMessageThrowsExceptionIfGivenIncompatibleObjectToConvert() throws Exception {
new SimpleMessageConverter().toMessage(new Object(), null);
}
@Test
public void testToMessageSimplyReturnsMessageAsIsIfSuppliedWithMessage() throws JMSException {
Session session = mock(Session.class);
ObjectMessage message = mock(ObjectMessage.class);
@ -147,7 +146,6 @@ public final class SimpleMessageConverterTests {
@Test
public void testFromMessageSimplyReturnsMessageAsIsIfSuppliedWithMessage() throws JMSException {
Message message = mock(Message.class);
SimpleMessageConverter converter = new SimpleMessageConverter();
@ -157,36 +155,36 @@ public final class SimpleMessageConverterTests {
@Test
public void testMapConversionWhereMapHasNonStringTypesForKeys() throws JMSException {
MapMessage message = mock(MapMessage.class);
final Session session = mock(Session.class);
Session session = mock(Session.class);
given(session.createMapMessage()).willReturn(message);
final Map<Integer, String> content = new HashMap<Integer, String>(1);
Map<Integer, String> content = new HashMap<Integer, String>(1);
content.put(1, "value1");
final SimpleMessageConverter converter = new SimpleMessageConverter();
SimpleMessageConverter converter = new SimpleMessageConverter();
try {
converter.toMessage(content, session);
fail("expected MessageConversionException");
} catch (MessageConversionException ex) { /* expected */ }
}
catch (MessageConversionException ex) { /* expected */ }
}
@Test
public void testMapConversionWhereMapHasNNullForKey() throws JMSException {
MapMessage message = mock(MapMessage.class);
final Session session = mock(Session.class);
Session session = mock(Session.class);
given(session.createMapMessage()).willReturn(message);
final Map<Object, String> content = new HashMap<Object, String>(1);
Map<Object, String> content = new HashMap<Object, String>(1);
content.put(null, "value1");
final SimpleMessageConverter converter = new SimpleMessageConverter();
SimpleMessageConverter converter = new SimpleMessageConverter();
try {
converter.toMessage(content, session);
fail("expected MessageConversionException");
} catch (MessageConversionException ex) { /* expected */ }
}
catch (MessageConversionException ex) { /* expected */ }
}
}

View File

@ -275,7 +275,7 @@ public class MethodMessageHandlerTests {
private static Map<Class<? extends Throwable>, Method> initExceptionMappings(Class<?> handlerType) {
Map<Class<? extends Throwable>, Method> result = new HashMap<Class<? extends Throwable>, Method>();
for (Method method : MethodIntrospector.selectMethods(handlerType, EXCEPTION_HANDLER_METHOD_FILTER)) {
for(Class<? extends Throwable> exception : getExceptionsFromMethodSignature(method)) {
for (Class<? extends Throwable> exception : getExceptionsFromMethodSignature(method)) {
result.put(exception, method);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2016 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,10 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.messaging.simp.stomp;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
package org.springframework.messaging.simp.stomp;
import java.lang.reflect.Type;
import java.util.ArrayList;
@ -41,6 +39,9 @@ import org.springframework.util.Assert;
import org.springframework.util.SocketUtils;
import org.springframework.util.concurrent.ListenableFuture;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
/**
* Integration tests for {@link Reactor2TcpStompClient}.
*
@ -86,7 +87,8 @@ public class Reactor2TcpStompClientTests {
public void tearDown() throws Exception {
try {
this.client.shutdown();
} catch (Throwable ex) {
}
catch (Throwable ex) {
logger.error("Failed to shut client", ex);
}
final CountDownLatch latch = new CountDownLatch(1);
@ -100,7 +102,6 @@ public class Reactor2TcpStompClientTests {
@Test
public void publishSubscribe() throws Exception {
String destination = "/topic/foo";
ConsumingHandler consumingHandler1 = new ConsumingHandler(destination);
ListenableFuture<StompSession> consumerFuture1 = this.client.connect(consumingHandler1);
@ -146,9 +147,9 @@ public class Reactor2TcpStompClientTests {
public void handleTransportError(StompSession session, Throwable exception) {
logger.error(exception);
}
}
private static class ConsumingHandler extends LoggingSessionHandler {
private final List<String> topics;
@ -157,14 +158,12 @@ public class Reactor2TcpStompClientTests {
private final List<String> received = new ArrayList<>();
public ConsumingHandler(String... topics) {
Assert.notEmpty(topics);
this.topics = Arrays.asList(topics);
this.subscriptionLatch = new CountDownLatch(this.topics.size());
}
public List<String> getReceived() {
return this.received;
}
@ -208,16 +207,15 @@ public class Reactor2TcpStompClientTests {
}
return true;
}
}
private static class ProducingHandler extends LoggingSessionHandler {
private final List<String> topics = new ArrayList<>();
private final List<Object> payloads = new ArrayList<>();
public ProducingHandler addToSend(String topic, Object payload) {
this.topics.add(topic);
this.payloads.add(payload);
@ -226,7 +224,7 @@ public class Reactor2TcpStompClientTests {
@Override
public void afterConnected(StompSession session, StompHeaders connectedHeaders) {
for (int i=0; i < this.topics.size(); i++) {
for (int i = 0; i < this.topics.size(); i++) {
session.send(this.topics.get(i), this.payloads.get(i));
}
}

View File

@ -326,7 +326,7 @@ public class StompBrokerRelayMessageHandlerIntegrationTests {
}
public boolean matchMessage(Message<?> message) {
for (int i=0 ; i < this.expected.length; i++) {
for (int i = 0 ; i < this.expected.length; i++) {
if (this.expected[i].match(message)) {
this.actual[i] = message;
return true;

View File

@ -325,7 +325,8 @@ public class StompCodecTests {
this.decoder.apply(buffer);
if (consumer.arguments.isEmpty()) {
return null;
} else {
}
else {
return consumer.arguments.get(0);
}
}

View File

@ -166,7 +166,8 @@ public class HibernateJtaTransactionTests {
if (readOnly) {
verify(session).setFlushMode(FlushMode.MANUAL);
} else {
}
else {
verify(session).flush();
}
verify(session).close();
@ -188,7 +189,8 @@ public class HibernateJtaTransactionTests {
UserTransaction ut = mock(UserTransaction.class);
if (status == Status.STATUS_NO_TRANSACTION) {
given(ut.getStatus()).willReturn(status, status, Status.STATUS_ACTIVE);
} else {
}
else {
given(ut.getStatus()).willReturn(status);
}
@ -520,13 +522,13 @@ public class HibernateJtaTransactionTests {
verify(ut).commit();
if (flushNever) {
if(!readOnly) {
if (!readOnly) {
InOrder ordered = inOrder(session);
ordered.verify(session).setFlushMode(FlushMode.AUTO);
ordered.verify(session).setFlushMode(FlushMode.MANUAL);
}
}
if(!flushNever && !readOnly) {
if (!flushNever && !readOnly) {
verify(session).flush();
}
verify(session).afterTransactionCompletion(true, null);
@ -716,7 +718,7 @@ public class HibernateJtaTransactionTests {
}
verify(session1).disconnect();
verify(session1).close();
if(!rollback) {
if (!rollback) {
verify(session1).flush();
verify(session2, atLeastOnce()).flush();
}
@ -792,7 +794,7 @@ public class HibernateJtaTransactionTests {
}
verify(ut, atLeastOnce()).begin();
if(!suspendException) {
if (!suspendException) {
verify(tm).resume(tx);
}
verify(ut).rollback();
@ -1448,10 +1450,11 @@ public class HibernateJtaTransactionTests {
assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));
InOrder ordered = inOrder(session);
if(flushNever) {
if (flushNever) {
ordered.verify(session).setFlushMode(FlushMode.AUTO);
ordered.verify(session).setFlushMode(FlushMode.MANUAL);
} else {
}
else {
ordered.verify(session).flush();
}
ordered.verify(session).disconnect();

View File

@ -79,7 +79,7 @@ public class MockFilterChainTests {
chain.doFilter(this.request, this.response);
fail("Expected Exception");
}
catch(IllegalStateException ex) {
catch (IllegalStateException ex) {
assertEquals("This FilterChain has already been called!", ex.getMessage());
}
}
@ -94,7 +94,7 @@ public class MockFilterChainTests {
chain.doFilter(this.request, this.response);
fail("Expected Exception");
}
catch(IllegalStateException ex) {
catch (IllegalStateException ex) {
assertEquals("This FilterChain has already been called!", ex.getMessage());
}
}
@ -118,7 +118,7 @@ public class MockFilterChainTests {
chain.doFilter(this.request, this.response);
fail("Expected Exception");
}
catch(IllegalStateException ex) {
catch (IllegalStateException ex) {
assertEquals("This FilterChain has already been called!", ex.getMessage());
}
}

View File

@ -59,7 +59,7 @@ public class StatusResultMatchersTests {
List<AssertionError> failures = new ArrayList<AssertionError>();
for(HttpStatus status : HttpStatus.values()) {
for (HttpStatus status : HttpStatus.values()) {
MockHttpServletResponse response = new MockHttpServletResponse();
response.setStatus(status.value());
MvcResult mvcResult = new StubMvcResult(request, null, null, null, null, null, response);
@ -91,9 +91,7 @@ public class StatusResultMatchersTests {
@Test
public void statusRanges() throws Exception {
for(HttpStatus status : HttpStatus.values()) {
for (HttpStatus status : HttpStatus.values()) {
MockHttpServletResponse response = new MockHttpServletResponse();
response.setStatus(status.value());
MvcResult mvcResult = new StubMvcResult(request, null, null, null, null, null, response);

View File

@ -123,7 +123,7 @@ public class UrlBasedCorsConfigurationSource implements CorsConfigurationSource
@Override
public CorsConfiguration getCorsConfiguration(HttpServletRequest request) {
String lookupPath = this.urlPathHelper.getLookupPathForRequest(request);
for(Map.Entry<String, CorsConfiguration> entry : this.corsConfigurations.entrySet()) {
for (Map.Entry<String, CorsConfiguration> entry : this.corsConfigurations.entrySet()) {
if (this.pathMatcher.match(entry.getKey(), lookupPath)) {
return entry.getValue();
}

View File

@ -48,9 +48,8 @@ import org.springframework.web.method.support.ModelAndViewContainer;
* Assist with initialization of the {@link Model} before controller method
* invocation and with updates to it after the invocation.
*
* <p>On initialization the model is populated with attributes temporarily
* stored in the session and through the invocation of {@code @ModelAttribute}
* methods.
* <p>On initialization the model is populated with attributes temporarily stored
* in the session and through the invocation of {@code @ModelAttribute} methods.
*
* <p>On update model attributes are synchronized with the session and also
* {@link BindingResult} attributes are added if missing.
@ -62,7 +61,6 @@ public final class ModelFactory {
private static final Log logger = LogFactory.getLog(ModelFactory.class);
private final List<ModelMethod> modelMethods = new ArrayList<ModelMethod>();
private final WebDataBinderFactory dataBinderFactory;
@ -92,11 +90,11 @@ public final class ModelFactory {
/**
* Populate the model in the following order:
* <ol>
* <li>Retrieve "known" session attributes listed as {@code @SessionAttributes}.
* <li>Invoke {@code @ModelAttribute} methods
* <li>Find {@code @ModelAttribute} method arguments also listed as
* {@code @SessionAttributes} and ensure they're present in the model raising
* an exception if necessary.
* <li>Retrieve "known" session attributes listed as {@code @SessionAttributes}.
* <li>Invoke {@code @ModelAttribute} methods
* <li>Find {@code @ModelAttribute} method arguments also listed as
* {@code @SessionAttributes} and ensure they're present in the model raising
* an exception if necessary.
* </ol>
* @param request the current request
* @param container a container with the model to be initialized
@ -108,15 +106,13 @@ public final class ModelFactory {
Map<String, ?> sessionAttributes = this.sessionAttributesHandler.retrieveAttributes(request);
container.mergeAttributes(sessionAttributes);
invokeModelAttributeMethods(request, container);
for (String name : findSessionAttributeArguments(handlerMethod)) {
if (!container.containsAttribute(name)) {
Object value = this.sessionAttributesHandler.retrieveAttribute(request, name);
if (value == null) {
throw new HttpSessionRequiredException(
"Expected session attribute '" + name + "'");
throw new HttpSessionRequiredException("Expected session attribute '" + name + "'");
}
container.addAttribute(name, value);
}
@ -127,8 +123,8 @@ public final class ModelFactory {
* Invoke model attribute methods to populate the model.
* Attributes are added only if not already present in the model.
*/
private void invokeModelAttributeMethods(NativeWebRequest request,
ModelAndViewContainer container) throws Exception {
private void invokeModelAttributeMethods(NativeWebRequest request, ModelAndViewContainer container)
throws Exception {
while (!this.modelMethods.isEmpty()) {
InvocableHandlerMethod modelMethod = getNextModelMethod(container).getHandlerMethod();
@ -141,7 +137,6 @@ public final class ModelFactory {
}
Object returnValue = modelMethod.invokeForRequest(request, container);
if (!modelMethod.isVoid()){
String returnValueName = getNameForReturnValue(returnValue, modelMethod.getReturnType());
if (!ann.binding()) {
@ -291,7 +286,6 @@ public final class ModelFactory {
private final Set<String> dependencies = new HashSet<String>();
private ModelMethod(InvocableHandlerMethod handlerMethod) {
this.handlerMethod = handlerMethod;
for (MethodParameter parameter : handlerMethod.getMethodParameters()) {

View File

@ -288,7 +288,7 @@ final class HierarchicalUriComponents extends UriComponents {
return;
}
int length = source.length();
for (int i=0; i < length; i++) {
for (int i = 0; i < length; i++) {
char ch = source.charAt(i);
if (ch == '%') {
if ((i + 2) < length) {

View File

@ -61,7 +61,8 @@ public class ProtobufHttpMessageConverterTests {
public void extensionRegistryNull() {
try {
new ProtobufHttpMessageConverter(null);
} catch (Exception e) {
}
catch (Exception ex) {
fail("Unable to create ProtobufHttpMessageConverter with null extensionRegistry");
}
}

View File

@ -150,8 +150,9 @@ public class WebAsyncManagerTests {
try {
this.asyncManager.startCallableProcessing(task);
fail("Expected Exception");
}catch(Exception e) {
assertEquals(exception, e);
}
catch (Exception ex) {
assertEquals(exception, ex);
}
assertFalse(this.asyncManager.hasConcurrentResult());
@ -162,7 +163,6 @@ public class WebAsyncManagerTests {
@Test
public void startCallableProcessingPreProcessException() throws Exception {
Callable<Object> task = new StubCallable(21);
Exception exception = new Exception();
@ -183,7 +183,6 @@ public class WebAsyncManagerTests {
@Test
public void startCallableProcessingPostProcessException() throws Exception {
Callable<Object> task = new StubCallable(21);
Exception exception = new Exception();
@ -205,7 +204,6 @@ public class WebAsyncManagerTests {
@Test
public void startCallableProcessingPostProcessContinueAfterException() throws Exception {
Callable<Object> task = new StubCallable(21);
Exception exception = new Exception();
@ -231,7 +229,6 @@ public class WebAsyncManagerTests {
@Test
public void startCallableProcessingWithAsyncTask() throws Exception {
AsyncTaskExecutor executor = mock(AsyncTaskExecutor.class);
given(this.asyncWebRequest.getNativeRequest(HttpServletRequest.class)).willReturn(this.servletRequest);
@ -259,7 +256,6 @@ public class WebAsyncManagerTests {
@Test
public void startDeferredResultProcessing() throws Exception {
DeferredResult<String> deferredResult = new DeferredResult<String>(1000L);
String concurrentResult = "abc";
@ -282,7 +278,6 @@ public class WebAsyncManagerTests {
@Test
public void startDeferredResultProcessingBeforeConcurrentHandlingException() throws Exception {
DeferredResult<Integer> deferredResult = new DeferredResult<Integer>();
Exception exception = new Exception();
@ -295,7 +290,7 @@ public class WebAsyncManagerTests {
this.asyncManager.startDeferredResultProcessing(deferredResult);
fail("Expected Exception");
}
catch(Exception success) {
catch (Exception success) {
assertEquals(exception, success);
}
@ -328,7 +323,6 @@ public class WebAsyncManagerTests {
@Test
public void startDeferredResultProcessingPostProcessException() throws Exception {
DeferredResult<Integer> deferredResult = new DeferredResult<Integer>();
Exception exception = new Exception();
@ -371,6 +365,7 @@ public class WebAsyncManagerTests {
verify(this.asyncWebRequest).dispatch();
}
private final class StubCallable implements Callable<Object> {
private Object value;
@ -388,6 +383,7 @@ public class WebAsyncManagerTests {
}
}
@SuppressWarnings("serial")
private static class SyncTaskExecutor extends SimpleAsyncTaskExecutor {

View File

@ -49,7 +49,8 @@ public class Spr8510Tests {
try {
cll.contextInitialized(new ServletContextEvent(sc));
fail("expected exception");
} catch (Throwable t) {
}
catch (Throwable t) {
// assert that an attempt was made to load the correct XML
assertTrue(t.getMessage(), t.getMessage().endsWith(
"Could not open ServletContext resource [/programmatic.xml]"));
@ -75,7 +76,8 @@ public class Spr8510Tests {
try {
cll.contextInitialized(new ServletContextEvent(sc));
fail("expected exception");
} catch (Throwable t) {
}
catch (Throwable t) {
// assert that an attempt was made to load the correct XML
assertTrue(t.getMessage(), t.getMessage().endsWith(
"Could not open ServletContext resource [/from-init-param.xml]"));
@ -98,7 +100,8 @@ public class Spr8510Tests {
try {
cll.contextInitialized(new ServletContextEvent(sc));
fail("expected exception");
} catch (Throwable t) {
}
catch (Throwable t) {
// assert that an attempt was made to load the correct XML
assertTrue(t.getMessage().endsWith(
"Could not open ServletContext resource [/from-init-param.xml]"));
@ -125,7 +128,8 @@ public class Spr8510Tests {
try {
cll.contextInitialized(new ServletContextEvent(sc));
fail("expected exception");
} catch (Throwable t) {
}
catch (Throwable t) {
// assert that an attempt was made to load the correct XML
System.out.println(t.getMessage());
assertTrue(t.getMessage().endsWith(
@ -150,7 +154,8 @@ public class Spr8510Tests {
try {
cll.contextInitialized(new ServletContextEvent(sc));
fail("expected exception");
} catch (Throwable t) {
}
catch (Throwable t) {
// assert that an attempt was made to load the correct XML
System.out.println(t.getMessage());
assertTrue(t.getMessage().endsWith(

View File

@ -101,7 +101,8 @@ public class Log4jWebConfigurerTests {
try {
assertLogOutput();
} finally {
}
finally {
Log4jWebConfigurer.shutdownLogging(sc);
}
assertTrue(MockLog4jAppender.closeCalled);
@ -132,7 +133,8 @@ public class Log4jWebConfigurerTests {
try {
assertLogOutput();
} finally {
}
finally {
listener.contextDestroyed(new ServletContextEvent(sc));
}
assertTrue(MockLog4jAppender.closeCalled);

View File

@ -58,7 +58,7 @@ public class XmlPortletApplicationContextTests extends AbstractXmlWebApplication
beanFactory.addBeanPostProcessor(new BeanPostProcessor() {
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if(bean instanceof TestBean) {
if (bean instanceof TestBean) {
((TestBean) bean).getFriends().add("myFriend");
}
return bean;

View File

@ -162,9 +162,11 @@ public final class PortletWrappingControllerTests {
public void processAction(ActionRequest request, ActionResponse response) throws PortletException {
if (request.getParameter("test") != null) {
response.setRenderParameter(RESULT_RENDER_PARAMETER_NAME, "myPortlet-action");
} else if (request.getParameter(PORTLET_NAME_ACTION_REQUEST_PARAMETER_NAME) != null) {
}
else if (request.getParameter(PORTLET_NAME_ACTION_REQUEST_PARAMETER_NAME) != null) {
response.setRenderParameter(RESULT_RENDER_PARAMETER_NAME, getPortletConfig().getPortletName());
} else {
}
else {
throw new IllegalArgumentException("no request parameters");
}
}

View File

@ -435,12 +435,13 @@ public final class PortletUtilsTests {
public void testGetRequiredSessionAttributeWithExistingSessionAndNoAttribute() throws Exception {
MockPortletSession session = new MockPortletSession();
final PortletRequest request = mock(PortletRequest.class);
PortletRequest request = mock(PortletRequest.class);
given(request.getPortletSession(false)).willReturn(session);
try {
PortletUtils.getRequiredSessionAttribute(request, "foo");
fail("expected IllegalStateException");
} catch (IllegalStateException ex) { /* expected */ }
}
catch (IllegalStateException ex) { /* expected */ }
}

View File

@ -224,7 +224,7 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
if (this.contentNegotiationManager == null) {
this.contentNegotiationManager = initContentNegotiationManager();
}
if( this.resourceHttpMessageConverter == null) {
if ( this.resourceHttpMessageConverter == null) {
this.resourceHttpMessageConverter = new ResourceHttpMessageConverter();
}
}
@ -486,7 +486,7 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
ServletWebRequest webRequest = new ServletWebRequest(request);
try {
List<MediaType> mediaTypes = getContentNegotiationManager().resolveMediaTypes(webRequest);
if(!mediaTypes.isEmpty()) {
if (!mediaTypes.isEmpty()) {
mediaType = mediaTypes.get(0);
}
}

View File

@ -218,7 +218,7 @@ public class ResourceUrlProvider implements ApplicationListener<ContextRefreshed
if (!matchingPatterns.isEmpty()) {
Comparator<String> patternComparator = getPathMatcher().getPatternComparator(lookupPath);
Collections.sort(matchingPatterns, patternComparator);
for(String pattern : matchingPatterns) {
for (String pattern : matchingPatterns) {
String pathWithinMapping = getPathMatcher().extractPathWithinPattern(pattern, lookupPath);
String pathMapping = lookupPath.substring(0, lookupPath.indexOf(pathWithinMapping));
if (logger.isTraceEnabled()) {

View File

@ -123,9 +123,9 @@ public class VersionResourceResolver extends AbstractResourceResolver {
List<String> patternsList = Arrays.asList(pathPatterns);
List<String> prefixedPatterns = new ArrayList<String>(pathPatterns.length);
String versionPrefix = "/" + version;
for(String pattern : patternsList) {
for (String pattern : patternsList) {
prefixedPatterns.add(pattern);
if(!pattern.startsWith(versionPrefix) && !patternsList.contains(versionPrefix + pattern)) {
if (!pattern.startsWith(versionPrefix) && !patternsList.contains(versionPrefix + pattern)) {
prefixedPatterns.add(versionPrefix + pattern);
}
}

View File

@ -176,7 +176,8 @@ public class AnnotationDrivenBeanDefinitionParserTests {
List<HttpMessageConverter<?>> converters = (List<HttpMessageConverter<?>>) value;
if (hasDefaultRegistrations) {
assertTrue("Default and custom converter expected", converters.size() > 2);
} else {
}
else {
assertTrue("Only custom converters expected", converters.size() == 2);
}
assertTrue(converters.get(0) instanceof StringHttpMessageConverter);

View File

@ -181,7 +181,7 @@ public class FlashMapManagerTests {
@Test
public void retrieveAndUpdateRemoveExpired() throws InterruptedException {
List<FlashMap> flashMaps = new ArrayList<FlashMap>();
for (int i=0; i < 5; i++) {
for (int i = 0; i < 5; i++) {
FlashMap expiredFlashMap = new FlashMap();
expiredFlashMap.startExpirationPeriod(-1);
flashMaps.add(expiredFlashMap);

View File

@ -465,7 +465,8 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
tag.setValue("foo");
tag.doStartTag();
fail("Must throw an IllegalStateException when not nested within a <select/> tag.");
} catch (IllegalStateException ex) {
}
catch (IllegalStateException ex) {
// expected
}
}
@ -542,7 +543,8 @@ public class OptionTagTests extends AbstractHtmlElementTagTests {
public String toId() {
if (this.variant != null) {
return this.rules + "-" + this.variant;
} else {
}
else {
return rules;
}
}

View File

@ -100,7 +100,8 @@ public class PasswordInputTagTests extends InputTagTests {
protected void assertValueAttribute(String output, String expectedValue) {
if (this.getPasswordTag().isShowPassword()) {
super.assertValueAttribute(output, expectedValue);
} else {
}
else {
super.assertValueAttribute(output, "");
}
}

View File

@ -147,11 +147,11 @@ public class ScriptTemplateViewTests {
this.view.setApplicationContext(this.wac);
ExecutorService executor = Executors.newFixedThreadPool(4);
List<Future<Boolean>> results = new ArrayList<>();
for(int i = 0; i < iterations; i++) {
for (int i = 0; i < iterations; i++) {
results.add(executor.submit(() -> view.getEngine() != null));
}
assertEquals(iterations, results.size());
for(int i = 0; i < iterations; i++) {
for (int i = 0; i < iterations; i++) {
assertTrue(results.get(i).get());
}
executor.shutdown();

View File

@ -32,7 +32,7 @@ public abstract class AbstractSockJsMessageCodec implements SockJsMessageCodec {
Assert.notNull(messages, "messages must not be null");
StringBuilder sb = new StringBuilder();
sb.append("a[");
for (int i=0; i < messages.length; i++) {
for (int i = 0; i < messages.length; i++) {
sb.append('"');
char[] quotedChars = applyJsonQuoting(messages[i]);
sb.append(escapeSockJsSpecialChars(quotedChars));

View File

@ -38,7 +38,8 @@ public class ContextLoaderTestUtils {
public static void setCurrentWebApplicationContext(ClassLoader classLoader, WebApplicationContext applicationContext) {
if (applicationContext != null) {
currentContextPerThread.put(classLoader, applicationContext);
} else {
}
else {
currentContextPerThread.remove(classLoader);
}
}

View File

@ -88,7 +88,7 @@ public class ConcurrentWebSocketSessionDecoratorTests {
assertTrue(concurrentSession.getTimeSinceSendStarted() > 0);
TextMessage payload = new TextMessage("payload");
for (int i=0; i < 5; i++) {
for (int i = 0; i < 5; i++) {
concurrentSession.sendMessage(payload);
}
@ -166,7 +166,7 @@ public class ConcurrentWebSocketSessionDecoratorTests {
assertTrue(sentMessageLatch.await(5, TimeUnit.SECONDS));
StringBuilder sb = new StringBuilder();
for (int i=0 ; i < 1023; i++) {
for (int i = 0 ; i < 1023; i++) {
sb.append("a");
}

View File

@ -91,7 +91,7 @@ public class RestTemplateXhrTransportTests {
@Test
public void connectReceiveAndCloseWithPrelude() throws Exception {
StringBuilder sb = new StringBuilder(2048);
for (int i=0; i < 2048; i++) {
for (int i = 0; i < 2048; i++) {
sb.append('h');
}
String body = sb.toString() + "\n" + "o\n" + "a[\"foo\"]\n" + "c[3000,\"Go away!\"]";

Some files were not shown because too many files have changed in this diff Show More