diff --git a/spring-binding/src/main/java/org/springframework/binding/collection/AbstractCachingMapDecorator.java b/spring-binding/src/main/java/org/springframework/binding/collection/AbstractCachingMapDecorator.java index 5830d8be..6762b9f3 100644 --- a/spring-binding/src/main/java/org/springframework/binding/collection/AbstractCachingMapDecorator.java +++ b/spring-binding/src/main/java/org/springframework/binding/collection/AbstractCachingMapDecorator.java @@ -1,3 +1,18 @@ +/* + * Copyright 2004-2020 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 + * + * https://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.binding.collection; import java.io.Serializable; @@ -68,7 +83,7 @@ public abstract class AbstractCachingMapDecorator implements Map, Se * @param size the initial cache size */ public AbstractCachingMapDecorator(boolean weak, int size) { - Map internalMap = weak ? new WeakHashMap (size) : new HashMap<>(size); + Map internalMap = weak ? new WeakHashMap<>(size) : new HashMap<>(size); this.targetMap = Collections.synchronizedMap(internalMap); this.synchronize = true; this.weak = weak; diff --git a/spring-binding/src/main/java/org/springframework/binding/convert/converters/StringToCharacter.java b/spring-binding/src/main/java/org/springframework/binding/convert/converters/StringToCharacter.java index aba90d9e..91a10cc3 100644 --- a/spring-binding/src/main/java/org/springframework/binding/convert/converters/StringToCharacter.java +++ b/spring-binding/src/main/java/org/springframework/binding/convert/converters/StringToCharacter.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2012 the original author or authors. + * Copyright 2004-2020 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. @@ -22,7 +22,7 @@ public class StringToCharacter extends StringToObject { } protected Object toObject(String string, Class targetClass) { - return new Character(string.charAt(0)); + return string.charAt(0); } protected String toString(Object object) { diff --git a/spring-binding/src/main/java/org/springframework/binding/expression/el/ELExpressionParser.java b/spring-binding/src/main/java/org/springframework/binding/expression/el/ELExpressionParser.java index 6ee56c52..b407b091 100644 --- a/spring-binding/src/main/java/org/springframework/binding/expression/el/ELExpressionParser.java +++ b/spring-binding/src/main/java/org/springframework/binding/expression/el/ELExpressionParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2012 the original author or authors. + * Copyright 2004-2020 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. @@ -46,7 +46,7 @@ public class ELExpressionParser implements ExpressionParser { private ExpressionFactory expressionFactory; - private Map, ELContextFactory> contextFactories = new HashMap, ELContextFactory>(); + private Map, ELContextFactory> contextFactories = new HashMap<>(); private ConversionService conversionService = new DefaultConversionService(); diff --git a/spring-binding/src/main/java/org/springframework/binding/message/DefaultMessageContext.java b/spring-binding/src/main/java/org/springframework/binding/message/DefaultMessageContext.java index 06301f93..4ab854ee 100644 --- a/spring-binding/src/main/java/org/springframework/binding/message/DefaultMessageContext.java +++ b/spring-binding/src/main/java/org/springframework/binding/message/DefaultMessageContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2012 the original author or authors. + * Copyright 2004-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -44,13 +44,13 @@ public class DefaultMessageContext implements StateManageableMessageContext { private MessageSource messageSource; @SuppressWarnings("serial") - private Map> sourceMessages = new AbstractCachingMapDecorator>( - new LinkedHashMap>()) { + private Map> sourceMessages = + new AbstractCachingMapDecorator>(new LinkedHashMap<>()) { - protected List create(Object source) { - return new ArrayList<>(); - } - }; + protected List create(Object source) { + return new ArrayList<>(); + } + }; /** * Creates a new default message context. Defaults to a message source that simply resolves default text and cannot @@ -130,7 +130,7 @@ public class DefaultMessageContext implements StateManageableMessageContext { // implementing state manageable message context public Serializable createMessagesMemento() { - return new LinkedHashMap>(sourceMessages); + return new LinkedHashMap<>(sourceMessages); } @SuppressWarnings("unchecked") diff --git a/spring-binding/src/test/java/org/springframework/binding/convert/service/DefaultConversionServiceTests.java b/spring-binding/src/test/java/org/springframework/binding/convert/service/DefaultConversionServiceTests.java index 1a80f02c..711b4064 100644 --- a/spring-binding/src/test/java/org/springframework/binding/convert/service/DefaultConversionServiceTests.java +++ b/spring-binding/src/test/java/org/springframework/binding/convert/service/DefaultConversionServiceTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2012 the original author or authors. + * Copyright 2004-2020 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. @@ -164,11 +164,7 @@ public class DefaultConversionServiceTests { DefaultConversionService service = new DefaultConversionService(); service.addConverter("princy", new CustomTwoWayConverter()); ConversionExecutor executor = service.getConversionExecutor("princy", Principal.class, String.class); - assertEquals("name", executor.execute(new Principal() { - public String getName() { - return "name"; - } - })); + assertEquals("name", executor.execute((Principal) () -> "name")); } @Test @@ -197,16 +193,8 @@ public class DefaultConversionServiceTests { DefaultConversionService service = new DefaultConversionService(); service.addConverter("princy", new CustomTwoWayConverter()); ConversionExecutor executor = service.getConversionExecutor("princy", Principal[].class, String[].class); - final Principal princy1 = new Principal() { - public String getName() { - return "princy1"; - } - }; - final Principal princy2 = new Principal() { - public String getName() { - return "princy2"; - } - }; + final Principal princy1 = () -> "princy1"; + final Principal princy2 = () -> "princy2"; String[] p = (String[]) executor.execute(new Principal[] { princy1, princy2 }); assertEquals("princy1", p[0]); assertEquals("princy2", p[1]); @@ -567,11 +555,7 @@ public class DefaultConversionServiceTests { private static class CustomConverter implements Converter { public Object convertSourceToTargetClass(final Object source, Class targetClass) throws Exception { - return new Principal() { - public String getName() { - return (String) source; - } - }; + return (Principal) () -> (String) source; } public Class getSourceClass() { diff --git a/spring-faces/src/main/java/org/springframework/faces/config/FacesFlowBuilderServicesBeanDefinitionParser.java b/spring-faces/src/main/java/org/springframework/faces/config/FacesFlowBuilderServicesBeanDefinitionParser.java index f3291744..e499461e 100644 --- a/spring-faces/src/main/java/org/springframework/faces/config/FacesFlowBuilderServicesBeanDefinitionParser.java +++ b/spring-faces/src/main/java/org/springframework/faces/config/FacesFlowBuilderServicesBeanDefinitionParser.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2014 the original author or authors. + * Copyright 2004-2020 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. @@ -82,7 +82,7 @@ public class FacesFlowBuilderServicesBeanDefinitionParser extends AbstractSingle private boolean parseEnableManagedBeans(Element element, BeanDefinitionBuilder definitionBuilder) { String enableManagedBeans = element.getAttribute(ENABLE_MANAGED_BEANS_ATTR); if (StringUtils.hasText(enableManagedBeans)) { - return Boolean.valueOf(enableManagedBeans); + return Boolean.parseBoolean(enableManagedBeans); } else { return false; } diff --git a/spring-faces/src/main/java/org/springframework/faces/model/SelectionTrackingActionListener.java b/spring-faces/src/main/java/org/springframework/faces/model/SelectionTrackingActionListener.java index 1a19553f..ce572fca 100644 --- a/spring-faces/src/main/java/org/springframework/faces/model/SelectionTrackingActionListener.java +++ b/spring-faces/src/main/java/org/springframework/faces/model/SelectionTrackingActionListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2012 the original author or authors. + * Copyright 2004-2020 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. @@ -52,7 +52,7 @@ public class SelectionTrackingActionListener implements ActionListener { private final ActionListener delegate; - private final Map, Method> valueMethodCache = new ConcurrentHashMap, Method>(256); + private final Map, Method> valueMethodCache = new ConcurrentHashMap<>(256); public SelectionTrackingActionListener(ActionListener delegate) { diff --git a/spring-faces/src/main/java/org/springframework/faces/webflow/FlowFacesContext.java b/spring-faces/src/main/java/org/springframework/faces/webflow/FlowFacesContext.java index a3e4c5f1..fec3fda7 100644 --- a/spring-faces/src/main/java/org/springframework/faces/webflow/FlowFacesContext.java +++ b/spring-faces/src/main/java/org/springframework/faces/webflow/FlowFacesContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2015 the original author or authors. + * Copyright 2004-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,6 +28,7 @@ import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; + import javax.el.ELContext; import javax.faces.application.FacesMessage; import javax.faces.context.ExternalContext; @@ -38,7 +39,6 @@ import javax.faces.context.PartialViewContextFactory; import javax.faces.lifecycle.Lifecycle; import org.springframework.binding.message.Message; -import org.springframework.binding.message.MessageCriteria; import org.springframework.binding.message.MessageResolver; import org.springframework.binding.message.Severity; import org.springframework.context.MessageSource; @@ -230,12 +230,9 @@ public class FlowFacesContext extends FacesContextWrapper { */ public List getMessageList(final String clientId) { final FacesMessageSource source = new FacesMessageSource(clientId); - Message[] messages = this.context.getMessageContext().getMessagesByCriteria(new MessageCriteria() { - public boolean test(Message message) { - return ObjectUtils.nullSafeEquals(message.getSource(), source) - || ObjectUtils.nullSafeEquals(message.getSource(), clientId); - } - }); + Message[] messages = this.context.getMessageContext().getMessagesByCriteria(message -> + ObjectUtils.nullSafeEquals(message.getSource(), source) + || ObjectUtils.nullSafeEquals(message.getSource(), clientId)); return asFacesMessages(messages); } @@ -338,8 +335,8 @@ public class FlowFacesContext extends FacesContextWrapper { String detail = (String) ois.readObject(); int severityOrdinal = ois.readInt(); FacesMessage.Severity severity = FacesMessage.SEVERITY_INFO; - for (Iterator iterator = FacesMessage.VALUES.iterator(); iterator.hasNext();) { - FacesMessage.Severity value = (FacesMessage.Severity) iterator.next(); + for (Object o : FacesMessage.VALUES) { + FacesMessage.Severity value = (FacesMessage.Severity) o; if (value.getOrdinal() == severityOrdinal) { severity = value; } diff --git a/spring-webflow/src/main/java/org/springframework/webflow/config/FlowRegistryFactoryBean.java b/spring-webflow/src/main/java/org/springframework/webflow/config/FlowRegistryFactoryBean.java index fd1a69b5..ebce848b 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/config/FlowRegistryFactoryBean.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/config/FlowRegistryFactoryBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2012 the original author or authors. + * Copyright 2004-2020 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. @@ -289,11 +289,7 @@ class FlowRegistryFactoryBean implements FactoryBean, Be flowRegistry, flowBuilderServices); FlowAssembler assembler = new FlowAssembler(builder, builderContext); return assembler.assembleFlow(); - } catch (IllegalArgumentException e) { - throw new FlowDefinitionConstructionException(builderInfo.getId(), e); - } catch (InstantiationException e) { - throw new FlowDefinitionConstructionException(builderInfo.getId(), e); - } catch (IllegalAccessException e) { + } catch (IllegalArgumentException | IllegalAccessException | InstantiationException e) { throw new FlowDefinitionConstructionException(builderInfo.getId(), e); } } diff --git a/spring-webflow/src/main/java/org/springframework/webflow/conversation/impl/ConversationContainer.java b/spring-webflow/src/main/java/org/springframework/webflow/conversation/impl/ConversationContainer.java index 3ee2c779..9edd54f0 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/conversation/impl/ConversationContainer.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/conversation/impl/ConversationContainer.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2015 the original author or authors. + * Copyright 2004-2020 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. @@ -16,8 +16,6 @@ package org.springframework.webflow.conversation.impl; import java.io.Serializable; -import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; @@ -134,8 +132,7 @@ public class ConversationContainer implements Serializable { * Remove identified conversation from this container. */ public synchronized void removeConversation(ConversationId id) { - for (Iterator it = conversations.iterator(); it.hasNext();) { - ContainedConversation conversation = it.next(); + for (ContainedConversation conversation : conversations) { if (conversation.getId().equals(id)) { conversations.remove(conversation); break; diff --git a/spring-webflow/src/main/java/org/springframework/webflow/engine/model/builder/xml/DefaultDocumentLoader.java b/spring-webflow/src/main/java/org/springframework/webflow/engine/model/builder/xml/DefaultDocumentLoader.java index 488e15c9..f8475008 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/engine/model/builder/xml/DefaultDocumentLoader.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/engine/model/builder/xml/DefaultDocumentLoader.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2008 the original author or authors. + * Copyright 2004-2020 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. @@ -93,9 +93,7 @@ public class DefaultDocumentLoader implements DocumentLoader { } public Document loadDocument(Resource resource) throws IOException, ParserConfigurationException, SAXException { - InputStream is = null; - try { - is = resource.getInputStream(); + try (InputStream is = resource.getInputStream()) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(isValidating()); factory.setNamespaceAware(true); @@ -111,10 +109,6 @@ public class DefaultDocumentLoader implements DocumentLoader { docBuilder.setErrorHandler(new SimpleSaxErrorHandler(logger)); docBuilder.setEntityResolver(getEntityResolver()); return docBuilder.parse(is); - } finally { - if (is != null) { - is.close(); - } } } } \ No newline at end of file diff --git a/spring-webflow/src/main/java/org/springframework/webflow/engine/support/TransitionExecutingFlowExecutionExceptionHandler.java b/spring-webflow/src/main/java/org/springframework/webflow/engine/support/TransitionExecutingFlowExecutionExceptionHandler.java index b44a8ed7..0232bad6 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/engine/support/TransitionExecutingFlowExecutionExceptionHandler.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/engine/support/TransitionExecutingFlowExecutionExceptionHandler.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2012 the original author or authors. + * Copyright 2004-2020 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. @@ -58,7 +58,7 @@ public class TransitionExecutingFlowExecutionExceptionHandler implements FlowExe /** * The exceptionType to targetStateResolver map. */ - private Map, TargetStateResolver> exceptionTargetStateMappings = new HashMap, TargetStateResolver>(); + private Map, TargetStateResolver> exceptionTargetStateMappings = new HashMap<>(); /** * The list of actions to execute when this handler handles an exception. @@ -190,4 +190,4 @@ public class TransitionExecutingFlowExecutionExceptionHandler implements FlowExe public String toString() { return new ToStringCreator(this).append("exceptionHandlingMappings", exceptionTargetStateMappings).toString(); } -} +} diff --git a/spring-webflow/src/main/java/org/springframework/webflow/execution/repository/snapshot/SerializedFlowExecutionSnapshot.java b/spring-webflow/src/main/java/org/springframework/webflow/execution/repository/snapshot/SerializedFlowExecutionSnapshot.java index 86dd4e81..8f6aeee5 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/execution/repository/snapshot/SerializedFlowExecutionSnapshot.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/execution/repository/snapshot/SerializedFlowExecutionSnapshot.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2012 the original author or authors. + * Copyright 2004-2020 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. @@ -168,13 +168,10 @@ public class SerializedFlowExecutionSnapshot extends FlowExecutionSnapshot imple */ protected byte[] serialize(FlowExecution flowExecution) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(1024); - ObjectOutputStream oos = new ObjectOutputStream(baos); - try { + try (ObjectOutputStream oos = new ObjectOutputStream(baos)) { oos.writeObject(flowExecution); oos.flush(); return baos.toByteArray(); - } finally { - oos.close(); } } @@ -189,11 +186,8 @@ public class SerializedFlowExecutionSnapshot extends FlowExecutionSnapshot imple */ protected FlowExecution deserialize(byte[] data, ClassLoader classLoader) throws IOException, ClassNotFoundException { - ObjectInputStream ois = new ConfigurableObjectInputStream(new ByteArrayInputStream(data), classLoader); - try { + try (ObjectInputStream ois = new ConfigurableObjectInputStream(new ByteArrayInputStream(data), classLoader)) { return (FlowExecution) ois.readObject(); - } finally { - ois.close(); } } @@ -203,12 +197,9 @@ public class SerializedFlowExecutionSnapshot extends FlowExecutionSnapshot imple */ protected byte[] compress(byte[] dataToCompress) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); - GZIPOutputStream gzipos = new GZIPOutputStream(baos); - try { + try (GZIPOutputStream gzipos = new GZIPOutputStream(baos)) { gzipos.write(dataToCompress); gzipos.flush(); - } finally { - gzipos.close(); } return baos.toByteArray(); } @@ -231,7 +222,7 @@ public class SerializedFlowExecutionSnapshot extends FlowExecutionSnapshot imple private static class ConfigurableObjectInputStream extends ObjectInputStream { /* Temporary workaround for SPR-???? */ - private static final HashMap> PRIMITIVE_CLASSES = new HashMap>(8, 1.0F); + private static final HashMap> PRIMITIVE_CLASSES = new HashMap<>(8, 1.0F); static { PRIMITIVE_CLASSES.put("boolean", boolean.class); PRIMITIVE_CLASSES.put("byte", byte.class); diff --git a/spring-webflow/src/main/java/org/springframework/webflow/expression/spel/FlowVariablePropertyAccessor.java b/spring-webflow/src/main/java/org/springframework/webflow/expression/spel/FlowVariablePropertyAccessor.java index d78c18b5..3deba2eb 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/expression/spel/FlowVariablePropertyAccessor.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/expression/spel/FlowVariablePropertyAccessor.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2012 the original author or authors. + * Copyright 2004-2020 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. @@ -50,21 +50,11 @@ public class FlowVariablePropertyAccessor implements PropertyAccessor { private static Map variables = new HashMap<>(); static { - variables.put("currentUser", new FlowVariableAccessor() { - public Object getVariable() { - return RequestContextHolder.getRequestContext().getExternalContext().getCurrentUser(); - } - }); - variables.put("flowRequestContext", new FlowVariableAccessor() { - public Object getVariable() { - return RequestContextHolder.getRequestContext(); - } - }); - variables.put("resourceBundle", new FlowVariableAccessor() { - public Object getVariable() { - return RequestContextHolder.getRequestContext().getActiveFlow().getApplicationContext(); - } - }); + variables.put("currentUser", () -> + RequestContextHolder.getRequestContext().getExternalContext().getCurrentUser()); + variables.put("flowRequestContext", RequestContextHolder::getRequestContext); + variables.put("resourceBundle", () -> + RequestContextHolder.getRequestContext().getActiveFlow().getApplicationContext()); } public Class[] getSpecificTargetClasses() { diff --git a/spring-webflow/src/main/java/org/springframework/webflow/mvc/view/AbstractMvcView.java b/spring-webflow/src/main/java/org/springframework/webflow/mvc/view/AbstractMvcView.java index bdeef514..8366a3f4 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/mvc/view/AbstractMvcView.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/mvc/view/AbstractMvcView.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2018 the original author or authors. + * Copyright 2004-2020 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. @@ -547,8 +547,8 @@ public abstract class AbstractMvcView implements View { if (!beanWrapper.isReadableProperty(propertyNames.get(0))) { return false; } - for (int i=0; i < propertyNames.size(); i++) { - if (!SourceVersion.isName(propertyNames.get(i))) { + for (String propertyName : propertyNames) { + if (!SourceVersion.isName(propertyName)) { return false; } } diff --git a/spring-webflow/src/main/java/org/springframework/webflow/security/SecurityFlowExecutionListener.java b/spring-webflow/src/main/java/org/springframework/webflow/security/SecurityFlowExecutionListener.java index 8b7d90d3..902635cc 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/security/SecurityFlowExecutionListener.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/security/SecurityFlowExecutionListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2015 the original author or authors. + * Copyright 2004-2020 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. @@ -107,7 +107,7 @@ public class SecurityFlowExecutionListener implements FlowExecutionListener { } private AbstractAccessDecisionManager createManager(SecurityRule rule) { - List> voters = new ArrayList>(); + List> voters = new ArrayList<>(); voters.add(new RoleVoter()); if (rule.getComparisonType() == SecurityRule.COMPARISON_ANY) { return new AffirmativeBased(voters); diff --git a/spring-webflow/src/main/java/org/springframework/webflow/test/MockExternalContext.java b/spring-webflow/src/main/java/org/springframework/webflow/test/MockExternalContext.java index 0dd0c3e0..b9820f59 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/test/MockExternalContext.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/test/MockExternalContext.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2012 the original author or authors. + * Copyright 2004-2020 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. @@ -370,7 +370,7 @@ public class MockExternalContext implements ExternalContext { * @param responseAllowed true or false */ public void setResponseAllowed(boolean responseAllowed) { - this.responseAllowed = Boolean.valueOf(responseAllowed); + this.responseAllowed = responseAllowed; } /** diff --git a/spring-webflow/src/main/java/org/springframework/webflow/upgrade/WebFlowUpgrader.java b/spring-webflow/src/main/java/org/springframework/webflow/upgrade/WebFlowUpgrader.java index 8a4079c5..8f1b31d1 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/upgrade/WebFlowUpgrader.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/upgrade/WebFlowUpgrader.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2008 the original author or authors. + * Copyright 2004-2020 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. @@ -63,9 +63,7 @@ public class WebFlowUpgrader { Source source = new StreamSource(flowResource.getInputStream()); Result result = new StreamResult(output); transform(source, result); - } catch (TransformerException e) { - e.printStackTrace(); - } catch (IOException e) { + } catch (TransformerException | IOException e) { e.printStackTrace(); } return output.toString(); diff --git a/spring-webflow/src/main/java/org/springframework/webflow/validation/ValidationHelper.java b/spring-webflow/src/main/java/org/springframework/webflow/validation/ValidationHelper.java index 497775ae..4552f63d 100644 --- a/spring-webflow/src/main/java/org/springframework/webflow/validation/ValidationHelper.java +++ b/spring-webflow/src/main/java/org/springframework/webflow/validation/ValidationHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2008-2012 the original author or authors. + * Copyright 2008-2020 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. @@ -357,7 +357,7 @@ public class ValidationHelper { private Method findValidationMethod(Object model, Object validator, String methodName, Class context) { Class modelClass = AopUtils.getTargetClass(model); - List> modelSearchClasses = new ArrayList>(); + List> modelSearchClasses = new ArrayList<>(); while (modelClass != null) { modelSearchClasses.add(modelClass); modelClass = modelClass.getSuperclass(); diff --git a/spring-webflow/src/test/java/org/springframework/webflow/core/collection/LocalAttributeMapTests.java b/spring-webflow/src/test/java/org/springframework/webflow/core/collection/LocalAttributeMapTests.java index 2daa18b6..68cf0988 100644 --- a/spring-webflow/src/test/java/org/springframework/webflow/core/collection/LocalAttributeMapTests.java +++ b/spring-webflow/src/test/java/org/springframework/webflow/core/collection/LocalAttributeMapTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2012 the original author or authors. + * Copyright 2004-2020 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,33 +45,33 @@ public class LocalAttributeMapTests { attributeMap.put("integer", 12345); attributeMap.put("boolean", true); attributeMap.put("long", 12345L); - attributeMap.put("double", new Double(12345)); - attributeMap.put("float", new Float(12345)); + attributeMap.put("double", 12345d); + attributeMap.put("float", 12345f); attributeMap.put("bigDecimal", new BigDecimal("12345.67")); attributeMap.put("bean", new TestBean()); attributeMap.put("stringArray", new String[] { "1", "2", "3" }); attributeMap.put("collection", new LinkedList<>()); } - @Test + @Test public void testGet() { TestBean bean = (TestBean) attributeMap.get("bean"); assertNotNull(bean); } - @Test + @Test public void testGetNull() { TestBean bean = (TestBean) attributeMap.get("bogus"); assertNull(bean); } - @Test + @Test public void testGetRequiredType() { TestBean bean = attributeMap.get("bean", TestBean.class); assertNotNull(bean); } - @Test + @Test public void testGetWrongType() { try { attributeMap.get("bean", String.class); @@ -81,7 +81,7 @@ public class LocalAttributeMapTests { } } - @Test + @Test public void testGetWithDefaultOption() { TestBean d = new TestBean(); TestBean bean = (TestBean) attributeMap.get("bean", d); @@ -89,20 +89,20 @@ public class LocalAttributeMapTests { assertNotSame(bean, d); } - @Test + @Test public void testGetWithDefault() { TestBean d = new TestBean(); TestBean bean = (TestBean) attributeMap.get("bogus", d); assertSame(bean, d); } - @Test + @Test public void testGetRequired() { TestBean bean = (TestBean) attributeMap.getRequired("bean"); assertNotNull(bean); } - @Test + @Test public void testGetRequiredNotPresent() { try { attributeMap.getRequired("bogus"); @@ -112,13 +112,13 @@ public class LocalAttributeMapTests { } } - @Test + @Test public void testGetRequiredOfType() { TestBean bean = attributeMap.getRequired("bean", TestBean.class); assertNotNull(bean); } - @Test + @Test public void testGetRequiredWrongType() { try { attributeMap.getRequired("bean", String.class); @@ -128,13 +128,13 @@ public class LocalAttributeMapTests { } } - @Test + @Test public void testGetNumber() { BigDecimal bd = attributeMap.getNumber("bigDecimal", BigDecimal.class); assertEquals(new BigDecimal("12345.67"), bd); } - @Test + @Test public void testGetNumberWrongType() { try { attributeMap.getNumber("bigDecimal", Integer.class); @@ -144,7 +144,7 @@ public class LocalAttributeMapTests { } } - @Test + @Test public void testGetNumberWithDefaultOption() { BigDecimal d = new BigDecimal("1"); BigDecimal bd = attributeMap.getNumber("bigDecimal", BigDecimal.class, d); @@ -152,7 +152,7 @@ public class LocalAttributeMapTests { assertNotSame(d, bd); } - @Test + @Test public void testGetNumberWithDefault() { BigDecimal d = new BigDecimal("1"); BigDecimal bd = attributeMap.getNumber("bogus", BigDecimal.class, d); @@ -160,13 +160,13 @@ public class LocalAttributeMapTests { assertSame(d, bd); } - @Test + @Test public void testGetNumberRequired() { BigDecimal bd = attributeMap.getRequiredNumber("bigDecimal", BigDecimal.class); assertEquals(new BigDecimal("12345.67"), bd); } - @Test + @Test public void testGetNumberRequiredNotPresent() { try { attributeMap.getRequiredNumber("bogus", BigDecimal.class); @@ -176,25 +176,25 @@ public class LocalAttributeMapTests { } } - @Test + @Test public void testGetInteger() { Integer i = attributeMap.getInteger("integer"); assertEquals(new Integer(12345), i); } - @Test + @Test public void testGetIntegerNull() { Integer i = attributeMap.getInteger("bogus"); assertNull(i); } - @Test + @Test public void testGetIntegerRequired() { Integer i = attributeMap.getRequiredInteger("integer"); assertEquals(new Integer(12345), i); } - @Test + @Test public void testGetIntegerRequiredNotPresent() { try { attributeMap.getRequiredInteger("bogus"); @@ -204,25 +204,25 @@ public class LocalAttributeMapTests { } } - @Test + @Test public void testGetLong() { Long i = attributeMap.getLong("long"); assertEquals(new Long(12345), i); } - @Test + @Test public void testGetLongNull() { Long i = attributeMap.getLong("bogus"); assertNull(i); } - @Test + @Test public void testGetLongRequired() { Long i = attributeMap.getRequiredLong("long"); assertEquals(new Long(12345), i); } - @Test + @Test public void testGetLongRequiredNotPresent() { try { attributeMap.getRequiredLong("bogus"); @@ -232,25 +232,25 @@ public class LocalAttributeMapTests { } } - @Test + @Test public void testGetString() { String i = attributeMap.getString("string"); assertEquals("A string", i); } - @Test + @Test public void testGetStringNull() { String i = attributeMap.getString("bogus"); assertNull(i); } - @Test + @Test public void testGetStringRequired() { String i = attributeMap.getRequiredString("string"); assertEquals("A string", i); } - @Test + @Test public void testGetStringRequiredNotPresent() { try { attributeMap.getRequiredString("bogus"); @@ -260,25 +260,25 @@ public class LocalAttributeMapTests { } } - @Test + @Test public void testGetBoolean() { Boolean i = attributeMap.getBoolean("boolean"); assertEquals(Boolean.TRUE, i); } - @Test + @Test public void testGetBooleanNull() { Boolean i = attributeMap.getBoolean("bogus"); assertNull(i); } - @Test + @Test public void testGetBooleanRequired() { Boolean i = attributeMap.getRequiredBoolean("boolean"); assertEquals(Boolean.TRUE, i); } - @Test + @Test public void testGetBooleanRequiredNotPresent() { try { attributeMap.getRequiredBoolean("bogus"); @@ -288,25 +288,25 @@ public class LocalAttributeMapTests { } } - @Test + @Test public void testGetArray() { String[] i = attributeMap.getArray("stringArray", String[].class); assertEquals(3, i.length); } - @Test + @Test public void testGetArrayNull() { String[] i = attributeMap.getArray("A bogus array", String[].class); assertNull(i); } - @Test + @Test public void testGetArrayRequired() { String[] i = attributeMap.getRequiredArray("stringArray", String[].class); assertEquals(3, i.length); } - @Test + @Test public void testGetArrayRequiredNotPresent() { try { attributeMap.getRequiredArray("A bogus array", String[].class); @@ -317,7 +317,7 @@ public class LocalAttributeMapTests { } @SuppressWarnings("unchecked") - @Test + @Test public void testGetCollection() { List i = attributeMap.getCollection("collection", List.class); assertTrue(i instanceof LinkedList); @@ -325,20 +325,20 @@ public class LocalAttributeMapTests { } @SuppressWarnings("unchecked") - @Test + @Test public void testGetCollectionNull() { List i = attributeMap.getCollection("bogus", List.class); assertNull(i); } @SuppressWarnings("unchecked") - @Test + @Test public void testGetCollectionRequired() { List i = attributeMap.getRequiredCollection("collection", List.class); assertEquals(0, i.size()); } - @Test + @Test public void testGetCollectionRequiredNotPresent() { try { attributeMap.getRequiredCollection("A bogus collection"); @@ -348,13 +348,13 @@ public class LocalAttributeMapTests { } } - @Test + @Test public void testGetMap() { Map map = attributeMap.asMap(); assertEquals(10, map.size()); } - @Test + @Test public void testUnion() { LocalAttributeMap one = new LocalAttributeMap<>(); one.put("foo", "bar"); @@ -371,7 +371,7 @@ public class LocalAttributeMapTests { assertEquals("boo", three.get("bar")); } - @Test + @Test public void testEquality() { LocalAttributeMap map = new LocalAttributeMap<>(); map.put("foo", "bar"); @@ -382,7 +382,7 @@ public class LocalAttributeMapTests { assertEquals(map, map2); } - @Test + @Test public void testExtract() { assertEquals("A string", attributeMap.extract("string")); assertFalse(attributeMap.contains("string")); diff --git a/spring-webflow/src/test/java/org/springframework/webflow/expression/el/ImplicitFlowVariableELResolverTests.java b/spring-webflow/src/test/java/org/springframework/webflow/expression/el/ImplicitFlowVariableELResolverTests.java index a6ee624b..102637e3 100644 --- a/spring-webflow/src/test/java/org/springframework/webflow/expression/el/ImplicitFlowVariableELResolverTests.java +++ b/spring-webflow/src/test/java/org/springframework/webflow/expression/el/ImplicitFlowVariableELResolverTests.java @@ -1,19 +1,14 @@ package org.springframework.webflow.expression.el; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertSame; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; - import java.security.Principal; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import javax.el.ELResolver; import javax.el.PropertyNotWritableException; import org.junit.jupiter.api.Test; + import org.springframework.binding.message.MessageContext; import org.springframework.util.ClassUtils; import org.springframework.webflow.context.ExternalContext; @@ -27,6 +22,11 @@ import org.springframework.webflow.test.MockFlowExecutionContext; import org.springframework.webflow.test.MockFlowExecutionKey; import org.springframework.webflow.test.MockRequestContext; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + public class ImplicitFlowVariableELResolverTests extends FlowDependentELResolverTestCase { private static final List vars = new ArrayList<>(); @@ -261,9 +261,7 @@ public class ImplicitFlowVariableELResolverTests extends FlowDependentELResolver @Test public void testIsReadOnly_AllVars() { RequestContextHolder.setRequestContext(new MockRequestContext()); - Iterator i = vars.iterator(); - while (i.hasNext()) { - String var = i.next(); + for (String var : vars) { assertTrue(context.getELResolver().isReadOnly(context, null, var)); } } @@ -271,9 +269,7 @@ public class ImplicitFlowVariableELResolverTests extends FlowDependentELResolver @Test public void testSetValue_AllVars() { RequestContextHolder.setRequestContext(new MockRequestContext()); - Iterator i = vars.iterator(); - while (i.hasNext()) { - String var = i.next(); + for (String var : vars) { try { context.getELResolver().setValue(context, null, var, new Object()); fail("setValue should not be allowed"); diff --git a/spring-webflow/src/test/java/org/springframework/webflow/expression/spel/ScopeSearchingPropertyAccessorTests.java b/spring-webflow/src/test/java/org/springframework/webflow/expression/spel/ScopeSearchingPropertyAccessorTests.java index b80ef231..235e060d 100644 --- a/spring-webflow/src/test/java/org/springframework/webflow/expression/spel/ScopeSearchingPropertyAccessorTests.java +++ b/spring-webflow/src/test/java/org/springframework/webflow/expression/spel/ScopeSearchingPropertyAccessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2012 the original author or authors. + * Copyright 2004-2020 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. @@ -15,20 +15,19 @@ */ package org.springframework.webflow.expression.spel; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertSame; - import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; + import org.springframework.expression.TypedValue; import org.springframework.expression.spel.support.StandardEvaluationContext; import org.springframework.webflow.engine.ViewState; import org.springframework.webflow.execution.RequestContext; -import org.springframework.webflow.execution.View; -import org.springframework.webflow.execution.ViewFactory; import org.springframework.webflow.test.MockFlowSession; import org.springframework.webflow.test.MockRequestContext; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertSame; + public class ScopeSearchingPropertyAccessorTests { private ScopeSearchingPropertyAccessor accessor = new ScopeSearchingPropertyAccessor(); @@ -79,10 +78,8 @@ public class ScopeSearchingPropertyAccessorTests { protected void initView(MockRequestContext requestContext) { ((MockFlowSession) requestContext.getFlowExecutionContext().getActiveSession()).setState(new ViewState( - requestContext.getRootFlow(), "view", new ViewFactory() { - public View getView(RequestContext context) { - throw new UnsupportedOperationException("Not implemented"); - } + requestContext.getRootFlow(), "view", context -> { + throw new UnsupportedOperationException("Not implemented"); })); } diff --git a/spring-webflow/src/test/java/org/springframework/webflow/persistence/TestBean.java b/spring-webflow/src/test/java/org/springframework/webflow/persistence/TestBean.java index d7dd833b..70bce37c 100644 --- a/spring-webflow/src/test/java/org/springframework/webflow/persistence/TestBean.java +++ b/spring-webflow/src/test/java/org/springframework/webflow/persistence/TestBean.java @@ -1,5 +1,5 @@ /* - * Copyright 2004-2012 the original author or authors. + * Copyright 2004-2020 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. @@ -37,7 +37,7 @@ public class TestBean { } public TestBean(long id, String name) { - this.entityId = new Long(id); + this.entityId = id; this.name = name; }