Make sure placement of curly braces is consistent

This commit is contained in:
Benedikt Ritter 2017-06-06 22:14:47 +02:00
parent 3a818ed6a8
commit 309b34f057
No known key found for this signature in database
GPG Key ID: 9DAADC1C9FCC82D0
24 changed files with 1291 additions and 1134 deletions

View File

@ -49,5 +49,8 @@ limitations under the License.
<module name="ModifierOrder"/>
<module name="RedundantModifier"/>
<module name="UpperEll" />
<module name="LeftCurly"/>
<module name="NeedBraces"/>
<module name="RightCurly"/>
</module>
</module>

View File

@ -805,7 +805,9 @@ public class ObjectUtils {
* @return the boolean v, unchanged
* @since 3.2
*/
public static boolean CONST(final boolean v) { return v; }
public static boolean CONST(final boolean v) {
return v;
}
/**
* This method returns the provided value unchanged.
@ -824,7 +826,9 @@ public class ObjectUtils {
* @return the byte v, unchanged
* @since 3.2
*/
public static byte CONST(final byte v) { return v; }
public static byte CONST(final byte v) {
return v;
}
/**
* This method returns the provided value unchanged.
@ -870,7 +874,9 @@ public class ObjectUtils {
* @return the char v, unchanged
* @since 3.2
*/
public static char CONST(final char v) { return v; }
public static char CONST(final char v) {
return v;
}
/**
* This method returns the provided value unchanged.
@ -889,7 +895,9 @@ public class ObjectUtils {
* @return the short v, unchanged
* @since 3.2
*/
public static short CONST(final short v) { return v; }
public static short CONST(final short v) {
return v;
}
/**
* This method returns the provided value unchanged.
@ -936,7 +944,9 @@ public class ObjectUtils {
* @return the int v, unchanged
* @since 3.2
*/
public static int CONST(final int v) { return v; }
public static int CONST(final int v) {
return v;
}
/**
* This method returns the provided value unchanged.
@ -955,7 +965,9 @@ public class ObjectUtils {
* @return the long v, unchanged
* @since 3.2
*/
public static long CONST(final long v) { return v; }
public static long CONST(final long v) {
return v;
}
/**
* This method returns the provided value unchanged.
@ -974,7 +986,9 @@ public class ObjectUtils {
* @return the float v, unchanged
* @since 3.2
*/
public static float CONST(final float v) { return v; }
public static float CONST(final float v) {
return v;
}
/**
* This method returns the provided value unchanged.
@ -993,7 +1007,9 @@ public class ObjectUtils {
* @return the double v, unchanged
* @since 3.2
*/
public static double CONST(final double v) { return v; }
public static double CONST(final double v) {
return v;
}
/**
* This method returns the provided value unchanged.
@ -1013,6 +1029,8 @@ public class ObjectUtils {
* @return the genericized Object v, unchanged (typically a String).
* @since 3.2
*/
public static <T> T CONST(final T v) { return v; }
public static <T> T CONST(final T v) {
return v;
}
}

View File

