Skip to content

Commit

Permalink
Always use static imports for assertion methods to be consistent with…
Browse files Browse the repository at this point in the history
… other tests classes.
  • Loading branch information
PascalSchumacher committed Oct 15, 2017
1 parent 729bcc4 commit 1f0dfc3
Show file tree
Hide file tree
Showing 16 changed files with 338 additions and 329 deletions.
49 changes: 24 additions & 25 deletions src/test/java/org/apache/commons/lang3/ArrayUtilsTest.java
Expand Up @@ -33,7 +33,6 @@
import java.util.Date;
import java.util.Map;

import org.junit.Assert;
import org.junit.Test;

/**
Expand Down Expand Up @@ -4968,12 +4967,12 @@ public void testIsSortedBool() {

@Test
public void testCreatePrimitiveArray() {
Assert.assertNull(ArrayUtils.toPrimitive((Object[]) null));
Assert.assertArrayEquals(new int[]{}, ArrayUtils.toPrimitive(new Integer[]{}));
Assert.assertArrayEquals(new short[]{2}, ArrayUtils.toPrimitive(new Short[]{2}));
Assert.assertArrayEquals(new long[]{2, 3}, ArrayUtils.toPrimitive(new Long[]{2L, 3L}));
Assert.assertArrayEquals(new float[]{3.14f}, ArrayUtils.toPrimitive(new Float[]{3.14f}), 0.1f);
Assert.assertArrayEquals(new double[]{2.718}, ArrayUtils.toPrimitive(new Double[]{2.718}), 0.1);
assertNull(ArrayUtils.toPrimitive((Object[]) null));
assertArrayEquals(new int[]{}, ArrayUtils.toPrimitive(new Integer[]{}));
assertArrayEquals(new short[]{2}, ArrayUtils.toPrimitive(new Short[]{2}));
assertArrayEquals(new long[]{2, 3}, ArrayUtils.toPrimitive(new Long[]{2L, 3L}));
assertArrayEquals(new float[]{3.14f}, ArrayUtils.toPrimitive(new Float[]{3.14f}), 0.1f);
assertArrayEquals(new double[]{2.718}, ArrayUtils.toPrimitive(new Double[]{2.718}), 0.1);
}

@Test
Expand Down Expand Up @@ -5009,9 +5008,9 @@ public void testShuffle() {
String[] array2 = ArrayUtils.clone(array1);

ArrayUtils.shuffle(array1);
Assert.assertFalse(Arrays.equals(array1, array2));
assertFalse(Arrays.equals(array1, array2));
for (String element : array2) {
Assert.assertTrue("Element " + element + " not found", ArrayUtils.contains(array1, element));
assertTrue("Element " + element + " not found", ArrayUtils.contains(array1, element));
}
}

Expand All @@ -5021,8 +5020,8 @@ public void testShuffleBoolean() {
boolean[] array2 = ArrayUtils.clone(array1);

ArrayUtils.shuffle(array1);
Assert.assertFalse(Arrays.equals(array1, array2));
Assert.assertEquals(5, ArrayUtils.removeAllOccurences(array1, true).length);
assertFalse(Arrays.equals(array1, array2));
assertEquals(5, ArrayUtils.removeAllOccurences(array1, true).length);
}

@Test
Expand All @@ -5031,9 +5030,9 @@ public void testShuffleByte() {
byte[] array2 = ArrayUtils.clone(array1);

ArrayUtils.shuffle(array1);
Assert.assertFalse(Arrays.equals(array1, array2));
assertFalse(Arrays.equals(array1, array2));
for (byte element : array2) {
Assert.assertTrue("Element " + element + " not found", ArrayUtils.contains(array1, element));
assertTrue("Element " + element + " not found", ArrayUtils.contains(array1, element));
}
}

Expand All @@ -5043,9 +5042,9 @@ public void testShuffleChar() {
char[] array2 = ArrayUtils.clone(array1);

ArrayUtils.shuffle(array1);
Assert.assertFalse(Arrays.equals(array1, array2));
assertFalse(Arrays.equals(array1, array2));
for (char element : array2) {
Assert.assertTrue("Element " + element + " not found", ArrayUtils.contains(array1, element));
assertTrue("Element " + element + " not found", ArrayUtils.contains(array1, element));
}
}

Expand All @@ -5055,9 +5054,9 @@ public void testShuffleShort() {
short[] array2 = ArrayUtils.clone(array1);

ArrayUtils.shuffle(array1);
Assert.assertFalse(Arrays.equals(array1, array2));
assertFalse(Arrays.equals(array1, array2));
for (short element : array2) {
Assert.assertTrue("Element " + element + " not found", ArrayUtils.contains(array1, element));
assertTrue("Element " + element + " not found", ArrayUtils.contains(array1, element));
}
}

Expand All @@ -5067,9 +5066,9 @@ public void testShuffleInt() {
int[] array2 = ArrayUtils.clone(array1);

ArrayUtils.shuffle(array1);
Assert.assertFalse(Arrays.equals(array1, array2));
assertFalse(Arrays.equals(array1, array2));
for (int element : array2) {
Assert.assertTrue("Element " + element + " not found", ArrayUtils.contains(array1, element));
assertTrue("Element " + element + " not found", ArrayUtils.contains(array1, element));
}
}

Expand All @@ -5079,9 +5078,9 @@ public void testShuffleLong() {
long[] array2 = ArrayUtils.clone(array1);

ArrayUtils.shuffle(array1);
Assert.assertFalse(Arrays.equals(array1, array2));
assertFalse(Arrays.equals(array1, array2));
for (long element : array2) {
Assert.assertTrue("Element " + element + " not found", ArrayUtils.contains(array1, element));
assertTrue("Element " + element + " not found", ArrayUtils.contains(array1, element));
}
}

Expand All @@ -5091,9 +5090,9 @@ public void testShuffleFloat() {
float[] array2 = ArrayUtils.clone(array1);

ArrayUtils.shuffle(array1);
Assert.assertFalse(Arrays.equals(array1, array2));
assertFalse(Arrays.equals(array1, array2));
for (float element : array2) {
Assert.assertTrue("Element " + element + " not found", ArrayUtils.contains(array1, element));
assertTrue("Element " + element + " not found", ArrayUtils.contains(array1, element));
}
}

Expand All @@ -5103,9 +5102,9 @@ public void testShuffleDouble() {
double[] array2 = ArrayUtils.clone(array1);

ArrayUtils.shuffle(array1);
Assert.assertFalse(Arrays.equals(array1, array2));
assertFalse(Arrays.equals(array1, array2));
for (double element : array2) {
Assert.assertTrue("Element " + element + " not found", ArrayUtils.contains(array1, element));
assertTrue("Element " + element + " not found", ArrayUtils.contains(array1, element));
}
}
}
Expand Up @@ -36,7 +36,6 @@
import java.lang.reflect.Modifier;
import java.util.HashMap;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

Expand Down Expand Up @@ -211,7 +210,7 @@ public void testDeserializeStream() throws Exception {
public void testDeserializeClassCastException() {
final String value = "Hello";
final byte[] serialized = SerializationUtils.serialize(value);
Assert.assertEquals(value, SerializationUtils.deserialize(serialized));
assertEquals(value, SerializationUtils.deserialize(serialized));
// Causes ClassCastException in call site, not in SerializationUtils.deserialize
@SuppressWarnings("unused") // needed to cause Exception
final Integer i = SerializationUtils.deserialize(serialized);
Expand Down
19 changes: 9 additions & 10 deletions src/test/java/org/apache/commons/lang3/SystemUtilsTest.java
Expand Up @@ -38,7 +38,6 @@
import java.lang.reflect.Modifier;
import java.util.Locale;

import org.junit.Assert;
import org.junit.Test;

/**
Expand All @@ -62,7 +61,7 @@ public void testConstructor() {
public void testGetHostName() {
final String hostName = SystemUtils.getHostName();
String expected = SystemUtils.IS_OS_WINDOWS ? System.getenv("COMPUTERNAME") : System.getenv("HOSTNAME");
Assert.assertEquals(expected, hostName);
assertEquals(expected, hostName);
}

/**
Expand All @@ -71,8 +70,8 @@ public void testGetHostName() {
@Test
public void testGetJavaHome() {
final File dir = SystemUtils.getJavaHome();
Assert.assertNotNull(dir);
Assert.assertTrue(dir.exists());
assertNotNull(dir);
assertTrue(dir.exists());
}

/**
Expand All @@ -81,8 +80,8 @@ public void testGetJavaHome() {
@Test
public void testGetJavaIoTmpDir() {
final File dir = SystemUtils.getJavaIoTmpDir();
Assert.assertNotNull(dir);
Assert.assertTrue(dir.exists());
assertNotNull(dir);
assertTrue(dir.exists());
}

/**
Expand All @@ -91,8 +90,8 @@ public void testGetJavaIoTmpDir() {
@Test
public void testGetUserDir() {
final File dir = SystemUtils.getUserDir();
Assert.assertNotNull(dir);
Assert.assertTrue(dir.exists());
assertNotNull(dir);
assertTrue(dir.exists());
}

/**
Expand All @@ -101,8 +100,8 @@ public void testGetUserDir() {
@Test
public void testGetUserHome() {
final File dir = SystemUtils.getUserHome();
Assert.assertNotNull(dir);
Assert.assertTrue(dir.exists());
assertNotNull(dir);
assertTrue(dir.exists());
}

@Test
Expand Down
Expand Up @@ -17,6 +17,8 @@

package org.apache.commons.lang3.builder;

import static org.junit.Assert.assertEquals;

import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
Expand Down Expand Up @@ -113,7 +115,7 @@ public Integer call() {
tasks.add(producer);
final List<Future<Integer>> futures = threadPool.invokeAll(tasks);
for (final Future<Integer> future : futures) {
Assert.assertEquals(REPEAT, future.get().intValue());
assertEquals(REPEAT, future.get().intValue());
}
threadPool.shutdown();
threadPool.awaitTermination(1, TimeUnit.SECONDS);
Expand Down
Expand Up @@ -17,12 +17,13 @@

package org.apache.commons.lang3.builder;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.junit.Assert;

import org.apache.commons.lang3.ArrayUtils;
import org.junit.Test;

Expand Down Expand Up @@ -120,17 +121,17 @@ public void test_toStringExcludeNullCollection() {
}

private void validateNonSecretField(final String toString) {
Assert.assertTrue(toString.contains(NOT_SECRET_FIELD));
Assert.assertTrue(toString.contains(NOT_SECRET_VALUE));
assertTrue(toString.contains(NOT_SECRET_FIELD));
assertTrue(toString.contains(NOT_SECRET_VALUE));
}

private void validateSecretFieldAbsent(final String toString) {
Assert.assertEquals(ArrayUtils.INDEX_NOT_FOUND, toString.indexOf(SECRET_VALUE));
assertEquals(ArrayUtils.INDEX_NOT_FOUND, toString.indexOf(SECRET_VALUE));
this.validateNonSecretField(toString);
}

private void validateSecretFieldPresent(final String toString) {
Assert.assertTrue(toString.indexOf(SECRET_VALUE) > 0);
assertTrue(toString.indexOf(SECRET_VALUE) > 0);
this.validateNonSecretField(toString);
}
}
Expand Up @@ -34,7 +34,6 @@

import org.apache.commons.lang3.test.NotVisibleExceptionFactory;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

Expand Down Expand Up @@ -544,25 +543,25 @@ public void testThrow() {
final Exception expected = new InterruptedException();
try {
ExceptionUtils.rethrow(expected);
Assert.fail("Exception not thrown");
fail("Exception not thrown");
} catch (final Exception actual) {
Assert.assertSame(expected, actual);
assertSame(expected, actual);
}
}

@Test
public void testCatchTechniques() {
try {
throwsCheckedException();
Assert.fail("Exception not thrown");
fail("Exception not thrown");
} catch (final Exception ioe) {
assertTrue(ioe instanceof IOException);
assertEquals(1, ExceptionUtils.getThrowableCount(ioe));
}

try {
redeclareCheckedException();
Assert.fail("Exception not thrown");
fail("Exception not thrown");
} catch (final IOException ioe) {
assertEquals(1, ExceptionUtils.getThrowableCount(ioe));
}
Expand All @@ -588,39 +587,39 @@ public static class TestThrowable extends Throwable {
public void testWrapAndUnwrapError() {
try {
ExceptionUtils.wrapAndThrow(new OutOfMemoryError());
Assert.fail("Error not thrown");
fail("Error not thrown");
} catch (final Throwable t) {
Assert.assertTrue(ExceptionUtils.hasCause(t, Error.class));
assertTrue(ExceptionUtils.hasCause(t, Error.class));
}
}

@Test
public void testWrapAndUnwrapRuntimeException() {
try {
ExceptionUtils.wrapAndThrow(new IllegalArgumentException());
Assert.fail("RuntimeException not thrown");
fail("RuntimeException not thrown");
} catch (final Throwable t) {
Assert.assertTrue(ExceptionUtils.hasCause(t, RuntimeException.class));
assertTrue(ExceptionUtils.hasCause(t, RuntimeException.class));
}
}

@Test
public void testWrapAndUnwrapCheckedException() {
try {
ExceptionUtils.wrapAndThrow(new IOException());
Assert.fail("Checked Exception not thrown");
fail("Checked Exception not thrown");
} catch (final Throwable t) {
Assert.assertTrue(ExceptionUtils.hasCause(t, IOException.class));
assertTrue(ExceptionUtils.hasCause(t, IOException.class));
}
}

@Test
public void testWrapAndUnwrapThrowable() {
try {
ExceptionUtils.wrapAndThrow(new TestThrowable());
Assert.fail("Checked Exception not thrown");
fail("Checked Exception not thrown");
} catch (final Throwable t) {
Assert.assertTrue(ExceptionUtils.hasCause(t, TestThrowable.class));
assertTrue(ExceptionUtils.hasCause(t, TestThrowable.class));
}
}
}

0 comments on commit 1f0dfc3

Please sign in to comment.