aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSean Owen <sowen@cloudera.com>2015-11-02 14:36:37 -0600
committerImran Rashid <irashid@irashid-MBP.local>2015-11-02 14:36:37 -0600
commitb3aedca6b55c678e40a5961e2fd3af4cb8c52bba (patch)
treed422a99b009d6ff39f609596dd09971c55688b0f
parentf92f334ca47c03b980b06cf300aa652d0ffa1880 (diff)
downloadspark-b3aedca6b55c678e40a5961e2fd3af4cb8c52bba.tar.gz
spark-b3aedca6b55c678e40a5961e2fd3af4cb8c52bba.tar.bz2
spark-b3aedca6b55c678e40a5961e2fd3af4cb8c52bba.zip
[SPARK-11456][TESTS] Remove deprecated junit.framework in Java tests
Replace use of `junit.framework` with `org.junit`, and touch up tests in question Author: Sean Owen <sowen@cloudera.com> Closes #9411 from srowen/SPARK-11456.
-rw-r--r--unsafe/src/test/java/org/apache/spark/unsafe/bitset/BitSetSuite.java4
-rw-r--r--unsafe/src/test/java/org/apache/spark/unsafe/hash/Murmur3_x86_32Suite.java11
-rw-r--r--unsafe/src/test/java/org/apache/spark/unsafe/types/CalendarIntervalSuite.java78
-rw-r--r--unsafe/src/test/java/org/apache/spark/unsafe/types/UTF8StringSuite.java74
4 files changed, 84 insertions, 83 deletions
diff --git a/unsafe/src/test/java/org/apache/spark/unsafe/bitset/BitSetSuite.java b/unsafe/src/test/java/org/apache/spark/unsafe/bitset/BitSetSuite.java
index a93fc0ee29..14e38683df 100644
--- a/unsafe/src/test/java/org/apache/spark/unsafe/bitset/BitSetSuite.java
+++ b/unsafe/src/test/java/org/apache/spark/unsafe/bitset/BitSetSuite.java
@@ -17,7 +17,7 @@
package org.apache.spark.unsafe.bitset;
-import junit.framework.Assert;
+import org.junit.Assert;
import org.junit.Test;
import org.apache.spark.unsafe.memory.MemoryBlock;
@@ -25,7 +25,7 @@ import org.apache.spark.unsafe.memory.MemoryBlock;
public class BitSetSuite {
private static BitSet createBitSet(int capacity) {
- assert capacity % 64 == 0;
+ Assert.assertEquals(0, capacity % 64);
return new BitSet(MemoryBlock.fromLongArray(new long[capacity / 64]));
}
diff --git a/unsafe/src/test/java/org/apache/spark/unsafe/hash/Murmur3_x86_32Suite.java b/unsafe/src/test/java/org/apache/spark/unsafe/hash/Murmur3_x86_32Suite.java
index 2f8cb132ac..e759cb33b3 100644
--- a/unsafe/src/test/java/org/apache/spark/unsafe/hash/Murmur3_x86_32Suite.java
+++ b/unsafe/src/test/java/org/apache/spark/unsafe/hash/Murmur3_x86_32Suite.java
@@ -17,12 +17,13 @@
package org.apache.spark.unsafe.hash;
+import java.nio.charset.StandardCharsets;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
-import junit.framework.Assert;
import org.apache.spark.unsafe.Platform;
+import org.junit.Assert;
import org.junit.Test;
/**
@@ -56,7 +57,7 @@ public class Murmur3_x86_32Suite {
Random rand = new Random();
// A set used to track collision rate.
- Set<Integer> hashcodes = new HashSet<Integer>();
+ Set<Integer> hashcodes = new HashSet<>();
for (int i = 0; i < size; i++) {
int vint = rand.nextInt();
long lint = rand.nextLong();
@@ -76,7 +77,7 @@ public class Murmur3_x86_32Suite {
Random rand = new Random();
// A set used to track collision rate.
- Set<Integer> hashcodes = new HashSet<Integer>();
+ Set<Integer> hashcodes = new HashSet<>();
for (int i = 0; i < size; i++) {
int byteArrSize = rand.nextInt(100) * 8;
byte[] bytes = new byte[byteArrSize];
@@ -98,10 +99,10 @@ public class Murmur3_x86_32Suite {
public void randomizedStressTestPaddedStrings() {
int size = 64000;
// A set used to track collision rate.
- Set<Integer> hashcodes = new HashSet<Integer>();
+ Set<Integer> hashcodes = new HashSet<>();
for (int i = 0; i < size; i++) {
int byteArrSize = 8;
- byte[] strBytes = ("" + i).getBytes();
+ byte[] strBytes = String.valueOf(i).getBytes(StandardCharsets.UTF_8);
byte[] paddedBytes = new byte[byteArrSize];
System.arraycopy(strBytes, 0, paddedBytes, 0, strBytes.length);
diff --git a/unsafe/src/test/java/org/apache/spark/unsafe/types/CalendarIntervalSuite.java b/unsafe/src/test/java/org/apache/spark/unsafe/types/CalendarIntervalSuite.java
index 80d4982c4b..9e69e264ff 100644
--- a/unsafe/src/test/java/org/apache/spark/unsafe/types/CalendarIntervalSuite.java
+++ b/unsafe/src/test/java/org/apache/spark/unsafe/types/CalendarIntervalSuite.java
@@ -19,7 +19,7 @@ package org.apache.spark.unsafe.types;
import org.junit.Test;
-import static junit.framework.Assert.*;
+import static org.junit.Assert.*;
import static org.apache.spark.unsafe.types.CalendarInterval.*;
public class CalendarIntervalSuite {
@@ -42,19 +42,19 @@ public class CalendarIntervalSuite {
CalendarInterval i;
i = new CalendarInterval(34, 0);
- assertEquals(i.toString(), "interval 2 years 10 months");
+ assertEquals("interval 2 years 10 months", i.toString());
i = new CalendarInterval(-34, 0);
- assertEquals(i.toString(), "interval -2 years -10 months");
+ assertEquals("interval -2 years -10 months", i.toString());
i = new CalendarInterval(0, 3 * MICROS_PER_WEEK + 13 * MICROS_PER_HOUR + 123);
- assertEquals(i.toString(), "interval 3 weeks 13 hours 123 microseconds");
+ assertEquals("interval 3 weeks 13 hours 123 microseconds", i.toString());
i = new CalendarInterval(0, -3 * MICROS_PER_WEEK - 13 * MICROS_PER_HOUR - 123);
- assertEquals(i.toString(), "interval -3 weeks -13 hours -123 microseconds");
+ assertEquals("interval -3 weeks -13 hours -123 microseconds", i.toString());
i = new CalendarInterval(34, 3 * MICROS_PER_WEEK + 13 * MICROS_PER_HOUR + 123);
- assertEquals(i.toString(), "interval 2 years 10 months 3 weeks 13 hours 123 microseconds");
+ assertEquals("interval 2 years 10 months 3 weeks 13 hours 123 microseconds", i.toString());
}
@Test
@@ -73,32 +73,32 @@ public class CalendarIntervalSuite {
input = "interval -5 years 23 month";
CalendarInterval result = new CalendarInterval(-5 * 12 + 23, 0);
- assertEquals(CalendarInterval.fromString(input), result);
+ assertEquals(fromString(input), result);
input = "interval -5 years 23 month ";
- assertEquals(CalendarInterval.fromString(input), result);
+ assertEquals(fromString(input), result);
input = " interval -5 years 23 month ";
- assertEquals(CalendarInterval.fromString(input), result);
+ assertEquals(fromString(input), result);
// Error cases
input = "interval 3month 1 hour";
- assertEquals(CalendarInterval.fromString(input), null);
+ assertNull(fromString(input));
input = "interval 3 moth 1 hour";
- assertEquals(CalendarInterval.fromString(input), null);
+ assertNull(fromString(input));
input = "interval";
- assertEquals(CalendarInterval.fromString(input), null);
+ assertNull(fromString(input));
input = "int";
- assertEquals(CalendarInterval.fromString(input), null);
+ assertNull(fromString(input));
input = "";
- assertEquals(CalendarInterval.fromString(input), null);
+ assertNull(fromString(input));
input = null;
- assertEquals(CalendarInterval.fromString(input), null);
+ assertNull(fromString(input));
}
@Test
@@ -108,15 +108,15 @@ public class CalendarIntervalSuite {
input = "99-10";
i = new CalendarInterval(99 * 12 + 10, 0L);
- assertEquals(CalendarInterval.fromYearMonthString(input), i);
+ assertEquals(fromYearMonthString(input), i);
input = "-8-10";
i = new CalendarInterval(-8 * 12 - 10, 0L);
- assertEquals(CalendarInterval.fromYearMonthString(input), i);
+ assertEquals(fromYearMonthString(input), i);
try {
input = "99-15";
- CalendarInterval.fromYearMonthString(input);
+ fromYearMonthString(input);
fail("Expected to throw an exception for the invalid input");
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().contains("month 15 outside range"));
@@ -131,19 +131,19 @@ public class CalendarIntervalSuite {
input = "5 12:40:30.999999999";
i = new CalendarInterval(0, 5 * MICROS_PER_DAY + 12 * MICROS_PER_HOUR +
40 * MICROS_PER_MINUTE + 30 * MICROS_PER_SECOND + 999999L);
- assertEquals(CalendarInterval.fromDayTimeString(input), i);
+ assertEquals(fromDayTimeString(input), i);
input = "10 0:12:0.888";
i = new CalendarInterval(0, 10 * MICROS_PER_DAY + 12 * MICROS_PER_MINUTE);
- assertEquals(CalendarInterval.fromDayTimeString(input), i);
+ assertEquals(fromDayTimeString(input), i);
input = "-3 0:0:0";
i = new CalendarInterval(0, -3 * MICROS_PER_DAY);
- assertEquals(CalendarInterval.fromDayTimeString(input), i);
+ assertEquals(fromDayTimeString(input), i);
try {
input = "5 30:12:20";
- CalendarInterval.fromDayTimeString(input);
+ fromDayTimeString(input);
fail("Expected to throw an exception for the invalid input");
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().contains("hour 30 outside range"));
@@ -151,7 +151,7 @@ public class CalendarIntervalSuite {
try {
input = "5 30-12";
- CalendarInterval.fromDayTimeString(input);
+ fromDayTimeString(input);
fail("Expected to throw an exception for the invalid input");
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().contains("not match day-time format"));
@@ -165,19 +165,19 @@ public class CalendarIntervalSuite {
input = "12";
i = new CalendarInterval(12 * 12, 0L);
- assertEquals(CalendarInterval.fromSingleUnitString("year", input), i);
+ assertEquals(fromSingleUnitString("year", input), i);
input = "100";
i = new CalendarInterval(0, 100 * MICROS_PER_DAY);
- assertEquals(CalendarInterval.fromSingleUnitString("day", input), i);
+ assertEquals(fromSingleUnitString("day", input), i);
input = "1999.38888";
i = new CalendarInterval(0, 1999 * MICROS_PER_SECOND + 38);
- assertEquals(CalendarInterval.fromSingleUnitString("second", input), i);
+ assertEquals(fromSingleUnitString("second", input), i);
try {
input = String.valueOf(Integer.MAX_VALUE);
- CalendarInterval.fromSingleUnitString("year", input);
+ fromSingleUnitString("year", input);
fail("Expected to throw an exception for the invalid input");
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().contains("outside range"));
@@ -185,7 +185,7 @@ public class CalendarIntervalSuite {
try {
input = String.valueOf(Long.MAX_VALUE / MICROS_PER_HOUR + 1);
- CalendarInterval.fromSingleUnitString("hour", input);
+ fromSingleUnitString("hour", input);
fail("Expected to throw an exception for the invalid input");
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().contains("outside range"));
@@ -197,16 +197,16 @@ public class CalendarIntervalSuite {
String input = "interval 3 month 1 hour";
String input2 = "interval 2 month 100 hour";
- CalendarInterval interval = CalendarInterval.fromString(input);
- CalendarInterval interval2 = CalendarInterval.fromString(input2);
+ CalendarInterval interval = fromString(input);
+ CalendarInterval interval2 = fromString(input2);
assertEquals(interval.add(interval2), new CalendarInterval(5, 101 * MICROS_PER_HOUR));
input = "interval -10 month -81 hour";
input2 = "interval 75 month 200 hour";
- interval = CalendarInterval.fromString(input);
- interval2 = CalendarInterval.fromString(input2);
+ interval = fromString(input);
+ interval2 = fromString(input2);
assertEquals(interval.add(interval2), new CalendarInterval(65, 119 * MICROS_PER_HOUR));
}
@@ -216,25 +216,25 @@ public class CalendarIntervalSuite {
String input = "interval 3 month 1 hour";
String input2 = "interval 2 month 100 hour";
- CalendarInterval interval = CalendarInterval.fromString(input);
- CalendarInterval interval2 = CalendarInterval.fromString(input2);
+ CalendarInterval interval = fromString(input);
+ CalendarInterval interval2 = fromString(input2);
assertEquals(interval.subtract(interval2), new CalendarInterval(1, -99 * MICROS_PER_HOUR));
input = "interval -10 month -81 hour";
input2 = "interval 75 month 200 hour";
- interval = CalendarInterval.fromString(input);
- interval2 = CalendarInterval.fromString(input2);
+ interval = fromString(input);
+ interval2 = fromString(input2);
assertEquals(interval.subtract(interval2), new CalendarInterval(-85, -281 * MICROS_PER_HOUR));
}
- private void testSingleUnit(String unit, int number, int months, long microseconds) {
+ private static void testSingleUnit(String unit, int number, int months, long microseconds) {
String input1 = "interval " + number + " " + unit;
String input2 = "interval " + number + " " + unit + "s";
CalendarInterval result = new CalendarInterval(months, microseconds);
- assertEquals(CalendarInterval.fromString(input1), result);
- assertEquals(CalendarInterval.fromString(input2), result);
+ assertEquals(fromString(input1), result);
+ assertEquals(fromString(input2), result);
}
}
diff --git a/unsafe/src/test/java/org/apache/spark/unsafe/types/UTF8StringSuite.java b/unsafe/src/test/java/org/apache/spark/unsafe/types/UTF8StringSuite.java
index 98aa8a2469..e21ffdcff9 100644
--- a/unsafe/src/test/java/org/apache/spark/unsafe/types/UTF8StringSuite.java
+++ b/unsafe/src/test/java/org/apache/spark/unsafe/types/UTF8StringSuite.java
@@ -24,13 +24,13 @@ import java.util.HashMap;
import com.google.common.collect.ImmutableMap;
import org.junit.Test;
-import static junit.framework.Assert.*;
+import static org.junit.Assert.*;
import static org.apache.spark.unsafe.types.UTF8String.*;
public class UTF8StringSuite {
- private void checkBasic(String str, int len) throws UnsupportedEncodingException {
+ private static void checkBasic(String str, int len) throws UnsupportedEncodingException {
UTF8String s1 = fromString(str);
UTF8String s2 = fromBytes(str.getBytes("utf8"));
assertEquals(s1.numChars(), len);
@@ -42,12 +42,12 @@ public class UTF8StringSuite {
assertEquals(s1.hashCode(), s2.hashCode());
- assertEquals(s1.compareTo(s2), 0);
+ assertEquals(0, s1.compareTo(s2));
- assertEquals(s1.contains(s2), true);
- assertEquals(s2.contains(s1), true);
- assertEquals(s1.startsWith(s1), true);
- assertEquals(s1.endsWith(s1), true);
+ assertTrue(s1.contains(s2));
+ assertTrue(s2.contains(s1));
+ assertTrue(s1.startsWith(s1));
+ assertTrue(s1.endsWith(s1));
}
@Test
@@ -59,8 +59,8 @@ public class UTF8StringSuite {
@Test
public void emptyStringTest() {
- assertEquals(fromString(""), EMPTY_UTF8);
- assertEquals(fromBytes(new byte[0]), EMPTY_UTF8);
+ assertEquals(EMPTY_UTF8, fromString(""));
+ assertEquals(EMPTY_UTF8, fromBytes(new byte[0]));
assertEquals(0, EMPTY_UTF8.numChars());
assertEquals(0, EMPTY_UTF8.numBytes());
}
@@ -76,9 +76,9 @@ public class UTF8StringSuite {
byte[] buf1 = {1, 2, 3, 4, 5, 6, 7, 8, 9};
byte[] buf2 = {1, 2, 3};
- UTF8String str1 = UTF8String.fromBytes(buf1, 0, 3);
- UTF8String str2 = UTF8String.fromBytes(buf1, 0, 8);
- UTF8String str3 = UTF8String.fromBytes(buf2);
+ UTF8String str1 = fromBytes(buf1, 0, 3);
+ UTF8String str2 = fromBytes(buf1, 0, 8);
+ UTF8String str3 = fromBytes(buf2);
assertTrue(str1.getPrefix() - str2.getPrefix() < 0);
assertEquals(str1.getPrefix(), str3.getPrefix());
}
@@ -98,7 +98,7 @@ public class UTF8StringSuite {
assertTrue(fromString("你好123").compareTo(fromString("你好122")) > 0);
}
- protected void testUpperandLower(String upper, String lower) {
+ protected static void testUpperandLower(String upper, String lower) {
UTF8String us = fromString(upper);
UTF8String ls = fromString(lower);
assertEquals(ls, us.toLowerCase());
@@ -127,22 +127,22 @@ public class UTF8StringSuite {
@Test
public void concatTest() {
assertEquals(EMPTY_UTF8, concat());
- assertEquals(null, concat((UTF8String) null));
+ assertNull(concat((UTF8String) null));
assertEquals(EMPTY_UTF8, concat(EMPTY_UTF8));
assertEquals(fromString("ab"), concat(fromString("ab")));
assertEquals(fromString("ab"), concat(fromString("a"), fromString("b")));
assertEquals(fromString("abc"), concat(fromString("a"), fromString("b"), fromString("c")));
- assertEquals(null, concat(fromString("a"), null, fromString("c")));
- assertEquals(null, concat(fromString("a"), null, null));
- assertEquals(null, concat(null, null, null));
+ assertNull(concat(fromString("a"), null, fromString("c")));
+ assertNull(concat(fromString("a"), null, null));
+ assertNull(concat(null, null, null));
assertEquals(fromString("数据砖头"), concat(fromString("数据"), fromString("砖头")));
}
@Test
public void concatWsTest() {
// Returns null if the separator is null
- assertEquals(null, concatWs(null, (UTF8String)null));
- assertEquals(null, concatWs(null, fromString("a")));
+ assertNull(concatWs(null, (UTF8String) null));
+ assertNull(concatWs(null, fromString("a")));
// If separator is null, concatWs should skip all null inputs and never return null.
UTF8String sep = fromString("哈哈");
@@ -381,16 +381,16 @@ public class UTF8StringSuite {
@Test
public void levenshteinDistance() {
- assertEquals(EMPTY_UTF8.levenshteinDistance(EMPTY_UTF8), 0);
- assertEquals(EMPTY_UTF8.levenshteinDistance(fromString("a")), 1);
- assertEquals(fromString("aaapppp").levenshteinDistance(EMPTY_UTF8), 7);
- assertEquals(fromString("frog").levenshteinDistance(fromString("fog")), 1);
- assertEquals(fromString("fly").levenshteinDistance(fromString("ant")),3);
- assertEquals(fromString("elephant").levenshteinDistance(fromString("hippo")), 7);
- assertEquals(fromString("hippo").levenshteinDistance(fromString("elephant")), 7);
- assertEquals(fromString("hippo").levenshteinDistance(fromString("zzzzzzzz")), 8);
- assertEquals(fromString("hello").levenshteinDistance(fromString("hallo")),1);
- assertEquals(fromString("世界千世").levenshteinDistance(fromString("千a世b")),4);
+ assertEquals(0, EMPTY_UTF8.levenshteinDistance(EMPTY_UTF8));
+ assertEquals(1, EMPTY_UTF8.levenshteinDistance(fromString("a")));
+ assertEquals(7, fromString("aaapppp").levenshteinDistance(EMPTY_UTF8));
+ assertEquals(1, fromString("frog").levenshteinDistance(fromString("fog")));
+ assertEquals(3, fromString("fly").levenshteinDistance(fromString("ant")));
+ assertEquals(7, fromString("elephant").levenshteinDistance(fromString("hippo")));
+ assertEquals(7, fromString("hippo").levenshteinDistance(fromString("elephant")));
+ assertEquals(8, fromString("hippo").levenshteinDistance(fromString("zzzzzzzz")));
+ assertEquals(1, fromString("hello").levenshteinDistance(fromString("hallo")));
+ assertEquals(4, fromString("世界千世").levenshteinDistance(fromString("千a世b")));
}
@Test
@@ -432,14 +432,14 @@ public class UTF8StringSuite {
@Test
public void findInSet() {
- assertEquals(fromString("ab").findInSet(fromString("ab")), 1);
- assertEquals(fromString("a,b").findInSet(fromString("b")), 2);
- assertEquals(fromString("abc,b,ab,c,def").findInSet(fromString("ab")), 3);
- assertEquals(fromString("ab,abc,b,ab,c,def").findInSet(fromString("ab")), 1);
- assertEquals(fromString(",,,ab,abc,b,ab,c,def").findInSet(fromString("ab")), 4);
- assertEquals(fromString(",ab,abc,b,ab,c,def").findInSet(fromString("")), 1);
- assertEquals(fromString("数据砖头,abc,b,ab,c,def").findInSet(fromString("ab")), 4);
- assertEquals(fromString("数据砖头,abc,b,ab,c,def").findInSet(fromString("def")), 6);
+ assertEquals(1, fromString("ab").findInSet(fromString("ab")));
+ assertEquals(2, fromString("a,b").findInSet(fromString("b")));
+ assertEquals(3, fromString("abc,b,ab,c,def").findInSet(fromString("ab")));
+ assertEquals(1, fromString("ab,abc,b,ab,c,def").findInSet(fromString("ab")));
+ assertEquals(4, fromString(",,,ab,abc,b,ab,c,def").findInSet(fromString("ab")));
+ assertEquals(1, fromString(",ab,abc,b,ab,c,def").findInSet(fromString("")));
+ assertEquals(4, fromString("数据砖头,abc,b,ab,c,def").findInSet(fromString("ab")));
+ assertEquals(6, fromString("数据砖头,abc,b,ab,c,def").findInSet(fromString("def")));
}
@Test