Skip to content

Commit

Permalink
Polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoeller committed Nov 22, 2018
1 parent ed9afa3 commit 85b5c5a
Show file tree
Hide file tree
Showing 18 changed files with 118 additions and 115 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2015 the original author or authors.
* Copyright 2002-2018 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.
Expand Down Expand Up @@ -43,8 +43,10 @@
* Decorator for a standard {@link BeanInfo} object, e.g. as created by
* {@link Introspector#getBeanInfo(Class)}, designed to discover and register static
* and/or non-void returning setter methods. For example:
*
* <pre class="code">
* public class Bean {
*
* private Foo foo;
*
* public Foo getFoo() {
Expand All @@ -56,6 +58,7 @@
* return this;
* }
* }</pre>
*
* The standard JavaBeans {@code Introspector} will discover the {@code getFoo} read
* method, but will bypass the {@code #setFoo(Foo)} write method, because its non-void
* returning signature does not comply with the JavaBeans specification.
Expand All @@ -68,6 +71,7 @@
* indexed properties</a> are fully supported.
*
* @author Chris Beams
* @author Juergen Hoeller
* @since 3.1
* @see #ExtendedBeanInfo(BeanInfo)
* @see ExtendedBeanInfoFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public void customAsyncAnnotationIsPropagated() {
Object bean = ctx.getBean(CustomAsyncBean.class);
assertTrue(AopUtils.isAopProxy(bean));
boolean isAsyncAdvised = false;
for (Advisor advisor : ((Advised)bean).getAdvisors()) {
for (Advisor advisor : ((Advised) bean).getAdvisors()) {
if (advisor instanceof AsyncAnnotationAdvisor) {
isAsyncAdvised = true;
break;
Expand Down Expand Up @@ -365,7 +365,8 @@ public AsyncBean asyncBean() {
@EnableAsync
static class AsyncConfigWithMockito {

@Bean @Lazy
@Bean
@Lazy
public AsyncBean asyncBean() {
return Mockito.mock(AsyncBean.class);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2018 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.
Expand All @@ -23,28 +23,29 @@
import org.springframework.jndi.JndiTemplate;

/**
* Simple extension of the JndiTemplate class that always returns
* a given object. Very useful for testing. Effectively a mock object.
* Simple extension of the JndiTemplate class that always returns a given object.
*
* <p>Very useful for testing. Effectively a mock object.
*
* @author Rod Johnson
* @author Juergen Hoeller
*/
public class ExpectedLookupTemplate extends JndiTemplate {

private final Map<String, Object> jndiObjects = new ConcurrentHashMap<String, Object>();
private final Map<String, Object> jndiObjects = new ConcurrentHashMap<String, Object>(16);


/**
* Construct a new JndiTemplate that will always return given objects
* for given names. To be populated through {@code addObject} calls.
* Construct a new JndiTemplate that will always return given objects for
* given names. To be populated through {@code addObject} calls.
* @see #addObject(String, Object)
*/
public ExpectedLookupTemplate() {
}

/**
* Construct a new JndiTemplate that will always return the
* given object, but honour only requests for the given name.
* Construct a new JndiTemplate that will always return the given object,
* but honour only requests for the given name.
* @param name the name the client is expected to look up
* @param object the object that will be returned
*/
Expand All @@ -54,20 +55,18 @@ public ExpectedLookupTemplate(String name, Object object) {


/**
* Add the given object to the list of JNDI objects that this
* template will expose.
* Add the given object to the list of JNDI objects that this template will expose.
* @param name the name the client is expected to look up
* @param object the object that will be returned
*/
public void addObject(String name, Object object) {
this.jndiObjects.put(name, object);
}


/**
* If the name is the expected name specified in the constructor,
* return the object provided in the constructor. If the name is
* unexpected, a respective NamingException gets thrown.
* If the name is the expected name specified in the constructor, return the
* object provided in the constructor. If the name is unexpected, a
* respective NamingException gets thrown.
*/
@Override
public Object lookup(String name) throws NamingException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2018 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.
Expand All @@ -26,6 +26,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;

/**
Expand All @@ -35,13 +36,14 @@
* configure JNDI appropriately, so that {@code new InitialContext()}
* will expose the required objects. Also usable for standalone applications,
* e.g. for binding a JDBC DataSource to a well-known JNDI location, to be
* able to use traditional J2EE data access code outside of a J2EE container.
* able to use traditional Java EE data access code outside of a Java EE
* container.
*
* <p>There are various choices for DataSource implementations:
* <ul>
* <li>{@code SingleConnectionDataSource} (using the same Connection for all getConnection calls)
* <li>{@code DriverManagerDataSource} (creating a new Connection on each getConnection call)
* <li>Apache's Jakarta Commons DBCP offers {@code org.apache.commons.dbcp.BasicDataSource} (a real pool)
* <li>Apache's Commons DBCP offers {@code org.apache.commons.dbcp.BasicDataSource} (a real pool)
* </ul>
*
* <p>Typical usage in bootstrap code:
Expand Down Expand Up @@ -98,7 +100,7 @@ public static SimpleNamingContextBuilder getCurrentContextBuilder() {

/**
* If no SimpleNamingContextBuilder is already configuring JNDI,
* create and activate one. Otherwise take the existing activate
* create and activate one. Otherwise take the existing activated
* SimpleNamingContextBuilder, clear it and return it.
* <p>This is mainly intended for test suites that want to
* reinitialize JNDI bindings from scratch repeatedly.
Expand Down Expand Up @@ -137,12 +139,10 @@ public void activate() throws IllegalStateException, NamingException {
logger.info("Activating simple JNDI environment");
synchronized (initializationLock) {
if (!initialized) {
if (NamingManager.hasInitialContextFactoryBuilder()) {
throw new IllegalStateException(
Assert.state(!NamingManager.hasInitialContextFactoryBuilder(),
"Cannot activate SimpleNamingContextBuilder: there is already a JNDI provider registered. " +
"Note that JNDI is a JVM-wide service, shared at the JVM system class loader level, " +
"with no reset option. As a consequence, a JNDI provider must only be registered once per JVM.");
}
NamingManager.setInitialContextFactoryBuilder(this);
initialized = true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
Expand Down Expand Up @@ -170,7 +170,7 @@ public static boolean containsElement(Object[] array, Object element) {
/**
* Check whether the given array of enum constants contains a constant with the given name,
* ignoring case when determining a match.
* @param enumValues the enum values to check, typically the product of a call to MyEnum.values()
* @param enumValues the enum values to check, typically obtained via {@code MyEnum.values()}
* @param constant the constant name to find (must not be null or empty string)
* @return whether the constant has been found in the given array
*/
Expand All @@ -180,15 +180,14 @@ public static boolean containsConstant(Enum<?>[] enumValues, String constant) {

/**
* Check whether the given array of enum constants contains a constant with the given name.
* @param enumValues the enum values to check, typically the product of a call to MyEnum.values()
* @param enumValues the enum values to check, typically obtained via {@code MyEnum.values()}
* @param constant the constant name to find (must not be null or empty string)
* @param caseSensitive whether case is significant in determining a match
* @return whether the constant has been found in the given array
*/
public static boolean containsConstant(Enum<?>[] enumValues, String constant, boolean caseSensitive) {
for (Enum<?> candidate : enumValues) {
if (caseSensitive ?
candidate.toString().equals(constant) :
if (caseSensitive ? candidate.toString().equals(constant) :
candidate.toString().equalsIgnoreCase(constant)) {
return true;
}
Expand All @@ -199,7 +198,7 @@ public static boolean containsConstant(Enum<?>[] enumValues, String constant, bo
/**
* Case insensitive alternative to {@link Enum#valueOf(Class, String)}.
* @param <E> the concrete Enum type
* @param enumValues the array of all Enum constants in question, usually per Enum.values()
* @param enumValues the array of all Enum constants in question, usually per {@code Enum.values()}
* @param constant the constant to get the enum value of
* @throws IllegalArgumentException if the given constant is not found in the given array
* of enum values. Use {@link #containsConstant(Enum[], String)} as a guard to avoid this exception.
Expand All @@ -210,9 +209,8 @@ public static <E extends Enum<?>> E caseInsensitiveValueOf(E[] enumValues, Strin
return candidate;
}
}
throw new IllegalArgumentException(
String.format("constant [%s] does not exist in enum type %s",
constant, enumValues.getClass().getComponentType().getName()));
throw new IllegalArgumentException("Constant [" + constant + "] does not exist in enum type " +
enumValues.getClass().getComponentType().getName());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -635,7 +634,7 @@ private static List<Method> findConcreteMethodsOnInterfaces(Class<?> clazz) {
for (Method ifcMethod : ifc.getMethods()) {
if (!Modifier.isAbstract(ifcMethod.getModifiers())) {
if (result == null) {
result = new LinkedList<Method>();
result = new ArrayList<Method>();
}
result.add(ifcMethod);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class ObjectUtilsTests {
@Rule
public final ExpectedException exception = ExpectedException.none();


@Test
public void isCheckedException() {
assertTrue(ObjectUtils.isCheckedException(new Exception()));
Expand Down Expand Up @@ -101,8 +102,8 @@ public void isEmptyArray() {
assertTrue(isEmpty(new Object[0]));
assertTrue(isEmpty(new Integer[0]));

assertFalse(isEmpty(new int[] { 42 }));
assertFalse(isEmpty(new Integer[] { new Integer(42) }));
assertFalse(isEmpty(new int[] {42}));
assertFalse(isEmpty(new Integer[] {42}));
}

@Test
Expand Down Expand Up @@ -271,7 +272,7 @@ public void hashCodeWithFloat() {
@Test
@Deprecated
public void hashCodeWithLong() {
long lng = 883l;
long lng = 883L;
int expected = (new Long(lng)).hashCode();
assertEquals(expected, ObjectUtils.hashCode(lng));
}
Expand Down Expand Up @@ -489,12 +490,12 @@ public void nullSafeHashCodeWithIntArrayEqualToNull() {

@Test
public void nullSafeHashCodeWithLongArray() {
long lng = 7993l;
long lng = 7993L;
int expected = 31 * 7 + (int) (lng ^ (lng >>> 32));
lng = 84320l;
lng = 84320L;
expected = 31 * expected + (int) (lng ^ (lng >>> 32));

long[] array = {7993l, 84320l};
long[] array = {7993L, 84320L};
int actual = ObjectUtils.nullSafeHashCode(array);

assertEquals(expected, actual);
Expand Down Expand Up @@ -715,7 +716,7 @@ public void nullSafeToStringWithIntArrayEqualToNull() {

@Test
public void nullSafeToStringWithLongArray() {
long[] array = {434l, 23423l};
long[] array = {434L, 23423L};
assertEquals("{434, 23423}", ObjectUtils.nullSafeToString(array));
}

Expand All @@ -737,7 +738,7 @@ public void nullSafeToStringWithPlainOldString() {

@Test
public void nullSafeToStringWithObjectArray() {
Object[] array = {"Han", new Long(43)};
Object[] array = {"Han", Long.valueOf(43)};
assertEquals("{Han, 43}", ObjectUtils.nullSafeToString(array));
}

Expand Down Expand Up @@ -807,7 +808,8 @@ public void caseInsensitiveValueOf() {
assertThat(ObjectUtils.caseInsensitiveValueOf(Tropes.values(), "BAR"), is(Tropes.BAR));

exception.expect(IllegalArgumentException.class);
exception.expectMessage(is("constant [bogus] does not exist in enum type org.springframework.util.ObjectUtilsTests$Tropes"));
exception.expectMessage(
is("Constant [bogus] does not exist in enum type org.springframework.util.ObjectUtilsTests$Tropes"));
ObjectUtils.caseInsensitiveValueOf(Tropes.values(), "bogus");
}

Expand All @@ -818,6 +820,6 @@ private void assertEqualHashCodes(int expected, Object array) {
}


enum Tropes { FOO, BAR, baz }
enum Tropes {FOO, BAR, baz}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
Expand Down Expand Up @@ -914,6 +914,7 @@ <T>List<T> queryForList(String sql, Object[] args, int[] argTypes, Class<T> elem
* @param pss ParameterizedPreparedStatementSetter to use
* @return an array containing for each batch another array containing the numbers of rows affected
* by each update in the batch
* @since 3.1
*/
<T> int[][] batchUpdate(String sql, Collection<T> batchArgs, int batchSize,
ParameterizedPreparedStatementSetter<T> pss) throws DataAccessException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
Expand Down Expand Up @@ -1018,11 +1018,7 @@ public <T> int[][] batchUpdate(String sql, final Collection<T> batchArgs, final
public int[][] doInPreparedStatement(PreparedStatement ps) throws SQLException {
List<int[]> rowsAffected = new ArrayList<int[]>();
try {
boolean batchSupported = true;
if (!JdbcUtils.supportsBatchUpdates(ps.getConnection())) {
batchSupported = false;
logger.warn("JDBC Driver does not support Batch updates; resorting to single statement execution");
}
boolean batchSupported = JdbcUtils.supportsBatchUpdates(ps.getConnection());
int n = 0;
for (T obj : batchArgs) {
pss.setValues(ps, obj);
Expand Down
Loading

0 comments on commit 85b5c5a

Please sign in to comment.