Skip to content
Permalink
Browse files
Fixing FindBugs in Test
  • Loading branch information
leerho committed Oct 9, 2019
1 parent 9c15939 commit 54153974c57ba29051de611cf2498917a7ee8a9e
Showing 8 changed files with 48 additions and 42 deletions.
@@ -79,11 +79,11 @@ public void execVariousTypesOfInput() throws Exception {
final Tuple tupleWithNull = TUPLE_FACTORY.newTuple(1);
tupleWithNull.set(0, null);
bag.add(tupleWithNull);
bag.add(TUPLE_FACTORY.newTuple(new Byte((byte) 1)));
bag.add(TUPLE_FACTORY.newTuple(new Integer(2)));
bag.add(TUPLE_FACTORY.newTuple(new Long(3)));
bag.add(TUPLE_FACTORY.newTuple(new Float(1)));
bag.add(TUPLE_FACTORY.newTuple(new Double(2)));
bag.add(TUPLE_FACTORY.newTuple(Byte.valueOf((byte) 1)));
bag.add(TUPLE_FACTORY.newTuple(Integer.valueOf(2)));
bag.add(TUPLE_FACTORY.newTuple(Long.valueOf(3L)));
bag.add(TUPLE_FACTORY.newTuple(Float.valueOf(1.0f)));
bag.add(TUPLE_FACTORY.newTuple(Double.valueOf(2.0)));
bag.add(TUPLE_FACTORY.newTuple(new DataByteArray(new byte[] {(byte) 1})));
bag.add(TUPLE_FACTORY.newTuple("a"));
final CpcSketch sketch = getSketch(func.exec(TUPLE_FACTORY.newTuple(bag)));
@@ -20,6 +20,7 @@
package org.apache.datasketches.pig.hash;

import static org.apache.datasketches.pig.PigTestingUtil.LS;
import static org.junit.Assert.assertNotNull;

import java.io.IOException;

@@ -61,9 +62,10 @@ public void checkExceptions2() throws IOException {
Tuple in, out;
//seed must be INTEGER or LONG
in = mTupleFactory.newTuple(2);
in.set(0, new String("ABC"));
in.set(1, new Double(9001));
in.set(0, "ABC");
in.set(1, Double.valueOf(9001));
out = hashUdf.exec(in);
assertNotNull(out);
}

@Test(expectedExceptions = IllegalArgumentException.class)
@@ -75,6 +77,7 @@ public void checkExceptions3() throws IOException {
in = mTupleFactory.newTuple(1);
in.set(0, in);
out = hashUdf.exec(in);
assertNotNull(out);
}

@Test(expectedExceptions = IllegalArgumentException.class)
@@ -84,10 +87,11 @@ public void checkExceptions4() throws IOException {
Tuple in, out;
//divisor must be INTEGER
in = mTupleFactory.newTuple(3);
in.set(0, new String("ABC"));
in.set(0, "ABC");
in.set(1, 0);
in.set(2, new Long(8));
in.set(2, Long.valueOf(8));
out = hashUdf.exec(in);
assertNotNull(out);
}

@Test(expectedExceptions = IllegalArgumentException.class)
@@ -97,10 +101,11 @@ public void checkExceptions5() throws IOException {
Tuple in, out;
//divisor must be INTEGER > 0
in = mTupleFactory.newTuple(3);
in.set(0, new String("ABC"));
in.set(0, "ABC");
in.set(1, 0);
in.set(2, new Integer(0));
in.set(2, Integer.valueOf(0));
out = hashUdf.exec(in);
assertNotNull(out);
}

@Test
@@ -118,35 +123,35 @@ public void check1ValidArg() throws IOException {
Assert.assertNull(out.get(1));
Assert.assertNull(out.get(2));

in.set(0, new Integer(1));
in.set(0, Integer.valueOf(1));
out = hashUdf.exec(in);
checkOutput(out, false);

in.set(0, new Long(1));
in.set(0, Long.valueOf(1));
out = hashUdf.exec(in);
checkOutput(out, false);

in.set(0, new Float(1));
in.set(0, Float.valueOf(1.0f));
out = hashUdf.exec(in);
checkOutput(out, false);

in.set(0, new Double(0.0));
in.set(0, Double.valueOf(0.0));
out = hashUdf.exec(in);
checkOutput(out, false);

in.set(0, new Double( -0.0));
in.set(0, Double.valueOf( -0.0));
out = hashUdf.exec(in);
checkOutput(out, false);

in.set(0, Double.NaN);
out = hashUdf.exec(in);
checkOutput(out, false);

in.set(0, new String("1"));
in.set(0, "1");
out = hashUdf.exec(in);
checkOutput(out, false);

in.set(0, new String("")); //empty
in.set(0, ""); //empty
out = hashUdf.exec(in);
Assert.assertNull(out.get(0));
Assert.assertNull(out.get(1));
@@ -176,17 +181,17 @@ public void check2ValidArg() throws IOException {
//test String, seed
in = mTupleFactory.newTuple(2);

in.set(0, new String("1"));
in.set(0, "1");
//2nd is null
out = hashUdf.exec(in);
checkOutput(out, false);

in.set(0, new String("1"));
in.set(0, "1");
in.set(1, 9001);
out = hashUdf.exec(in);
checkOutput(out, false);

in.set(0, new String("1"));
in.set(0, "1");
in.set(1, 9001L);
out = hashUdf.exec(in);
checkOutput(out, false);
@@ -201,19 +206,19 @@ public void check3ValidArg() throws IOException {
//test String, seed
in = mTupleFactory.newTuple(3);

in.set(0, new String("1"));
in.set(0, "1");
//2nd is null
//3rd is null
out = hashUdf.exec(in);
checkOutput(out, false);

in.set(0, new String("1"));
in.set(0, "1");
in.set(1, 9001);
//3rd is null
out = hashUdf.exec(in);
checkOutput(out, false);

in.set(0, new String("1"));
in.set(0, "1");
in.set(1, 9001);
in.set(2, 7);
out = hashUdf.exec(in);
@@ -80,11 +80,11 @@ public void execVariousTypesOfInput() throws Exception {
Tuple tupleWithNull = tupleFactory.newTuple(1);
tupleWithNull.set(0, null);
bag.add(tupleWithNull);
bag.add(tupleFactory.newTuple(new Byte((byte) 1)));
bag.add(tupleFactory.newTuple(new Integer(2)));
bag.add(tupleFactory.newTuple(new Long(3)));
bag.add(tupleFactory.newTuple(new Float(1)));
bag.add(tupleFactory.newTuple(new Double(2)));
bag.add(tupleFactory.newTuple(Byte.valueOf((byte) 1)));
bag.add(tupleFactory.newTuple(Integer.valueOf(2)));
bag.add(tupleFactory.newTuple(Long.valueOf(3)));
bag.add(tupleFactory.newTuple(Float.valueOf(1)));
bag.add(tupleFactory.newTuple(Double.valueOf(2)));
bag.add(tupleFactory.newTuple(new DataByteArray(new byte[] {(byte) 1})));
bag.add(tupleFactory.newTuple("a"));
DataByteArray result = func.exec(tupleFactory.newTuple(bag));
@@ -54,9 +54,9 @@ public void normalCase() throws Exception {
final Tuple resultTuple = func.exec(TUPLE_FACTORY.newTuple(Arrays.asList(new DataByteArray(sketch.toByteArray()), 2f, 7f)));
Assert.assertNotNull(resultTuple);
Assert.assertEquals(resultTuple.size(), 3);
Assert.assertEquals(((double) resultTuple.get(0)), 0.1);
Assert.assertEquals(((double) resultTuple.get(1)), 0.6);
Assert.assertEquals(((double) resultTuple.get(2)), 1.0);
Assert.assertEquals((resultTuple.get(0)), 0.1);
Assert.assertEquals((resultTuple.get(1)), 0.6);
Assert.assertEquals((resultTuple.get(2)), 1.0);
}

@Test(expectedExceptions = IllegalArgumentException.class)
@@ -40,12 +40,12 @@
@SuppressWarnings("javadoc")
public class AexcludeBTest {

@SuppressWarnings("unused")
@Test
public void checkConstructors() {
AexcludeB aNOTb = new AexcludeB();
aNOTb = new AexcludeB("9001");
aNOTb = new AexcludeB(9001);
assertNotNull(aNOTb);
}

@Test
@@ -53,22 +53,22 @@ public class DataToSketchTest {
private String udfName = "org.apache.datasketches.pig.theta.DataToSketch";
private long seed_ = Util.DEFAULT_UPDATE_SEED;

@SuppressWarnings("unused")
@Test(expectedExceptions = SketchesArgumentException.class)
public void testConstructorExceptions1() {
DataToSketch test = new DataToSketch("1023");
assertNotNull(test);
}

@SuppressWarnings("unused")
@Test(expectedExceptions = IllegalArgumentException.class)
public void testConstructorExceptions3() {
DataToSketch test = new DataToSketch("8");
assertNotNull(test);
}

@SuppressWarnings("unused")
@Test(expectedExceptions = SketchesArgumentException.class)
public void testConstructorExceptions4() {
DataToSketch test = new DataToSketch("1024", "2.0");
assertNotNull(test);
}

@Test
@@ -481,12 +481,13 @@ public void outputSchemaTest() throws IOException {
}

@Test
@SuppressWarnings("unused")
public void checkMisc() throws IOException {
DataToSketch dts = new DataToSketch("512", "1.0");
dts = new DataToSketch("512", "1.0", "9001");
DataToSketch.Initial dtsi = new DataToSketch.Initial("512", "1.0");
DataToSketch.IntermediateFinal dtsif = new DataToSketch.IntermediateFinal("512", "1.0");
assertNotNull(dtsi);
assertNotNull(dtsif);
Tuple inputTuple = TupleFactory.getInstance().newTuple(1); //null bag
dts.accumulate(inputTuple);
Tuple resultTuple = dts.getValue();
@@ -69,8 +69,6 @@ public void checkNotDBAExcep() throws IOException {
inter.accumulate(inputTuple); //add wrong type
}


@SuppressWarnings("unused")
@Test
public void checkConstructors() {
Intersect inter = new Intersect();
@@ -82,6 +80,8 @@ public void checkConstructors() {
Intersect.IntermediateFinal interFin = new Intersect.IntermediateFinal();
interFin = new Intersect.IntermediateFinal("9001");
interFin = new Intersect.IntermediateFinal(9001);
assertNotNull(initial);
assertNotNull(interFin);
inter.cleanup();
}

@@ -48,22 +48,22 @@ public class UnionTest {
// private String udfName = "org.apache.datasketches.pig.theta.SketchUnions";
// private long seed_ = Util.DEFAULT_UPDATE_SEED;

@SuppressWarnings("unused")
@Test(expectedExceptions = SketchesArgumentException.class)
public void checkConstructorExceptions1() {
Union test = new Union("1023");
assertNotNull(test);
}

@SuppressWarnings("unused")
@Test(expectedExceptions = IllegalArgumentException.class)
public void checkConstructorExceptions3() {
Union test = new Union("8");
assertNotNull(test);
}

@SuppressWarnings("unused")
@Test(expectedExceptions = SketchesArgumentException.class)
public void testConstructorExceptions4() {
Union test = new Union("1024", "2.0");
assertNotNull(test);
}

@Test(expectedExceptions = IllegalArgumentException.class)

0 comments on commit 5415397

Please sign in to comment.