Skip to content

Commit

Permalink
Merge pull request #4231 from hansva/main
Browse files Browse the repository at this point in the history
[SONAR] cleanup deprecated methods
  • Loading branch information
hansva authored Aug 21, 2024
2 parents c91eda4 + d20a119 commit 5e0127e
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 142 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ public void testGuessValueMetaInterface() {
assertEquals(null, ValueMetaFactory.guessValueMetaInterface(null));
assertEquals(null, ValueMetaFactory.guessValueMetaInterface(Short.valueOf((short) 1)));
assertEquals(null, ValueMetaFactory.guessValueMetaInterface(Byte.valueOf((byte) 1)));
assertEquals(null, ValueMetaFactory.guessValueMetaInterface(new Float(1.0)));
assertEquals(null, ValueMetaFactory.guessValueMetaInterface(Float.valueOf(1.0F)));
assertEquals(null, ValueMetaFactory.guessValueMetaInterface(new StringBuilder()));
assertEquals(null, ValueMetaFactory.guessValueMetaInterface((byte) 1));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@

public class ValueDataUtilTest {
@ClassRule public static RestoreHopEngineEnvironment env = new RestoreHopEngineEnvironment();
private static String yyyy_MM_dd = "yyyy-MM-dd";

@BeforeClass
public static void setUpBeforeClass() throws HopException {
Expand Down Expand Up @@ -77,36 +76,13 @@ public void checksumMissingFileTest() throws Exception {
assertNull(checksum);
}

@Test
public void checksumNullPathTest() throws Exception {
String nonExistingFile = "nonExistingFile";
String checksum =
ValueDataUtil.createChecksum(new ValueMetaString(), nonExistingFile, "MD5", false);
assertNull(checksum);
}

@Test
public void checksumWithFailIfNoFileTest() throws Exception {
String path = getClass().getResource("txt-sample.txt").getPath();
String checksum = ValueDataUtil.createChecksum(new ValueMetaString(), path, "MD5", true);
assertEquals("098f6bcd4621d373cade4e832627b4f6", checksum);
}

@Test
public void checksumWithoutFailIfNoFileTest() throws Exception {
String path = getClass().getResource("txt-sample.txt").getPath();
String checksum = ValueDataUtil.createChecksum(new ValueMetaString(), path, "MD5", false);
assertEquals("098f6bcd4621d373cade4e832627b4f6", checksum);
}

@Test
public void checksumNoFailIfNoFileTest() throws HopFileNotFoundException {
String nonExistingFile = "nonExistingFile";
String checksum =
ValueDataUtil.createChecksum(new ValueMetaString(), nonExistingFile, "MD5", false);
assertNull(checksum);
}

@Test(expected = HopFileNotFoundException.class)
public void checksumFailIfNoFileTest() throws HopFileNotFoundException {
String nonExistingPath = "nonExistingPath";
Expand Down Expand Up @@ -137,20 +113,6 @@ public void checksumCRC32MissingFileTest() throws Exception {
assertEquals(0, checksum);
}

@Test
public void checksumCRC32NullPathTest() throws Exception {
String nonExistingFile = "nonExistingFile";
long checksum = ValueDataUtil.checksumCRC32(new ValueMetaString(), nonExistingFile, false);
assertEquals(0, checksum);
}

@Test
public void checksumCRC32WithoutFailIfNoFileTest() throws Exception {
String path = getClass().getResource("txt-sample.txt").getPath();
long checksum = ValueDataUtil.checksumCRC32(new ValueMetaString(), path, false);
assertEquals(3632233996l, checksum);
}

@Test
public void checksumCRC32NoFailIfNoFileTest() throws HopFileNotFoundException {
String nonExistingPath = "nonExistingPath";
Expand Down Expand Up @@ -231,14 +193,6 @@ public void xmlFileBadlyFormedTest() throws HopFileNotFoundException {
assertFalse(wellFormed);
}

@Test
public void xmlFileWellFormedWithFailIfNoFileTest() throws HopFileNotFoundException {
String xmlFilePath = getClass().getResource("xml-sample.xml").getPath();
boolean wellFormed =
ValueDataUtil.isXmlFileWellFormed(new ValueMetaString(), xmlFilePath, true);
assertTrue(wellFormed);
}

@Test
public void xmlFileWellFormedWithoutFailIfNoFileTest() throws HopFileNotFoundException {
String xmlFilePath = getClass().getResource("xml-sample.xml").getPath();
Expand All @@ -247,14 +201,6 @@ public void xmlFileWellFormedWithoutFailIfNoFileTest() throws HopFileNotFoundExc
assertTrue(wellFormed);
}

@Test
public void xmlFileBadlyFormedWithFailIfNoFileTest() throws HopFileNotFoundException {
String invalidXmlFilePath = getClass().getResource("invalid-xml-sample.xml").getPath();
boolean wellFormed =
ValueDataUtil.isXmlFileWellFormed(new ValueMetaString(), invalidXmlFilePath, true);
assertFalse(wellFormed);
}

@Test
public void xmlFileBadlyFormedWithNoFailIfNoFileTest() throws HopFileNotFoundException {
String invalidXmlFilePath = getClass().getResource("invalid-xml-sample.xml").getPath();
Expand Down Expand Up @@ -428,7 +374,7 @@ public void testSumWithNullValues() throws Exception {

assertNull(ValueDataUtil.sum(metaA, null, metaB, null));

Long valueB = new Long(2);
Long valueB = Long.valueOf(2);
ValueDataUtil.sum(metaA, null, metaB, valueB);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public void testGetFieldDefinition() {
false,
false)); // should end up with (100) if "safeMode = true"

MonetDBDatabaseMeta.safeModeLocal.set(new Boolean(true));
MonetDBDatabaseMeta.safeModeLocal.set(Boolean.valueOf(true));
assertEquals(
"VARCHAR(100)",
nativeMeta.getFieldDefinition(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
Expand All @@ -32,7 +33,6 @@
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import junit.framework.Assert;
import org.apache.hop.core.Const;
import org.apache.hop.core.HopEnvironment;
import org.apache.hop.core.IRowSet;
Expand Down Expand Up @@ -64,7 +64,6 @@
* @see Calculator
*/
public class CalculatorUnitTest {
private static final Class<?> PKG = CalculatorUnitTest.class;
private TransformMockHelper<CalculatorMeta, CalculatorData> smh;

@ClassRule public static RestoreHopEngineEnvironment env = new RestoreHopEngineEnvironment();
Expand Down Expand Up @@ -144,11 +143,11 @@ public void testAddSeconds() throws HopException {
new Object[][] {
{
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2014-01-01 00:00:00"),
new Long(10)
Long.valueOf(10)
},
{
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2014-10-31 23:59:50"),
new Long(30)
Long.valueOf(30)
}
});
} catch (ParseException pe) {
Expand Down Expand Up @@ -191,7 +190,7 @@ public void testAddSeconds() throws HopException {
public void rowWrittenEvent(IRowMeta rowMeta, Object[] row)
throws HopTransformException {
try {
assertEquals(
customAssertEquals(
new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2014-01-01 00:00:10"),
row[2]);
} catch (ParseException pe) {
Expand Down Expand Up @@ -251,7 +250,7 @@ public void testReturnDigitsOnly() throws HopException {
@Override
public void rowWrittenEvent(IRowMeta rowMeta, Object[] row)
throws HopTransformException {
assertEquals("123456", row[2]);
customAssertEquals("123456", row[2]);
}
});
calculator.processRow();
Expand Down Expand Up @@ -739,13 +738,10 @@ public void assertRoundGeneral(
@Override
public void rowWrittenEvent(IRowMeta rowMeta, Object[] row)
throws HopTransformException {
assertEquals(msg + " resultRowSize", expectedResultRowSize, rowMeta.size());
customAssertEquals(expectedResultRowSize, rowMeta.size());
final int fieldResultIndex = rowMeta.size() - 1;
assertEquals(
msg + " fieldResult",
fieldResult,
rowMeta.getValueMeta(fieldResultIndex).getName());
assertEquals(msg, expectedResult, row[fieldResultIndex]);
customAssertEquals(fieldResult, rowMeta.getValueMeta(fieldResultIndex).getName());
customAssertEquals(expectedResult, row[fieldResultIndex]);
}
});
calculator.processRow();
Expand Down Expand Up @@ -957,37 +953,33 @@ private String getHopTypeName(int kettleNumberDataType) {
return kettleNumberDataTypeName;
}

public static void assertEquals(Object expected, Object actual) {
assertEquals(null, expected, actual);
}

public static void assertEquals(String msg, Object expected, Object actual) {
public static void customAssertEquals(Object expected, Object actual) {
if (expected instanceof BigDecimal && actual instanceof BigDecimal) {
if (((BigDecimal) expected).compareTo((BigDecimal) actual) != 0) {
Assert.assertEquals(msg, expected, actual);
assertEquals(expected, actual);
}
} else {
Assert.assertEquals(msg, expected, actual);
assertEquals(expected, actual);
}
}

@Test
public void calculatorReminder() throws Exception {
assertCalculatorReminder(
new Double("0.10000000000000053"),
new Object[] {new Long("10"), new Double("3.3")},
Double.valueOf("0.10000000000000053"),
new Object[] {Long.valueOf("10"), Double.valueOf("3.3")},
new int[] {IValueMeta.TYPE_INTEGER, IValueMeta.TYPE_NUMBER});
assertCalculatorReminder(
new Double("1.0"),
new Object[] {new Long("10"), new Double("4.5")},
Double.valueOf("1.0"),
new Object[] {Long.valueOf("10"), Double.valueOf("4.5")},
new int[] {IValueMeta.TYPE_INTEGER, IValueMeta.TYPE_NUMBER});
assertCalculatorReminder(
new Double("4.0"),
new Object[] {new Double("12.5"), new Double("4.25")},
Double.valueOf("4.0"),
new Object[] {Double.valueOf("12.5"), Double.valueOf("4.25")},
new int[] {IValueMeta.TYPE_NUMBER, IValueMeta.TYPE_NUMBER});
assertCalculatorReminder(
new Double("2.6000000000000005"),
new Object[] {new Double("12.5"), new Double("3.3")},
Double.valueOf("2.6000000000000005"),
new Object[] {Double.valueOf("12.5"), Double.valueOf("3.3")},
new int[] {IValueMeta.TYPE_NUMBER, IValueMeta.TYPE_NUMBER});
}

Expand Down Expand Up @@ -1054,7 +1046,7 @@ private void assertCalculatorReminder(
public void rowWrittenEvent(IRowMeta rowMeta, Object[] row)
throws HopTransformException {
try {
assertEquals(expectedResult, row[2]);
customAssertEquals(expectedResult, row[2]);
} catch (Exception pe) {
throw new HopTransformException(pe);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void test() throws Exception {
injector.setProperty(meta, "FIELD_LENGTH", setValue(new ValueMetaString("5"), "5"), "5");
assertEquals(5, meta.getFieldInfo().get(0).length);
injector.setProperty(
meta, "FIELD_LENGTH", setValue(new ValueMetaInteger("4"), new Long(4)), "4");
meta, "FIELD_LENGTH", setValue(new ValueMetaInteger("4"), Long.valueOf(4)), "4");
assertEquals(4, meta.getFieldInfo().get(0).length);

injector.setProperty(meta, "FIELD_PRECISION", setValue(new ValueMetaString(""), ""), "");
Expand All @@ -83,7 +83,7 @@ public void test() throws Exception {
injector.setProperty(meta, "FIELD_PRECISION", setValue(new ValueMetaString("5"), "5"), "5");
assertEquals(5, meta.getFieldInfo().get(0).precision);
injector.setProperty(
meta, "FIELD_PRECISION", setValue(new ValueMetaInteger("4"), new Long(4)), "4");
meta, "FIELD_PRECISION", setValue(new ValueMetaInteger("4"), Long.valueOf(4)), "4");
assertEquals(4, meta.getFieldInfo().get(0).precision);

ArrayList<UserDefinedJavaClassDef> definitions = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ public void setup() throws Exception {

@Test
public void test() throws Exception {
/*
check( "COMPATIBILITY_MODE", new IBooleanGetter() {
public boolean get() {
return meta.isCompatible();
}
} );
*/
check("OPTIMIZATION_LEVEL", () -> meta.getOptimizationLevel());
check("FIELD_NAME", () -> meta.getFieldname()[0]);
check("FIELD_RENAME_TO", () -> meta.getRename()[0]);
Expand Down Expand Up @@ -79,13 +72,13 @@ public boolean get() {
injector.setProperty(meta, "FIELD_LENGTH", setValue(new ValueMetaString("5"), "5"), "5");
assertEquals(5, meta.getLength()[0]);
injector.setProperty(
meta, "FIELD_LENGTH", setValue(new ValueMetaInteger("5"), new Long(5)), "5");
meta, "FIELD_LENGTH", setValue(new ValueMetaInteger("5"), Long.valueOf(5)), "5");
assertEquals(5, meta.getLength()[0]);
injector.setProperty(
meta, "FIELD_LENGTH", setValue(new ValueMetaInteger("5"), (Long) null), "5");
assertEquals(-1, meta.getLength()[0]);
injector.setProperty(
meta, "FIELD_LENGTH", setValue(new ValueMetaNumber("5"), new Double(5)), "5");
meta, "FIELD_LENGTH", setValue(new ValueMetaNumber("5"), Double.valueOf(5)), "5");
assertEquals(5, meta.getLength()[0]);
injector.setProperty(
meta, "FIELD_LENGTH", setValue(new ValueMetaInteger("5"), (Double) null), "5");
Expand All @@ -101,13 +94,13 @@ public boolean get() {
injector.setProperty(meta, "FIELD_PRECISION", setValue(new ValueMetaString("5"), "5"), "5");
assertEquals(5, meta.getPrecision()[0]);
injector.setProperty(
meta, "FIELD_PRECISION", setValue(new ValueMetaInteger("5"), new Long(5)), "5");
meta, "FIELD_PRECISION", setValue(new ValueMetaInteger("5"), Long.valueOf(5)), "5");
assertEquals(5, meta.getPrecision()[0]);
injector.setProperty(
meta, "FIELD_PRECISION", setValue(new ValueMetaInteger("5"), (Long) null), "5");
assertEquals(-1, meta.getPrecision()[0]);
injector.setProperty(
meta, "FIELD_PRECISION", setValue(new ValueMetaNumber("5"), new Double(5)), "5");
meta, "FIELD_PRECISION", setValue(new ValueMetaNumber("5"), Double.valueOf(5)), "5");
assertEquals(5, meta.getPrecision()[0]);
injector.setProperty(
meta, "FIELD_PRECISION", setValue(new ValueMetaInteger("5"), (Double) null), "5");
Expand Down
Loading

0 comments on commit 5e0127e

Please sign in to comment.