@ -8188,9 +8188,8 @@ public class StringUtils {
return m <= threshold ? m : -1;
} else if (m == 0) {
return n <= threshold ? n : -1;
}
} else if (Math.abs(n - m) > threshold) {
// no need to calculate the distance if the length difference is greater than the threshold
else if (Math.abs(n - m) > threshold) {
return -1;
}

View File

@ -627,13 +627,12 @@ public class EqualsBuilder implements Builder<Boolean> {
* @param rhs the right hand object
*/
private void appendArray(final Object lhs, final Object rhs) {
if (lhs.getClass() != rhs.getClass()) {
// Here when we compare different dimensions, for example: a boolean[][] to a boolean[]
this.setEquals(false);
}
// 'Switch' on type of array, to dispatch to the correct handler
// First we compare different dimensions, for example: a boolean[][] to a boolean[]
// then we 'Switch' on type of array, to dispatch to the correct handler
// This handles multi dimensional arrays of the same depth
else if (lhs instanceof long[]) {
if (lhs.getClass() != rhs.getClass()) {
this.setEquals(false);
} else if (lhs instanceof long[]) {
append((long[]) lhs, (long[]) rhs);
} else if (lhs instanceof int[]) {
append((int[]) lhs, (int[]) rhs);

View File

@ -169,12 +169,10 @@ abstract class MemberUtils {
if (noVarArgsPassed) {
// When no varargs passed, the best match is the most generic matching type, not the most specific.
totalCost += getObjectTransformationCost(destClass, Object.class) + varArgsCost;
}
else if (explicitArrayForVarags) {
} else if (explicitArrayForVarags) {
final Class<?> sourceClass = srcArgs[srcArgs.length-1].getComponentType();
totalCost += getObjectTransformationCost(sourceClass, destClass) + varArgsCost;
}
else {
} else {
// This is typical varargs case.
for (int i = destArgs.length-1; i < srcArgs.length; i++) {
final Class<?> srcClass = srcArgs[i];
@ -283,8 +281,13 @@ abstract class MemberUtils {
private final Class<?>[] parameterTypes;
private final boolean isVarArgs;
private static Executable of(final Method method) { return new Executable(method); }
private static Executable of(final Constructor<?> constructor) { return new Executable(constructor); }
private static Executable of(final Method method) {
return new Executable(method);
}
private static Executable of(final Constructor<?> constructor) {
return new Executable(constructor);
}
private Executable(final Method method) {
parameterTypes = method.getParameterTypes();
@ -296,9 +299,13 @@ abstract class MemberUtils {
isVarArgs = constructor.isVarArgs();
}
public Class<?>[] getParameterTypes() { return parameterTypes; }
public Class<?>[] getParameterTypes() {
return parameterTypes;
}
public boolean isVarArgs() { return isVarArgs; }
public boolean isVarArgs() {
return isVarArgs;
}
}
}

View File

@ -34,7 +34,10 @@ public class EntityArrays {
* characters to their named HTML 3.x equivalents.
* @return the mapping table
*/
public static String[][] ISO8859_1_ESCAPE() { return ISO8859_1_ESCAPE.clone(); }
public static String[][] ISO8859_1_ESCAPE() {
return ISO8859_1_ESCAPE.clone();
}
private static final String[][] ISO8859_1_ESCAPE = {
{"\u00A0", "&nbsp;"}, // non-breaking space
{"\u00A1", "&iexcl;"}, // inverted exclamation mark
@ -138,7 +141,10 @@ public class EntityArrays {
* Reverse of {@link #ISO8859_1_ESCAPE()} for unescaping purposes.
* @return the mapping table
*/
public static String[][] ISO8859_1_UNESCAPE() { return ISO8859_1_UNESCAPE.clone(); }
public static String[][] ISO8859_1_UNESCAPE() {
return ISO8859_1_UNESCAPE.clone();
}
private static final String[][] ISO8859_1_UNESCAPE = invert(ISO8859_1_ESCAPE);
/**
@ -147,7 +153,10 @@ public class EntityArrays {
* HTML 4.0 character entities.
* @return the mapping table
*/
public static String[][] HTML40_EXTENDED_ESCAPE() { return HTML40_EXTENDED_ESCAPE.clone(); }
public static String[][] HTML40_EXTENDED_ESCAPE() {
return HTML40_EXTENDED_ESCAPE.clone();
}
private static final String[][] HTML40_EXTENDED_ESCAPE = {
// <!-- Latin Extended-B -->
{"\u0192", "&fnof;"}, // latin small f with hook = function= florin, U+0192 ISOtech -->
@ -349,7 +358,10 @@ public class EntityArrays {
* Reverse of {@link #HTML40_EXTENDED_ESCAPE()} for unescaping purposes.
* @return the mapping table
*/
public static String[][] HTML40_EXTENDED_UNESCAPE() { return HTML40_EXTENDED_UNESCAPE.clone(); }
public static String[][] HTML40_EXTENDED_UNESCAPE() {
return HTML40_EXTENDED_UNESCAPE.clone();
}
private static final String[][] HTML40_EXTENDED_UNESCAPE = invert(HTML40_EXTENDED_ESCAPE);
/**
@ -358,7 +370,10 @@ public class EntityArrays {
* Namely: {@code " & < >}
* @return the mapping table
*/
public static String[][] BASIC_ESCAPE() { return BASIC_ESCAPE.clone(); }
public static String[][] BASIC_ESCAPE() {
return BASIC_ESCAPE.clone();
}
private static final String[][] BASIC_ESCAPE = {
{"\"", "&quot;"}, // " - double-quote
{"&", "&amp;"}, // & - ampersand
@ -370,14 +385,20 @@ public class EntityArrays {
* Reverse of {@link #BASIC_ESCAPE()} for unescaping purposes.
* @return the mapping table
*/
public static String[][] BASIC_UNESCAPE() { return BASIC_UNESCAPE.clone(); }
public static String[][] BASIC_UNESCAPE() {
return BASIC_UNESCAPE.clone();
}
private static final String[][] BASIC_UNESCAPE = invert(BASIC_ESCAPE);
/**
* Mapping to escape the apostrophe character to its XML character entity.
* @return the mapping table
*/
public static String[][] APOS_ESCAPE() { return APOS_ESCAPE.clone(); }
public static String[][] APOS_ESCAPE() {
return APOS_ESCAPE.clone();
}
private static final String[][] APOS_ESCAPE = {
{"'", "&apos;"}, // XML apostrophe
};
@ -386,7 +407,10 @@ public class EntityArrays {
* Reverse of {@link #APOS_ESCAPE()} for unescaping purposes.
* @return the mapping table
*/
public static String[][] APOS_UNESCAPE() { return APOS_UNESCAPE.clone(); }
public static String[][] APOS_UNESCAPE() {
return APOS_UNESCAPE.clone();
}
private static final String[][] APOS_UNESCAPE = invert(APOS_ESCAPE);
/**
@ -395,7 +419,10 @@ public class EntityArrays {
* Namely: {@code \b \n \t \f \r}
* @return the mapping table
*/
public static String[][] JAVA_CTRL_CHARS_ESCAPE() { return JAVA_CTRL_CHARS_ESCAPE.clone(); }
public static String[][] JAVA_CTRL_CHARS_ESCAPE() {
return JAVA_CTRL_CHARS_ESCAPE.clone();
}
private static final String[][] JAVA_CTRL_CHARS_ESCAPE = {
{"\b", "\\b"},
{"\n", "\\n"},
@ -408,7 +435,10 @@ public class EntityArrays {
* Reverse of {@link #JAVA_CTRL_CHARS_ESCAPE()} for unescaping purposes.
* @return the mapping table
*/
public static String[][] JAVA_CTRL_CHARS_UNESCAPE() { return JAVA_CTRL_CHARS_UNESCAPE.clone(); }
public static String[][] JAVA_CTRL_CHARS_UNESCAPE() {
return JAVA_CTRL_CHARS_UNESCAPE.clone();
}
private static final String[][] JAVA_CTRL_CHARS_UNESCAPE = invert(JAVA_CTRL_CHARS_ESCAPE);
/**

View File

@ -100,8 +100,7 @@ public class NumericEntityUnescaper extends CharSequenceTranslator {
// Note that this supports character codes without a ; on the end
while(end < seqEnd && ( input.charAt(end) >= '0' && input.charAt(end) <= '9' ||
input.charAt(end) >= 'a' && input.charAt(end) <= 'f' ||
input.charAt(end) >= 'A' && input.charAt(end) <= 'F' ) )
{
input.charAt(end) >= 'A' && input.charAt(end) <= 'F' ) ) {
end++;
}

View File

@ -380,8 +380,7 @@ public class DateUtils {
if (fdp.parse(str, pos, calendar) && pos.getIndex()==str.length()) {
return calendar.getTime();
}
}
catch(final IllegalArgumentException ignore) {
} catch(final IllegalArgumentException ignore) {
// leniency is preventing calendar from being set
}
pos.setIndex(0);

View File

@ -138,11 +138,9 @@ public class FastDateParser implements DateParser, Serializable {
if(centuryStart!=null) {
definingCalendar.setTime(centuryStart);
centuryStartYear= definingCalendar.get(Calendar.YEAR);
}
else if(locale.equals(JAPANESE_IMPERIAL)) {
} else if(locale.equals(JAPANESE_IMPERIAL)) {
centuryStartYear= 0;
}
else {
} else {
// from 80 years ago to 20 years from now
definingCalendar.setTime(new Date());
centuryStartYear= definingCalendar.get(Calendar.YEAR)-80;

View File

@ -196,11 +196,9 @@ abstract class FormatCache<F extends Format> {
DateFormat formatter;
if (dateStyle == null) {
formatter = DateFormat.getTimeInstance(timeStyle.intValue(), locale);
}
else if (timeStyle == null) {
} else if (timeStyle == null) {
formatter = DateFormat.getDateInstance(dateStyle.intValue(), locale);
}
else {
} else {
formatter = DateFormat.getDateTimeInstance(dateStyle.intValue(), timeStyle.intValue(), locale);
}
pattern = ((SimpleDateFormat)formatter).toPattern();

View File

@ -80,24 +80,60 @@ public class StopWatch {
private enum State {
UNSTARTED {
@Override boolean isStarted() { return false; }
@Override boolean isStopped() { return true; }
@Override boolean isSuspended() { return false; }
@Override
boolean isStarted() {
return false;
}
@Override
boolean isStopped() {
return true;
}
@Override
boolean isSuspended() {
return false;
}
},
RUNNING {
@Override boolean isStarted() { return true; }
@Override boolean isStopped() { return false; }
@Override boolean isSuspended() { return false; }
@Override
boolean isStarted() {
return true;
}
@Override
boolean isStopped() {
return false;
}
@Override
boolean isSuspended() {
return false;
}
},
STOPPED {
@Override boolean isStarted() { return false; }
@Override boolean isStopped() { return true; }
@Override boolean isSuspended() { return false; }
@Override
boolean isStarted() {
return false;
}
@Override
boolean isStopped() {
return true;
}
@Override
boolean isSuspended() {
return false;
}
},
SUSPENDED {
@Override boolean isStarted() { return true; }
@Override boolean isStopped() { return false; }
@Override boolean isSuspended() { return true; }
@Override
boolean isStarted() {
return true;
}
@Override
boolean isStopped() {
return false;
}
@Override
boolean isSuspended() {
return true;
}
};
/**

View File

@ -156,8 +156,7 @@ public class ArrayUtilsTest {
* Tests generic array creation with parameters of same type.
*/
@Test
public void testArrayCreation()
{
public void testArrayCreation() {
final String[] array = ArrayUtils.toArray("foo", "bar");
assertEquals(2, array.length);
assertEquals("foo", array[0]);
@ -168,8 +167,7 @@ public class ArrayUtilsTest {
* Tests generic array creation with general return type.
*/
@Test
public void testArrayCreationWithGeneralReturnType()
{
public void testArrayCreationWithGeneralReturnType() {
final Object obj = ArrayUtils.toArray("foo", "bar");
assertTrue(obj instanceof String[]);
}
@ -178,8 +176,7 @@ public class ArrayUtilsTest {
* Tests generic array creation with parameters of common base type.
*/
@Test
public void testArrayCreationWithDifferentTypes()
{
public void testArrayCreationWithDifferentTypes() {
final Number[] array = ArrayUtils.<Number>toArray(Integer.valueOf(42), Double.valueOf(Math.PI));
assertEquals(2, array.length);
assertEquals(Integer.valueOf(42), array[0]);
@ -190,8 +187,7 @@ public class ArrayUtilsTest {
* Tests generic array creation with generic type.
*/
@Test
public void testIndirectArrayCreation()
{
public void testIndirectArrayCreation() {
final String[] array = toArrayPropagatingType("foo", "bar");
assertEquals(2, array.length);
assertEquals("foo", array[0]);
@ -202,8 +198,7 @@ public class ArrayUtilsTest {
* Tests generic empty array creation with generic type.
*/
@Test
public void testEmptyArrayCreation()
{
public void testEmptyArrayCreation() {
final String[] array = ArrayUtils.<String>toArray();
assertEquals(0, array.length);
}
@ -212,15 +207,13 @@ public class ArrayUtilsTest {
* Tests indirect generic empty array creation with generic type.
*/
@Test
public void testIndirectEmptyArrayCreation()
{
public void testIndirectEmptyArrayCreation() {
final String[] array = ArrayUtilsTest.<String>toArrayPropagatingType();
assertEquals(0, array.length);
}
@SafeVarargs
private static <T> T[] toArrayPropagatingType(final T... items)
{
private static <T> T[] toArrayPropagatingType(final T... items) {
return ArrayUtils.toArray(items);
}
@ -236,33 +229,40 @@ public class ArrayUtilsTest {
try {
ArrayUtils.toMap(new String[][]{{"foo", "bar"}, {"short"}});
fail("exception expected");
} catch (final IllegalArgumentException ex) {}
} catch (final IllegalArgumentException ex) {
}
try {
ArrayUtils.toMap(new Object[]{new Object[]{"foo", "bar"}, "illegal type"});
fail("exception expected");
} catch (final IllegalArgumentException ex) {}
} catch (final IllegalArgumentException ex) {
}
try {
ArrayUtils.toMap(new Object[]{new Object[]{"foo", "bar"}, null});
fail("exception expected");
} catch (final IllegalArgumentException ex) {}
} catch (final IllegalArgumentException ex) {
}
map = ArrayUtils.toMap(new Object[]{new Map.Entry<Object, Object>() {
@Override
public Object getKey() {
return "foo";
}
@Override
public Object getValue() {
return "bar";
}
@Override
public Object setValue(final Object value) {
throw new UnsupportedOperationException();
}
@Override
public boolean equals(final Object o) {
throw new UnsupportedOperationException();
}
@Override
public int hashCode() {
throw new UnsupportedOperationException();
@ -364,7 +364,8 @@ public class ArrayUtilsTest {
//-----------------------------------------------------------------------
private class TestClass{}
private class TestClass {
}
@Test
public void testNullToEmptyGenericNull() {
@ -639,8 +640,7 @@ public class ArrayUtilsTest {
@Test
public void testNullToEmptyLongObject() {
@SuppressWarnings("boxing")
final Long[] original = new Long[] {1L, 2L};
@SuppressWarnings("boxing") final Long[] original = new Long[]{1L, 2L};
assertArrayEquals(original, ArrayUtils.nullToEmpty(original));
}
@ -678,8 +678,7 @@ public class ArrayUtilsTest {
@Test
public void testNullToEmptyShortObject() {
@SuppressWarnings("boxing")
final Short[] original = new Short[] {1, 2};
@SuppressWarnings("boxing") final Short[] original = new Short[]{1, 2};
assertArrayEquals(original, ArrayUtils.nullToEmpty(original));
}
@ -802,11 +801,10 @@ public class ArrayUtilsTest {
assertNotSame("java.sql.Date type", java.sql.Date.class,
ArrayUtils.subarray(dateArray, 1, 4).getClass().getComponentType());
try {
@SuppressWarnings("unused")
final
java.sql.Date[] dummy = (java.sql.Date[])ArrayUtils.subarray(dateArray, 1,3);
@SuppressWarnings("unused") final java.sql.Date[] dummy = (java.sql.Date[]) ArrayUtils.subarray(dateArray, 1, 3);
fail("Invalid downcast");
} catch (final ClassCastException e) {}
} catch (final ClassCastException e) {
}
}
@Test
@ -1691,15 +1689,18 @@ public class ArrayUtilsTest {
try {
ArrayUtils.isSameType(null, null);
fail();
} catch (final IllegalArgumentException ex) {}
} catch (final IllegalArgumentException ex) {
}
try {
ArrayUtils.isSameType(null, new Object[0]);
fail();
} catch (final IllegalArgumentException ex) {}
} catch (final IllegalArgumentException ex) {
}
try {
ArrayUtils.isSameType(new Object[0], null);
fail();
} catch (final IllegalArgumentException ex) {}
} catch (final IllegalArgumentException ex) {
}
assertTrue(ArrayUtils.isSameType(new Object[0], new Object[0]));
assertFalse(ArrayUtils.isSameType(new String[0], new Object[0]));
@ -4135,7 +4136,8 @@ public class ArrayUtilsTest {
try {
ArrayUtils.toPrimitive(new Boolean[]{Boolean.TRUE, null});
fail();
} catch (final NullPointerException ex) {}
} catch (final NullPointerException ex) {
}
}
@Test
@ -4185,7 +4187,8 @@ public class ArrayUtilsTest {
try {
ArrayUtils.toPrimitive(new Character[]{new Character(Character.MIN_VALUE), null});
fail();
} catch (final NullPointerException ex) {}
} catch (final NullPointerException ex) {
}
}
@Test
@ -4244,7 +4247,8 @@ public class ArrayUtilsTest {
try {
ArrayUtils.toPrimitive(new Byte[]{Byte.valueOf(Byte.MIN_VALUE), null});
fail();
} catch (final NullPointerException ex) {}
} catch (final NullPointerException ex) {
}
}
@Test
@ -4303,7 +4307,8 @@ public class ArrayUtilsTest {
try {
ArrayUtils.toPrimitive(new Short[]{Short.valueOf(Short.MIN_VALUE), null});
fail();
} catch (final NullPointerException ex) {}
} catch (final NullPointerException ex) {
}
}
@Test
@ -4359,7 +4364,8 @@ public class ArrayUtilsTest {
try {
ArrayUtils.toPrimitive(new Integer[]{Integer.valueOf(Integer.MIN_VALUE), null});
fail();
} catch (final NullPointerException ex) {}
} catch (final NullPointerException ex) {
}
}
@Test
@ -4423,7 +4429,8 @@ public class ArrayUtilsTest {
try {
ArrayUtils.toPrimitive(new Long[]{Long.valueOf(Long.MIN_VALUE), null});
fail();
} catch (final NullPointerException ex) {}
} catch (final NullPointerException ex) {
}
}
@Test
@ -4484,7 +4491,8 @@ public class ArrayUtilsTest {
try {
ArrayUtils.toPrimitive(new Float[]{Float.valueOf(Float.MIN_VALUE), null});
fail();
} catch (final NullPointerException ex) {}
} catch (final NullPointerException ex) {
}
}
@Test
@ -4545,7 +4553,8 @@ public class ArrayUtilsTest {
try {
ArrayUtils.toPrimitive(new Float[]{Float.valueOf(Float.MIN_VALUE), null});
fail();
} catch (final NullPointerException ex) {}
} catch (final NullPointerException ex) {
}
}
@Test
@ -4588,6 +4597,7 @@ public class ArrayUtilsTest {
}
//-----------------------------------------------------------------------
/**
* Test for {@link ArrayUtils#isEmpty(java.lang.Object[])}.
*/
@ -4733,6 +4743,7 @@ public class ArrayUtilsTest {
assertFalse(ArrayUtils.isNotEmpty(emptyBooleanArray));
assertTrue(ArrayUtils.isNotEmpty(notEmptyBooleanArray));
}
// ------------------------------------------------------------------------
@Test
public void testGetLength() {
@ -4789,7 +4800,8 @@ public class ArrayUtilsTest {
try {
ArrayUtils.getLength("notAnArray");
fail("IllegalArgumentException should have been thrown");
} catch (final IllegalArgumentException e) {}
} catch (final IllegalArgumentException e) {
}
}
@Test
@ -4976,7 +4988,8 @@ public class ArrayUtilsTest {
try {
ArrayUtils.toStringArray(new Object[]{null});
fail("NullPointerException expected!");
} catch (final NullPointerException expected) {}
} catch (final NullPointerException expected) {
}
}
@Test

View File

@ -1076,8 +1076,7 @@ public class ClassUtilsTest {
try {
ClassUtils.getClass( className );
fail( "ClassUtils.getClass() should fail with an exception of type " + exceptionType.getName() + " when given class name \"" + className + "\"." );
}
catch( final Exception e ) {
} catch( final Exception e ) {
assertTrue( exceptionType.isAssignableFrom( e.getClass() ) );
}
}

View File

@ -179,8 +179,7 @@ public class SerializationUtilsTest {
};
try {
SerializationUtils.serialize(iMap, streamTest);
}
catch(final SerializationException e) {
} catch(final SerializationException e) {
assertEquals("java.io.IOException: " + SERIALIZE_IO_EXCEPTION_MESSAGE, e.getMessage());
}
}
@ -422,8 +421,7 @@ public class SerializationUtilsTest {
}
class ClassNotFoundSerialization implements Serializable
{
class ClassNotFoundSerialization implements Serializable {
private static final long serialVersionUID = 1L;

View File

@ -800,33 +800,25 @@ public class ValidateTest {
}
@Test
public void testMatchesPattern()
{
public void testMatchesPattern() {
final CharSequence str = "hi";
Validate.matchesPattern(str, "[a-z]*");
try
{
try {
Validate.matchesPattern(str, "[0-9]*");
fail("Expecting IllegalArgumentException");
}
catch (final IllegalArgumentException e)
{
} catch (final IllegalArgumentException e) {
assertEquals("The string hi does not match the pattern [0-9]*", e.getMessage());
}
}
@Test
public void testMatchesPattern_withMessage()
{
public void testMatchesPattern_withMessage() {
final CharSequence str = "hi";
Validate.matchesPattern(str, "[a-z]*", "Does not match");
try
{
try {
Validate.matchesPattern(str, "[0-9]*", "Does not match");
fail("Expecting IllegalArgumentException");
}
catch (final IllegalArgumentException e)
{
} catch (final IllegalArgumentException e) {
assertEquals("Does not match", e.getMessage());
}
}
@ -913,8 +905,7 @@ public class ValidateTest {
//-----------------------------------------------------------------------
@Test
public void testInclusiveBetween()
{
public void testInclusiveBetween() {
Validate.inclusiveBetween("a", "c", "b");
try {
Validate.inclusiveBetween("0", "5", "6");
@ -925,8 +916,7 @@ public class ValidateTest {
}
@Test
public void testInclusiveBetween_withMessage()
{
public void testInclusiveBetween_withMessage() {
Validate.inclusiveBetween("a", "c", "b", "Error");
try {
Validate.inclusiveBetween("0", "5", "6", "Error");
@ -937,8 +927,7 @@ public class ValidateTest {
}
@Test
public void testInclusiveBetweenLong()
{
public void testInclusiveBetweenLong() {
Validate.inclusiveBetween(0, 2, 1);
Validate.inclusiveBetween(0, 2, 2);
try {
@ -950,8 +939,7 @@ public class ValidateTest {
}
@Test
public void testInclusiveBetweenLong_withMessage()
{
public void testInclusiveBetweenLong_withMessage() {
Validate.inclusiveBetween(0, 2, 1, "Error");
Validate.inclusiveBetween(0, 2, 2, "Error");
try {
@ -963,8 +951,7 @@ public class ValidateTest {
}
@Test
public void testInclusiveBetweenDouble()
{
public void testInclusiveBetweenDouble() {
Validate.inclusiveBetween(0.1, 2.1, 1.1);
Validate.inclusiveBetween(0.1, 2.1, 2.1);
try {
@ -976,8 +963,7 @@ public class ValidateTest {
}
@Test
public void testInclusiveBetweenDouble_withMessage()
{
public void testInclusiveBetweenDouble_withMessage() {
Validate.inclusiveBetween(0.1, 2.1, 1.1, "Error");
Validate.inclusiveBetween(0.1, 2.1, 2.1, "Error");
try {
@ -989,8 +975,7 @@ public class ValidateTest {
}
@Test
public void testExclusiveBetween()
{
public void testExclusiveBetween() {
Validate.exclusiveBetween("a", "c", "b");
try {
Validate.exclusiveBetween("0", "5", "6");
@ -1007,8 +992,7 @@ public class ValidateTest {
}
@Test
public void testExclusiveBetween_withMessage()
{
public void testExclusiveBetween_withMessage() {
Validate.exclusiveBetween("a", "c", "b", "Error");
try {
Validate.exclusiveBetween("0", "5", "6", "Error");
@ -1025,8 +1009,7 @@ public class ValidateTest {
}
@Test
public void testExclusiveBetweenLong()
{
public void testExclusiveBetweenLong() {
Validate.exclusiveBetween(0, 2, 1);
try {
Validate.exclusiveBetween(0, 5, 6);
@ -1043,8 +1026,7 @@ public class ValidateTest {
}
@Test
public void testExclusiveBetweenLong_withMessage()
{
public void testExclusiveBetweenLong_withMessage() {
Validate.exclusiveBetween(0, 2, 1, "Error");
try {
Validate.exclusiveBetween(0, 5, 6, "Error");
@ -1061,8 +1043,7 @@ public class ValidateTest {
}
@Test
public void testExclusiveBetweenDouble()
{
public void testExclusiveBetweenDouble() {
Validate.exclusiveBetween(0.1, 2.1, 1.1);
try {
Validate.exclusiveBetween(0.1, 5.1, 6.1);
@ -1079,8 +1060,7 @@ public class ValidateTest {
}
@Test
public void testExclusiveBetweenDouble_withMessage()
{
public void testExclusiveBetweenDouble_withMessage() {
Validate.exclusiveBetween(0.1, 2.1, 1.1, "Error");
try {
Validate.exclusiveBetween(0.1, 5.1, 6.1, "Error");

View File

@ -34,15 +34,22 @@ public class EqualsBuilderTest {
static class TestObject {
private int a;
TestObject() {
}
TestObject(final int a) {
this.a = a;
}
@Override
public boolean equals(final Object o) {
if (o == null) { return false; }
if (o == this) { return true; }
if (o == null) {
return false;
}
if (o == this) {
return true;
}
if (o.getClass() != getClass()) {
return false;
}
@ -67,17 +74,24 @@ public class EqualsBuilderTest {
static class TestSubObject extends TestObject {
private int b;
TestSubObject() {
super(0);
}
TestSubObject(final int a, final int b) {
super(a);
this.b = b;
}
@Override
public boolean equals(final Object o) {
if (o == null) { return false; }
if (o == this) { return true; }
if (o == null) {
return false;
}
if (o == this) {
return true;
}
if (o.getClass() != getClass()) {
return false;
}
@ -109,6 +123,7 @@ public class EqualsBuilderTest {
static class TestTSubObject extends TestObject {
@SuppressWarnings("unused")
private transient int t;
TestTSubObject(final int a, final int t) {
super(a);
this.t = t;
@ -118,6 +133,7 @@ public class EqualsBuilderTest {
static class TestTTSubObject extends TestTSubObject {
@SuppressWarnings("unused")
private transient int tt;
TestTTSubObject(final int a, final int t, final int tt) {
super(a, t);
this.tt = tt;
@ -127,6 +143,7 @@ public class EqualsBuilderTest {
static class TestTTLeafObject extends TestTTSubObject {
@SuppressWarnings("unused")
private final int leafValue;
TestTTLeafObject(final int a, final int t, final int tt, final int leafValue) {
super(a, t, tt);
this.leafValue = leafValue;
@ -135,12 +152,15 @@ public class EqualsBuilderTest {
static class TestTSubObject2 extends TestObject {
private transient int t;
TestTSubObject2(final int a, final int t) {
super(a);
}
public int getT() {
return t;
}
public void setT(final int t) {
this.t = t;
}
@ -173,6 +193,7 @@ public class EqualsBuilderTest {
static class TestRecursiveInnerObject {
private final int n;
TestRecursiveInnerObject(final int n) {
this.n = n;
}
@ -185,6 +206,7 @@ public class EqualsBuilderTest {
static class TestRecursiveCycleObject {
private TestRecursiveCycleObject cycle;
private final int n;
TestRecursiveCycleObject(final int n) {
this.n = n;
this.cycle = this;
@ -301,6 +323,7 @@ public class EqualsBuilderTest {
* <li>consistency</li>
* <li>non-null reference</li>
* </ul>
*
* @param to a TestObject
* @param toBis a TestObject, equal to to and toTer
* @param toTer Left hand side, equal to to and toBis

View File

@ -41,8 +41,7 @@ import org.junit.Test;
/**
* @since 3.0
*/
public class EventUtilsTest
{
public class EventUtilsTest {
@Test
public void testConstructor() {
@ -55,8 +54,7 @@ public class EventUtilsTest
}
@Test
public void testAddEventListener()
{
public void testAddEventListener() {
final PropertyChangeSource src = new PropertyChangeSource();
final EventCountingInvociationHandler handler = new EventCountingInvociationHandler();
final PropertyChangeListener listener = handler.createListener(PropertyChangeListener.class);
@ -68,64 +66,49 @@ public class EventUtilsTest
}
@Test
public void testAddEventListenerWithNoAddMethod()
{
public void testAddEventListenerWithNoAddMethod() {
final PropertyChangeSource src = new PropertyChangeSource();
final EventCountingInvociationHandler handler = new EventCountingInvociationHandler();
final ObjectChangeListener listener = handler.createListener(ObjectChangeListener.class);
try
{
try {
EventUtils.addEventListener(src, ObjectChangeListener.class, listener);
fail("Should not be allowed to add a listener to an object that doesn't support it.");
}
catch (final IllegalArgumentException e)
{
} catch (final IllegalArgumentException e) {
assertEquals("Class " + src.getClass().getName() + " does not have a public add" + ObjectChangeListener.class.getSimpleName() + " method which takes a parameter of type " + ObjectChangeListener.class.getName() + ".", e.getMessage());
}
}
@Test
public void testAddEventListenerThrowsException()
{
public void testAddEventListenerThrowsException() {
final ExceptionEventSource src = new ExceptionEventSource();
try
{
EventUtils.addEventListener(src, PropertyChangeListener.class, new PropertyChangeListener()
{
try {
EventUtils.addEventListener(src, PropertyChangeListener.class, new PropertyChangeListener() {
@Override
public void propertyChange(final PropertyChangeEvent e)
{
public void propertyChange(final PropertyChangeEvent e) {
// Do nothing!
}
});
fail("Add method should have thrown an exception, so method should fail.");
}
catch (final RuntimeException e)
{
} catch (final RuntimeException e) {
}
}
@Test
public void testAddEventListenerWithPrivateAddMethod()
{
public void testAddEventListenerWithPrivateAddMethod() {
final PropertyChangeSource src = new PropertyChangeSource();
final EventCountingInvociationHandler handler = new EventCountingInvociationHandler();
final VetoableChangeListener listener = handler.createListener(VetoableChangeListener.class);
try
{
try {
EventUtils.addEventListener(src, VetoableChangeListener.class, listener);
fail("Should not be allowed to add a listener to an object that doesn't support it.");
}
catch (final IllegalArgumentException e)
{
} catch (final IllegalArgumentException e) {
assertEquals("Class " + src.getClass().getName() + " does not have a public add" + VetoableChangeListener.class.getSimpleName() + " method which takes a parameter of type " + VetoableChangeListener.class.getName() + ".", e.getMessage());
}
}
@Test
public void testBindEventsToMethod()
{
public void testBindEventsToMethod() {
final PropertyChangeSource src = new PropertyChangeSource();
final EventCounter counter = new EventCounter();
EventUtils.bindEventsToMethod(counter, "eventOccurred", src, PropertyChangeListener.class);
@ -136,8 +119,7 @@ public class EventUtilsTest
@Test
public void testBindEventsToMethodWithEvent()
{
public void testBindEventsToMethodWithEvent() {
final PropertyChangeSource src = new PropertyChangeSource();
final EventCounterWithEvent counter = new EventCounterWithEvent();
EventUtils.bindEventsToMethod(counter, "eventOccurred", src, PropertyChangeListener.class);
@ -148,8 +130,7 @@ public class EventUtilsTest
@Test
public void testBindFilteredEventsToMethod()
{
public void testBindFilteredEventsToMethod() {
final MultipleEventSource src = new MultipleEventSource();
final EventCounter counter = new EventCounter();
EventUtils.bindEventsToMethod(counter, "eventOccurred", src, MultipleEventListener.class, "event1");
@ -160,120 +141,97 @@ public class EventUtilsTest
assertEquals(1, counter.getCount());
}
public interface MultipleEventListener
{
public interface MultipleEventListener {
void event1(PropertyChangeEvent e);
void event2(PropertyChangeEvent e);
}
public static class EventCounter
{
public static class EventCounter {
private int count;
public void eventOccurred()
{
public void eventOccurred() {
count++;
}
public int getCount()
{
public int getCount() {
return count;
}
}
public static class EventCounterWithEvent
{
public static class EventCounterWithEvent {
private int count;
public void eventOccurred(final PropertyChangeEvent e)
{
public void eventOccurred(final PropertyChangeEvent e) {
count++;
}
public int getCount()
{
public int getCount() {
return count;
}
}
private static class EventCountingInvociationHandler implements InvocationHandler
{
private static class EventCountingInvociationHandler implements InvocationHandler {
private final Map<String, Integer> eventCounts = new TreeMap<>();
public <L> L createListener(final Class<L> listenerType)
{
public <L> L createListener(final Class<L> listenerType) {
return listenerType.cast(Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
new Class[]{listenerType},
this));
}
public int getEventCount(final String eventName)
{
public int getEventCount(final String eventName) {
final Integer count = eventCounts.get(eventName);
return count == null ? 0 : count.intValue();
}
@Override
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable
{
public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
final Integer count = eventCounts.get(method.getName());
if (count == null)
{
if (count == null) {
eventCounts.put(method.getName(), Integer.valueOf(1));
}
else
{
} else {
eventCounts.put(method.getName(), Integer.valueOf(count.intValue() + 1));
}
return null;
}
}
public static class MultipleEventSource
{
public static class MultipleEventSource {
private final EventListenerSupport<MultipleEventListener> listeners = EventListenerSupport.create(MultipleEventListener.class);
public void addMultipleEventListener(final MultipleEventListener listener)
{
public void addMultipleEventListener(final MultipleEventListener listener) {
listeners.addListener(listener);
}
}
public static class ExceptionEventSource
{
public void addPropertyChangeListener(final PropertyChangeListener listener)
{
public static class ExceptionEventSource {
public void addPropertyChangeListener(final PropertyChangeListener listener) {
throw new RuntimeException();
}
}
public static class PropertyChangeSource
{
public static class PropertyChangeSource {
private final EventListenerSupport<PropertyChangeListener> listeners = EventListenerSupport.create(PropertyChangeListener.class);
private String property;
public void setProperty(final String property)
{
public void setProperty(final String property) {
final String oldValue = this.property;
this.property = property;
listeners.fire().propertyChange(new PropertyChangeEvent(this, "property", oldValue, property));
}
protected void addVetoableChangeListener(final VetoableChangeListener listener)
{
protected void addVetoableChangeListener(final VetoableChangeListener listener) {
// Do nothing!
}
public void addPropertyChangeListener(final PropertyChangeListener listener)
{
public void addPropertyChangeListener(final PropertyChangeListener listener) {
listeners.addListener(listener);
}
public void removePropertyChangeListener(final PropertyChangeListener listener)
{
public void removePropertyChangeListener(final PropertyChangeListener listener) {
listeners.removeListener(listener);
}
}

View File

@ -40,6 +40,7 @@ import org.junit.Test;
/**
* Tests {@link org.apache.commons.lang3.exception.ExceptionUtils}.
*
* @since 1.0
*/
public class ExceptionUtilsTest {
@ -479,6 +480,7 @@ public class ExceptionUtilsTest {
}
//-----------------------------------------------------------------------
/**
* Provides a method with a well known chained/nested exception
* name which matches the full signature (e.g. has a return value
@ -528,8 +530,13 @@ public class ExceptionUtilsTest {
private static final long serialVersionUID = 1L;
@SuppressWarnings("unused")
NestableException() { super(); }
NestableException(final Throwable t) { super(t); }
NestableException() {
super();
}
NestableException(final Throwable t) {
super(t);
}
}
@Test
@ -538,8 +545,7 @@ public class ExceptionUtilsTest {
try {
ExceptionUtils.rethrow(expected);
Assert.fail("Exception not thrown");
}
catch(final Exception actual) {
} catch (final Exception actual) {
Assert.assertSame(expected, actual);
}
}
@ -549,8 +555,7 @@ public class ExceptionUtilsTest {
try {
throwsCheckedException();
Assert.fail("Exception not thrown");
}
catch(final Exception ioe) {
} catch (final Exception ioe) {
assertTrue(ioe instanceof IOException);
assertEquals(1, ExceptionUtils.getThrowableCount(ioe));
}
@ -558,8 +563,7 @@ public class ExceptionUtilsTest {
try {
redeclareCheckedException();
Assert.fail("Exception not thrown");
}
catch(final IOException ioe) {
} catch (final IOException ioe) {
assertEquals(1, ExceptionUtils.getThrowableCount(ioe));
}
}
@ -585,8 +589,7 @@ public class ExceptionUtilsTest {
try {
ExceptionUtils.wrapAndThrow(new OutOfMemoryError());
Assert.fail("Error not thrown");
}
catch(final Throwable t) {
} catch (final Throwable t) {
Assert.assertTrue(ExceptionUtils.hasCause(t, Error.class));
}
}
@ -596,8 +599,7 @@ public class ExceptionUtilsTest {
try {
ExceptionUtils.wrapAndThrow(new IllegalArgumentException());
Assert.fail("RuntimeException not thrown");
}
catch(final Throwable t) {
} catch (final Throwable t) {
Assert.assertTrue(ExceptionUtils.hasCause(t, RuntimeException.class));
}
}
@ -607,8 +609,7 @@ public class ExceptionUtilsTest {
try {
ExceptionUtils.wrapAndThrow(new IOException());
Assert.fail("Checked Exception not thrown");
}
catch(final Throwable t) {
} catch (final Throwable t) {
Assert.assertTrue(ExceptionUtils.hasCause(t, IOException.class));
}
}
@ -618,8 +619,7 @@ public class ExceptionUtilsTest {
try {
ExceptionUtils.wrapAndThrow(new TestThrowable());
Assert.fail("Checked Exception not thrown");
}
catch(final Throwable t) {
} catch (final Throwable t) {
Assert.assertTrue(ExceptionUtils.hasCause(t, TestThrowable.class));
}
}

View File

@ -59,7 +59,8 @@ import org.junit.Test;
*/
public class MethodUtilsTest {
private interface PrivateInterface {}
private interface PrivateInterface {
}
static class TestBeanWithInterfaces implements PrivateInterface {
public String foo() {
@ -197,27 +198,79 @@ public class MethodUtilsTest {
// This method is overloaded for the wrapper class for every primitive type, plus the common supertypes
// Number and Object. This is an acid test since it easily leads to ambiguous methods.
public static String varOverload(final Byte... args) { return "Byte..."; }
public static String varOverload(final Character... args) { return "Character..."; }
public static String varOverload(final Short... args) { return "Short..."; }
public static String varOverload(final Boolean... args) { return "Boolean..."; }
public static String varOverload(final Float... args) { return "Float..."; }
public static String varOverload(final Double... args) { return "Double..."; }
public static String varOverload(final Integer... args) { return "Integer..."; }
public static String varOverload(final Long... args) { return "Long..."; }
public static String varOverload(final Number... args) { return "Number..."; }
public static String varOverload(final Object... args) { return "Object..."; }
public static String varOverload(final String... args) { return "String..."; }
public static String varOverload(final Byte... args) {
return "Byte...";
}
public static String varOverload(final Character... args) {
return "Character...";
}
public static String varOverload(final Short... args) {
return "Short...";
}
public static String varOverload(final Boolean... args) {
return "Boolean...";
}
public static String varOverload(final Float... args) {
return "Float...";
}
public static String varOverload(final Double... args) {
return "Double...";
}
public static String varOverload(final Integer... args) {
return "Integer...";
}
public static String varOverload(final Long... args) {
return "Long...";
}
public static String varOverload(final Number... args) {
return "Number...";
}
public static String varOverload(final Object... args) {
return "Object...";
}
public static String varOverload(final String... args) {
return "String...";
}
// This method is overloaded for the wrapper class for every numeric primitive type, plus the common
// supertype Number
public static String numOverload(final Byte... args) { return "Byte..."; }
public static String numOverload(final Short... args) { return "Short..."; }
public static String numOverload(final Float... args) { return "Float..."; }
public static String numOverload(final Double... args) { return "Double..."; }
public static String numOverload(final Integer... args) { return "Integer..."; }
public static String numOverload(final Long... args) { return "Long..."; }
public static String numOverload(final Number... args) { return "Number..."; }
public static String numOverload(final Byte... args) {
return "Byte...";
}
public static String numOverload(final Short... args) {
return "Short...";
}
public static String numOverload(final Float... args) {
return "Float...";
}
public static String numOverload(final Double... args) {
return "Double...";
}
public static String numOverload(final Integer... args) {
return "Integer...";
}
public static String numOverload(final Long... args) {
return "Long...";
}
public static String numOverload(final Number... args) {
return "Number...";
}
// These varOverloadEcho and varOverloadEchoStatic methods are designed to verify that
// not only is the correct overloaded variant invoked, but that the varags arguments
@ -225,6 +278,7 @@ public class MethodUtilsTest {
public ImmutablePair<String, Object[]> varOverloadEcho(final String... args) {
return new ImmutablePair<String, Object[]>("String...", args);
}
public ImmutablePair<String, Object[]> varOverloadEcho(final Number... args) {
return new ImmutablePair<String, Object[]>("Number...", args);
}
@ -232,6 +286,7 @@ public class MethodUtilsTest {
public static ImmutablePair<String, Object[]> varOverloadEchoStatic(final String... args) {
return new ImmutablePair<String, Object[]>("String...", args);
}
public static ImmutablePair<String, Object[]> varOverloadEchoStatic(final Number... args) {
return new ImmutablePair<String, Object[]>("Number...", args);
}
@ -242,8 +297,7 @@ public class MethodUtilsTest {
}
static void verify(final ImmutablePair<String, Object[]> a, final Object _b) {
@SuppressWarnings("unchecked")
final ImmutablePair<String, Object[]> b = (ImmutablePair<String, Object[]>) _b;
@SuppressWarnings("unchecked") final ImmutablePair<String, Object[]> b = (ImmutablePair<String, Object[]>) _b;
verify(a, b);
}
@ -885,18 +939,36 @@ public class MethodUtilsTest {
}
public static class InheritanceBean {
public void testOne(final Object obj) {}
public void testOne(final GrandParentObject obj) {}
public void testOne(final ParentObject obj) {}
public void testTwo(final Object obj) {}
public void testTwo(final GrandParentObject obj) {}
public void testTwo(final ChildInterface obj) {}
public void testOne(final Object obj) {
}
interface ChildInterface {}
public static class GrandParentObject {}
public static class ParentObject extends GrandParentObject {}
public static class ChildObject extends ParentObject implements ChildInterface {}
public void testOne(final GrandParentObject obj) {
}
public void testOne(final ParentObject obj) {
}
public void testTwo(final Object obj) {
}
public void testTwo(final GrandParentObject obj) {
}
public void testTwo(final ChildInterface obj) {
}
}
interface ChildInterface {
}
public static class GrandParentObject {
}
public static class ParentObject extends GrandParentObject {
}
public static class ChildObject extends ParentObject implements ChildInterface {
}
private static class MethodDescriptor {
final Class<?> declaringClass;

View File

@ -409,7 +409,9 @@ public class ExtendedMessageFormatTest {
return toAppendTo.append(((String)obj).toLowerCase());
}
@Override
public Object parseObject(final String source, final ParsePosition pos) {throw new UnsupportedOperationException();}
public Object parseObject(final String source, final ParsePosition pos) {
throw new UnsupportedOperationException();
}
}
/**
@ -423,7 +425,9 @@ public class ExtendedMessageFormatTest {
return toAppendTo.append(((String)obj).toUpperCase());
}
@Override
public Object parseObject(final String source, final ParsePosition pos) {throw new UnsupportedOperationException();}
public Object parseObject(final String source, final ParsePosition pos) {
throw new UnsupportedOperationException();
}
}

View File

@ -565,29 +565,25 @@ public class StrBuilderTest {
try {
sb.getChars(-1,0,a,0);
fail("no exception");
}
catch (final IndexOutOfBoundsException e) {
} catch (final IndexOutOfBoundsException e) {
}
try {
sb.getChars(0,-1,a,0);
fail("no exception");
}
catch (final IndexOutOfBoundsException e) {
} catch (final IndexOutOfBoundsException e) {
}
try {
sb.getChars(0,20,a,0);
fail("no exception");
}
catch (final IndexOutOfBoundsException e) {
} catch (final IndexOutOfBoundsException e) {
}
try {
sb.getChars(4,2,a,0);
fail("no exception");
}
catch (final IndexOutOfBoundsException e) {
} catch (final IndexOutOfBoundsException e) {
}
}

View File

@ -206,8 +206,7 @@ public class FastDateParserTest {
cal.set(Calendar.ERA, 0);
cal.set(Calendar.YEAR, 1868-year);
}
}
else {
} else {
if (year < 0) {
cal.set(Calendar.ERA, GregorianCalendar.BC);
year= -year;

View File

@ -40,8 +40,7 @@ public class FastDateParser_TimeZoneStrategyTest {
}
try {
parser.parse(tzDisplay);
}
catch(final Exception ex) {
} catch(final Exception ex) {
Assert.fail("'" + tzDisplay + "'"
+ " Locale: '" + locale.getDisplayName() + "'"
+ " TimeZone: " + zone[0]

View File

@ -37,7 +37,10 @@ public class StopWatchTest {
public void testStopWatchSimple() {
final StopWatch watch = new StopWatch();
watch.start();
try {Thread.sleep(550);} catch (final InterruptedException ex) {}
try {
Thread.sleep(550);
} catch (final InterruptedException ex) {
}
watch.stop();
final long time = watch.getTime();
assertEquals(time, watch.getTime());
@ -62,7 +65,10 @@ public class StopWatchTest {
assertEquals("00:00:00.000", watch.toString());
watch.start();
try {Thread.sleep(500);} catch (final InterruptedException ex) {}
try {
Thread.sleep(500);
} catch (final InterruptedException ex) {
}
assertTrue(watch.getTime() < 2000);
}
@ -85,13 +91,22 @@ public class StopWatchTest {
public void testStopWatchSplit() {
final StopWatch watch = new StopWatch();
watch.start();
try {Thread.sleep(550);} catch (final InterruptedException ex) {}
try {
Thread.sleep(550);
} catch (final InterruptedException ex) {
}
watch.split();
final long splitTime = watch.getSplitTime();
final String splitStr = watch.toSplitString();
try {Thread.sleep(550);} catch (final InterruptedException ex) {}
try {
Thread.sleep(550);
} catch (final InterruptedException ex) {
}
watch.unsplit();
try {Thread.sleep(550);} catch (final InterruptedException ex) {}
try {
Thread.sleep(550);
} catch (final InterruptedException ex) {
}
watch.stop();
final long totalTime = watch.getTime();
@ -107,12 +122,21 @@ public class StopWatchTest {
public void testStopWatchSuspend() {
final StopWatch watch = new StopWatch();
watch.start();
try {Thread.sleep(550);} catch (final InterruptedException ex) {}
try {
Thread.sleep(550);
} catch (final InterruptedException ex) {
}
watch.suspend();
final long suspendTime = watch.getTime();
try {Thread.sleep(550);} catch (final InterruptedException ex) {}
try {
Thread.sleep(550);
} catch (final InterruptedException ex) {
}
watch.resume();
try {Thread.sleep(550);} catch (final InterruptedException ex) {}
try {
Thread.sleep(550);
} catch (final InterruptedException ex) {
}
watch.stop();
final long totalTime = watch.getTime();
@ -126,10 +150,16 @@ public class StopWatchTest {
public void testLang315() {
final StopWatch watch = new StopWatch();
watch.start();
try {Thread.sleep(200);} catch (final InterruptedException ex) {}
try {
Thread.sleep(200);
} catch (final InterruptedException ex) {
}
watch.suspend();
final long suspendTime = watch.getTime();
try {Thread.sleep(200);} catch (final InterruptedException ex) {}
try {
Thread.sleep(200);
} catch (final InterruptedException ex) {
}
watch.stop();
final long totalTime = watch.getTime();
assertTrue(suspendTime == totalTime);
@ -275,7 +305,7 @@ public class StopWatchTest {
* Creates a suspended StopWatch object which appears to have elapsed
* for the requested amount of time in nanoseconds.
* <p>
*
* <p>
* <pre>
* // Create a mock StopWatch with a time of 2:59:01.999
* final long nanos = TimeUnit.HOURS.toNanos(2)