diff --git a/pom.xml b/pom.xml index 20cf6e11..fec4b4db 100644 --- a/pom.xml +++ b/pom.xml @@ -46,7 +46,7 @@ org.apache.maven.plugins maven-source-plugin - 3.0.1 + 3.2.1 attach-sources @@ -59,7 +59,7 @@ org.apache.maven.plugins maven-javadoc-plugin - 3.0.0 + 3.2.0 attach-javadoc @@ -72,7 +72,7 @@ org.apache.maven.plugins maven-surefire-plugin - 3.0.0-M2 + 3.0.0-M4 false diff --git a/taf-base-junit4-extensions/src/main/java/com/baloise/testautomation/taf/base/testing/e2e/LongRunner.java b/taf-base-junit4-extensions/src/main/java/com/baloise/testautomation/taf/base/testing/e2e/LongRunner.java index e74ab904..992f8f1b 100644 --- a/taf-base-junit4-extensions/src/main/java/com/baloise/testautomation/taf/base/testing/e2e/LongRunner.java +++ b/taf-base-junit4-extensions/src/main/java/com/baloise/testautomation/taf/base/testing/e2e/LongRunner.java @@ -50,11 +50,11 @@ public class LongRunnerClassInfo { public LongRunnerClassInfo() { testClass = null; - methods = new Vector(); + methods = new Vector<>(); } public LongRunnerClassInfo(Class aTestClass) { - this(aTestClass, new Vector()); + this(aTestClass, new Vector<>()); } public LongRunnerClassInfo(Class aTestClass, Collection methods) { @@ -114,7 +114,7 @@ private String getDataFileName(boolean isCompleted) { } private Field[] getFields() { - List dataFields = new ArrayList(); + List dataFields = new ArrayList<>(); Field[] fields = testClass.getFields(); for (Field field : fields) { if (field.isAnnotationPresent(Data.class)) { @@ -160,9 +160,7 @@ public void load() { } public void loadData() { - FileReader fileReader = null; - try { - fileReader = new FileReader(getDataFileName(false)); + try (FileReader fileReader = new FileReader(getDataFileName(false))) { Properties data = getData(); data.load(fileReader); for (Object key : data.keySet()) { @@ -194,36 +192,21 @@ public void loadData() { } } catch (Exception e) { - assertTrue("Some error occurred when trying to set variable " + key + " to " + data.get(key), false); + fail("Some error occurred when trying to set variable " + key + " to " + data.get(key)); } } } catch (IOException e) { fail("store of test data has NOT been correctly done"); } - finally { - try { - fileReader.close(); - } - catch (Exception e) {} - } } public void loadProcess() { - FileReader fileReader = null; - try { - fileReader = new FileReader(getProcessFileName(false)); + try (FileReader fileReader = new FileReader(getProcessFileName(false))) { methods = LongRunnerMethodInfo.loadWith(fileReader); - } - catch (IOException e) { + } catch (IOException e) { fail("load of test state information has NOT been correctly done"); } - finally { - try { - fileReader.close(); - } - catch (Exception e) {} - } } public boolean longRunnerMethodInfoExists(String methodName) { @@ -237,38 +220,20 @@ public void store() { } public void storeData() { - FileWriter fileWriter = null; - try { - fileWriter = new FileWriter(getDataFileName(false)); + try (FileWriter fileWriter = new FileWriter(getDataFileName(false))) { Properties data = getData(); data.store(fileWriter, "Data for long running JUnit test"); - } - catch (IOException e) { + } catch (IOException e) { fail("store of test data has NOT been correctly done"); } - finally { - try { - fileWriter.close(); - } - catch (Exception e) {} - } } public void storeProcess() { - FileWriter fileWriter = null; - try { - fileWriter = new FileWriter(getProcessFileName(false)); + try (FileWriter fileWriter = new FileWriter(getProcessFileName(false))) { LongRunnerMethodInfo.print(fileWriter, methods); - } - catch (IOException e) { + } catch (IOException e) { fail("store of test state information has NOT been correctly done"); } - finally { - try { - fileWriter.close(); - } - catch (Exception e) {} - } } } @@ -288,7 +253,7 @@ public LongRunnerInfo(Class aTestClass, long anId) { public int compareTo(Object o) { if (o instanceof LongRunnerInfo) { LongRunnerInfo lri = (LongRunnerInfo)o; - return new Long(id).compareTo(new Long(lri.id)); + return Long.compare(id, lri.id); } return 0; } @@ -306,7 +271,6 @@ private static String cellContents(CSVRecord header, CSVRecord line, String colu if (colIndex >= 0) { return line.get(colIndex); } - ; return ""; } @@ -324,7 +288,7 @@ private static Object[] getHeaders() { public static Collection loadWith(FileReader fileReader) throws IOException { CSVParser csvParser = new CSVParser(fileReader, getCSVFormat()); - Vector result = new Vector(); + Vector result = new Vector<>(); List records = csvParser.getRecords(); CSVRecord header = null; for (int i = 0; i < records.size(); i++) { @@ -369,11 +333,11 @@ public static void print(FileWriter fileWriter, Collection private TestStatus lastStatus = TestStatus.unknown; - private Date modified = null; + private Date modified; - private Date nextTry = null; + private Date nextTry; - private Date lastTry = null; + private Date lastTry; public LongRunnerMethodInfo(String aMethodName, TestStatus aLastStatus, Date aModified, Date aNextTry, Date aLastTry) { methodName = aMethodName; @@ -470,9 +434,9 @@ private String timeAsString(Date d) { @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface Suspend { - public double firstTryAfterHours() default 0.01; + double firstTryAfterHours() default 0.01; - public double maxHours() default 1.0; + double maxHours() default 1.0; } public enum TestStatus { @@ -484,19 +448,14 @@ public enum TestStatus { private static String path = ""; public static Collection getFor(Class testClass) { - Vector result = new Vector(); + Vector result = new Vector<>(); // TODO korrekte Prüfung assertTrue("Test class must be annotated with a Runner that is a LongRunner or a subclass of it", true); final String testClassName = testClass.getName(); - FilenameFilter fnf = new FilenameFilter() { - @Override - public boolean accept(File dir, String name) { - return name.startsWith(testClassName) && name.endsWith(".csv"); - } - }; + FilenameFilter fnf = (dir, name) -> name.startsWith(testClassName) && name.endsWith(".csv"); File dir; - if (path == null | path.isEmpty()) { + if (path == null || path.isEmpty()) { dir = new File("."); } else { @@ -504,10 +463,11 @@ public boolean accept(File dir, String name) { } final File[] files = dir.listFiles(fnf); - for (File file : files) { - final String id = file.getName().replace(testClassName, "").replace(".csv", "").replace(".", ""); - Long l = Long.parseLong(id); - result.add(new LongRunnerInfo(testClass, l)); + if (files != null) { + for (File file : files) { + final String id = file.getName().replace(testClassName, "").replace(".csv", "").replace(".", ""); + result.add(new LongRunnerInfo(testClass, Long.parseLong(id))); + } } return result; } @@ -562,7 +522,7 @@ protected Statement methodBlock(FrameworkMethod method) { if (lrmi.isPassed()) { return new Statement() { @Override - public void evaluate() throws Throwable { + public void evaluate() { m.getName(); info(m.getName() + " has passed in a previous test"); } @@ -571,7 +531,7 @@ public void evaluate() throws Throwable { if (lrmi.isFailed()) { return new Statement() { @Override - public void evaluate() throws Throwable { + public void evaluate() { Assert.fail(m.getName() + "has failed in a previous test run"); } }; @@ -580,7 +540,7 @@ public void evaluate() throws Throwable { if (lrmi.cantResumeAnymore()) { return new Statement() { @Override - public void evaluate() throws Throwable { + public void evaluate() { Assert.fail(m.getName() + " has timeout and cannot be resumed anymore"); } }; @@ -593,7 +553,7 @@ public void evaluate() throws Throwable { LongRunnerMethodInfo lrmi = aLrmi; @Override - public void evaluate() throws Throwable { + public void evaluate() { try { superStatement.evaluate(); lrmi.setToPassed(); diff --git a/taf-base-junit4-extensions/src/main/java/com/baloise/testautomation/taf/base/testing/e2e/LongRunnerSuite.java b/taf-base-junit4-extensions/src/main/java/com/baloise/testautomation/taf/base/testing/e2e/LongRunnerSuite.java index 87649cf0..015f1fe0 100644 --- a/taf-base-junit4-extensions/src/main/java/com/baloise/testautomation/taf/base/testing/e2e/LongRunnerSuite.java +++ b/taf-base-junit4-extensions/src/main/java/com/baloise/testautomation/taf/base/testing/e2e/LongRunnerSuite.java @@ -1,9 +1,5 @@ package com.baloise.testautomation.taf.base.testing.e2e; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -21,6 +17,8 @@ import com.baloise.testautomation.taf.base.testing.e2e.LongRunner.LongRunnerInfo; +import static org.junit.Assert.*; + public class LongRunnerSuite extends Suite { @Retention(RetentionPolicy.RUNTIME) @@ -28,7 +26,7 @@ public class LongRunnerSuite extends Suite { public @interface LongRunnerInit { } - private static Vector longRunnerInfo = new Vector(); + private static Vector longRunnerInfo = new Vector<>(); private static int currentIndex = 0; public static void addLongRunnerInfosFor(Class... testClasses) { @@ -48,10 +46,10 @@ private static Class[] getLongRunnerClasses(Class testClass) { for (Method method : methods) { if (method.isAnnotationPresent(LongRunnerInit.class)) { try { - method.invoke(testClass, new Object[] {}); + method.invoke(testClass); } catch (Exception e) { - assertNull("Mit 'LongRunnerInit' annotierte Methode konnte nicht ausgeführt werden. Muss 'static' sein.", e); + fail("Mit 'LongRunnerInit' annotierte Methode konnte nicht ausgeführt werden. Muss 'static' sein."); } } } diff --git a/taf-base/src/main/java/com/baloise/testautomation/taf/base/_base/ABase.java b/taf-base/src/main/java/com/baloise/testautomation/taf/base/_base/ABase.java index 998e16de..73f3236b 100644 --- a/taf-base/src/main/java/com/baloise/testautomation/taf/base/_base/ABase.java +++ b/taf-base/src/main/java/com/baloise/testautomation/taf/base/_base/ABase.java @@ -1,21 +1,7 @@ package com.baloise.testautomation.taf.base._base; -import com.baloise.testautomation.taf.base._interfaces.IAnnotations; -import com.baloise.testautomation.taf.base._interfaces.IAnnotations.Check; -import com.baloise.testautomation.taf.base._interfaces.IAnnotations.CheckData; -import com.baloise.testautomation.taf.base._interfaces.IAnnotations.Data; -import com.baloise.testautomation.taf.base._interfaces.IAnnotations.DataProvider; -import com.baloise.testautomation.taf.base._interfaces.IAnnotations.Excel; -import com.baloise.testautomation.taf.base._interfaces.IAnnotations.Fill; -import com.baloise.testautomation.taf.base._interfaces.IAnnotations.PreserveNull; -import com.baloise.testautomation.taf.base._interfaces.ICheck; -import com.baloise.testautomation.taf.base._interfaces.IComponent; -import com.baloise.testautomation.taf.base._interfaces.IData; -import com.baloise.testautomation.taf.base._interfaces.IDataProvider; -import com.baloise.testautomation.taf.base._interfaces.IDataRow; -import com.baloise.testautomation.taf.base._interfaces.IElement; -import com.baloise.testautomation.taf.base._interfaces.IFill; -import com.baloise.testautomation.taf.base._interfaces.IType; +import com.baloise.testautomation.taf.base._interfaces.*; +import com.baloise.testautomation.taf.base._interfaces.IAnnotations.*; import com.baloise.testautomation.taf.base.csv.CsvDataImporter; import com.baloise.testautomation.taf.base.excel.ExcelDataImporter; import com.baloise.testautomation.taf.base.types.TafId; @@ -31,17 +17,9 @@ import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; -import java.util.Vector; - -import static com.baloise.testautomation.taf.base._base.TafAssert.assertFalse; -import static com.baloise.testautomation.taf.base._base.TafAssert.assertNotNull; -import static com.baloise.testautomation.taf.base._base.TafAssert.assertTrue; -import static com.baloise.testautomation.taf.base._base.TafAssert.fail; +import java.util.*; + +import static com.baloise.testautomation.taf.base._base.TafAssert.*; public abstract class ABase implements IComponent { @@ -85,10 +63,7 @@ public void basicCheck() { catch (InvocationTargetException e1) { fail("error in field-check-method (executed by reflection), " + f.getName() + ": " + e1.getCause().getMessage()); } - catch (IllegalArgumentException e) { - e.printStackTrace(); - } - catch (IllegalAccessException e) { + catch (IllegalArgumentException | IllegalAccessException e) { e.printStackTrace(); } } @@ -118,10 +93,7 @@ public void basicFill() { catch (InvocationTargetException e1) { fail("error in field-fill-method (executed by reflection), " + f.getName() + ": " + e1.getCause().getMessage()); } - catch (IllegalArgumentException e) { - e.printStackTrace(); - } - catch (IllegalAccessException e) { + catch (IllegalArgumentException | IllegalAccessException e) { e.printStackTrace(); } } @@ -245,7 +217,7 @@ public Annotation getCheckAnnotation(Field f) { public List getCheckDataFields() { List fields = makeFieldsAccessible(getAllFields()); - List result = new ArrayList(); + List result = new ArrayList<>(); for (Field field : fields) { if (field.isAnnotationPresent(CheckData.class)) { result.add(field); @@ -256,19 +228,13 @@ public List getCheckDataFields() { public List getCheckFields() { List fields = makeFieldsAccessible(getAllFields()); - List result = new ArrayList(); + List result = new ArrayList<>(); for (Field field : fields) { if (field.isAnnotationPresent(Check.class)) { result.add(field); } } - Collections.sort(result, new Comparator() { - @Override - public int compare(Field f1, Field f2) { - return new Integer(f1.getAnnotation(Check.class).value()) - .compareTo(new Integer(f2.getAnnotation(Check.class).value())); - } - }); + result.sort(Comparator.comparingInt(f -> f.getAnnotation(Check.class).value())); return result; } @@ -278,7 +244,7 @@ public Method getCheckMethod(Field f) { public List getDataFields() { List fields = makeFieldsAccessible(getAllFields()); - List result = new ArrayList(); + List result = new ArrayList<>(); for (Field field : fields) { if (field.isAnnotationPresent(Data.class)) { result.add(field); @@ -317,19 +283,13 @@ public TafString getFill() { public List getFillFields() { List fields = makeFieldsAccessible(getAllFields()); - List result = new ArrayList(); + List result = new ArrayList<>(); for (Field field : fields) { if (field.isAnnotationPresent(Fill.class)) { result.add(field); } } - Collections.sort(result, new Comparator() { - @Override - public int compare(Field f1, Field f2) { - return new Integer(f1.getAnnotation(Fill.class).value()) - .compareTo(new Integer(f2.getAnnotation(Fill.class).value())); - } - }); + result.sort(Comparator.comparingInt(f -> f.getAnnotation(Fill.class).value())); return result; } @@ -508,8 +468,7 @@ public Collection loadCsv(Class klass, String pathAndIdAndDetail, S private Collection loadCsvFrom(File f, String idAndDetail) { CsvDataImporter csvImporter = new CsvDataImporter(f); - Collection dataRows = csvImporter.getWith(new TafId(idAndDetail)); - return dataRows; + return csvImporter.getWith(new TafId(idAndDetail)); } public Collection loadExcel(Class klass, String qualifierAndIdAndDetail, String suffix) { @@ -518,15 +477,16 @@ public Collection loadExcel(Class klass, String qualifierAndIdAndDe try (InputStream is = ResourceHelper.getResource(klass, filename).openStream()) { return loadExcelFrom(is, idAndDetail); } - catch (Exception e) {} + catch (Exception e) { + // ignore Exception + } fail("excel file with data NOT found: " + filename + " --> " + idAndDetail); return null; } public Collection loadExcelFrom(InputStream is, String idAndDetail) { ExcelDataImporter edl = new ExcelDataImporter(is, 0); - Collection dataRows = edl.getWith(new TafId(idAndDetail)); - return dataRows; + return edl.getWith(new TafId(idAndDetail)); // Vector tempData = new Vector(); // tempData.addAll(dataRows); // return tempData.get(0); @@ -629,10 +589,7 @@ public void setCheckFields(IDataRow data) { } } } - catch (IllegalArgumentException e) { - e.printStackTrace(); - } - catch (IllegalAccessException e) { + catch (IllegalArgumentException | IllegalAccessException e) { e.printStackTrace(); } } @@ -696,10 +653,7 @@ private void setFields(IDataRow data, List fields) { + getClass()); } } - catch (IllegalArgumentException e) { - e.printStackTrace(); - } - catch (IllegalAccessException e) { + catch (IllegalArgumentException | IllegalAccessException e) { e.printStackTrace(); } } @@ -769,9 +723,11 @@ public void setName(String name) { public void sleep(double seconds) { try { - Thread.sleep(new Double(seconds * 1000).longValue()); + Thread.sleep(Double.valueOf(seconds * 1000).longValue()); + } + catch (Exception e) { + // ignore exception } - catch (Exception e) {} } } diff --git a/taf-base/src/main/java/com/baloise/testautomation/taf/base/types/TafBoolean.java b/taf-base/src/main/java/com/baloise/testautomation/taf/base/types/TafBoolean.java index 608e7033..6578a74c 100644 --- a/taf-base/src/main/java/com/baloise/testautomation/taf/base/types/TafBoolean.java +++ b/taf-base/src/main/java/com/baloise/testautomation/taf/base/types/TafBoolean.java @@ -90,7 +90,7 @@ public TafBoolean(Boolean value) { public BigDecimal asBigDecimal() { Long l = asLong(); if (l != null) { - return BigDecimal.valueOf(l.longValue()); + return BigDecimal.valueOf(l); } else { return null; @@ -117,7 +117,7 @@ public Date asDate() { @Override public Double asDouble() { try { - return new Double(asInteger()); + return Double.parseDouble(String.valueOf(asInteger())); } catch (Exception e) { return null; @@ -129,7 +129,7 @@ public Integer asInteger() { if (isNotBoolean()) { return null; } - if (((Boolean)value).booleanValue()) { + if ((Boolean) value) { return 1; } return 0; @@ -138,7 +138,7 @@ public Integer asInteger() { @Override public Long asLong() { try { - return new Long(asInteger()); + return Long.parseLong(String.valueOf(asInteger())); } catch (Exception e) { return null; @@ -150,7 +150,7 @@ public boolean asPrimitiveBoolean() { if (result == null) { return false; } - return result.booleanValue(); + return result; } @Override @@ -177,7 +177,7 @@ public String asString() { if (isNotBoolean()) { return null; } - if (((Boolean)value).booleanValue()) { + if ((Boolean) value) { return TRUE; } return FALSE; diff --git a/taf-base/src/main/java/com/baloise/testautomation/taf/base/types/TafDouble.java b/taf-base/src/main/java/com/baloise/testautomation/taf/base/types/TafDouble.java index 7ff9bc6d..29662b2b 100644 --- a/taf-base/src/main/java/com/baloise/testautomation/taf/base/types/TafDouble.java +++ b/taf-base/src/main/java/com/baloise/testautomation/taf/base/types/TafDouble.java @@ -43,7 +43,9 @@ public static TafDouble normalDouble(String value) { Double d = Double.parseDouble(value); return normalDouble(d); } - catch (Exception e) {} + catch (Exception e) { + //ignore exception + } return customOrNullDouble(value); } @@ -107,7 +109,7 @@ public TafDouble(String text) { Number n; try { n = format.parse(text); - value = new Double(n.doubleValue()); + value = Double.parseDouble(String.valueOf(n.doubleValue())); } catch (ParseException e) { fail("illegal number format"); @@ -119,7 +121,7 @@ public TafDouble(String text) { public BigDecimal asBigDecimal() { Double d = asDouble(); if (d != null) { - return BigDecimal.valueOf(d.doubleValue()); + return BigDecimal.valueOf(d); } else { return null; @@ -187,8 +189,7 @@ public String asString(String decimalFormat) { } if (value != null) { DecimalFormat resultFormat = new DecimalFormat(decimalFormat); - String formattedString = resultFormat.format(value); - return formattedString; + return resultFormat.format(value); } return null; } diff --git a/taf-base/src/main/java/com/baloise/testautomation/taf/base/types/TafInteger.java b/taf-base/src/main/java/com/baloise/testautomation/taf/base/types/TafInteger.java index 937c25c6..1b0b968a 100644 --- a/taf-base/src/main/java/com/baloise/testautomation/taf/base/types/TafInteger.java +++ b/taf-base/src/main/java/com/baloise/testautomation/taf/base/types/TafInteger.java @@ -45,7 +45,9 @@ public static TafInteger normalInteger(String value) { Integer i = Integer.parseInt(value); return normalInteger(i); } - catch (Exception e) {} + catch (Exception e) { + // ignore Exception + } return customOrNullInteger(value); } @@ -110,7 +112,7 @@ public TafInteger(String text) { Number n; try { n = format.parse(text); - value = new Integer(Math.round(n.floatValue())); + value = Math.round(n.floatValue()); } catch (ParseException e) { fail("illegal number format"); @@ -141,7 +143,8 @@ public Date asDate() { @Override public Double asDouble() { if (!isNull()) { - return new Double((Integer)value); + Integer intValue = (Integer)value; + return Double.parseDouble(String.valueOf(intValue)); } return null; } @@ -160,7 +163,7 @@ public Integer asInteger() { @Override public Long asLong() { try { - return new Long(asInteger()); + return Long.parseLong(String.valueOf(asInteger())); } catch (Exception e) { return null; diff --git a/taf-base/src/test/java/com/baloise/testautomation/taf/base/TestCsvDataLoader.java b/taf-base/src/test/java/com/baloise/testautomation/taf/base/TestCsvDataLoader.java index 2be4ef38..5f778e9e 100644 --- a/taf-base/src/test/java/com/baloise/testautomation/taf/base/TestCsvDataLoader.java +++ b/taf-base/src/test/java/com/baloise/testautomation/taf/base/TestCsvDataLoader.java @@ -47,8 +47,7 @@ public void rowContents1() { CsvDataImporter edl = new CsvDataImporter(file); Collection data = edl.getWith(new TafId("int", "TEst", "1")); assertEquals(1, data.size()); - Vector vData = new Vector<>(); - vData.addAll(data); + Vector vData = new Vector<>(data); assertEquals(TafString.class, vData.get(0).get("INTEGER").getClass()); assertEquals(TafString.class, vData.get(0).get("double").getClass()); assertEquals(TafString.class, vData.get(0).get("date").getClass()); @@ -61,10 +60,9 @@ public void rowContents2() { CsvDataImporter edl = new CsvDataImporter(file); Collection data = edl.getWith(new TafId("int", "TEst", "2")); assertEquals(1, data.size()); - Vector vData = new Vector<>(); - vData.addAll(data); + Vector vData = new Vector<>(data); assertEquals(2, vData.get(0).get("INTEGER").asInteger().intValue()); - assertEquals(new Double(2.2), vData.get(0).get("Double").asDouble()); + assertEquals(Double.valueOf(2.2), vData.get(0).get("Double").asDouble()); SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy"); try { System.out.println(vData.get(0).get("date").asDate()); @@ -83,8 +81,7 @@ public void rowContents3() throws URISyntaxException { new File(getClass().getResource("TestCsvDataLoader.csv").toURI())); Collection data = edl.getWith(new TafId("test", "othertest", "")); assertEquals(1, data.size()); - Vector vData = new Vector<>(); - vData.addAll(data); + Vector vData = new Vector<>(data); assertTrue(vData.get(0).get("INTEGER").isNull()); assertTrue(vData.get(0).get("double").isSkip()); assertTrue(vData.get(0).get("date").isEmpty()); @@ -98,8 +95,7 @@ public void rowContents4() { CsvDataImporter edl = new CsvDataImporter(file); Collection data = edl.getWith(new TafId("test", "string", "")); assertEquals(1, data.size()); - Vector vData = new Vector<>(); - vData.addAll(data); + Vector vData = new Vector<>(data); assertTrue(vData.get(0).get("INTEGER") instanceof TafString); assertTrue(vData.get(0).get("double") instanceof TafString); @@ -110,8 +106,7 @@ public void rowTafId() { CsvDataImporter edl = new CsvDataImporter(file); Collection data = edl.getWith(new TafId("int", "TEst", "")); assertEquals(2, data.size()); - Vector vData = new Vector<>(); - vData.addAll(data); + Vector vData = new Vector<>(data); System.out.println(vData.get(0).getId().asIdDetailString()); assertTrue(vData.get(0).getId().asIdDetailString().equalsIgnoreCase("test-1")); assertTrue(vData.get(1).getId().asIdDetailString().equalsIgnoreCase("test-2")); diff --git a/taf-base/src/test/java/com/baloise/testautomation/taf/base/TestExcelDataLoader.java b/taf-base/src/test/java/com/baloise/testautomation/taf/base/TestExcelDataLoader.java index 2fef37c2..dd172863 100644 --- a/taf-base/src/test/java/com/baloise/testautomation/taf/base/TestExcelDataLoader.java +++ b/taf-base/src/test/java/com/baloise/testautomation/taf/base/TestExcelDataLoader.java @@ -59,8 +59,7 @@ public void rowContents1() throws URISyntaxException { new File(getClass().getResource("TestExcelDataLoader.xls").toURI()), 0); Collection data = edl.getWith(new TafId("int", "TEst", "1")); assertEquals(1, data.size()); - Vector vData = new Vector<>(); - vData.addAll(data); + Vector vData = new Vector<>(data); assertEquals(TafInteger.class, vData.get(0).get("INTEGER").getClass()); assertEquals(TafDouble.class, vData.get(0).get("double").getClass()); assertEquals(TafDate.class, vData.get(0).get("date").getClass()); @@ -74,10 +73,9 @@ public void rowContents2() throws URISyntaxException { new File(getClass().getResource("TestExcelDataLoader.xls").toURI()), 0); Collection data = edl.getWith(new TafId("int", "TEst", "2")); assertEquals(1, data.size()); - Vector vData = new Vector<>(); - vData.addAll(data); + Vector vData = new Vector<>(data); assertEquals(2, vData.get(0).get("INTEGER").asInteger().intValue()); - assertEquals(new Double(2.2), vData.get(0).get("Double").asDouble()); + assertEquals(Double.valueOf(2.2), vData.get(0).get("Double").asDouble()); SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy"); try { assertEquals(sdf.parse("02.02.2000"), vData.get(0).get("date").asDate()); @@ -95,8 +93,7 @@ public void rowContents3() throws URISyntaxException { new File(getClass().getResource("TestExcelDataLoader.xls").toURI()), 0); Collection data = edl.getWith(new TafId("test", "othertest", "")); assertEquals(1, data.size()); - Vector vData = new Vector<>(); - vData.addAll(data); + Vector vData = new Vector<>(data); assertTrue(vData.get(0).get("INTEGER").isNull()); assertTrue(vData.get(0).get("double").isSkip()); assertTrue(vData.get(0).get("date").isEmpty()); @@ -111,8 +108,7 @@ public void rowContents4() throws URISyntaxException { new File(getClass().getResource("TestExcelDataLoader.xls").toURI()), 0); Collection data = edl.getWith(new TafId("test", "string", "")); assertEquals(1, data.size()); - Vector vData = new Vector<>(); - vData.addAll(data); + Vector vData = new Vector<>(data); assertTrue(vData.get(0).get("INTEGER") instanceof TafString); assertTrue(vData.get(0).get("double") instanceof TafString); @@ -124,8 +120,7 @@ public void rowTafId() throws URISyntaxException { new File(getClass().getResource("TestExcelDataLoader.xls").toURI()), 0); Collection data = edl.getWith(new TafId("int", "TEst", "")); assertEquals(2, data.size()); - Vector vData = new Vector<>(); - vData.addAll(data); + Vector vData = new Vector<>(data); assertTrue(vData.get(0).getId().asIdDetailString().equalsIgnoreCase("test-1")); assertTrue(vData.get(1).getId().asIdDetailString().equalsIgnoreCase("test-2")); } diff --git a/taf-base/src/test/java/com/baloise/testautomation/taf/base/TestJsonDataLoader.java b/taf-base/src/test/java/com/baloise/testautomation/taf/base/TestJsonDataLoader.java index 9b5f21ce..41ae4d0c 100644 --- a/taf-base/src/test/java/com/baloise/testautomation/taf/base/TestJsonDataLoader.java +++ b/taf-base/src/test/java/com/baloise/testautomation/taf/base/TestJsonDataLoader.java @@ -51,8 +51,7 @@ public void openWithFile() { public void rowContents1() { Collection data = jsonDataImporter.getWith(new TafId("int", "TEst", "1")); assertEquals(1, data.size()); - Vector vData = new Vector<>(); - vData.addAll(data); + Vector vData = new Vector<>(data); assertEquals(TafString.class, vData.get(0).get("INTEGER").getClass()); assertEquals(TafString.class, vData.get(0).get("double").getClass()); assertEquals(TafString.class, vData.get(0).get("date").getClass()); @@ -64,10 +63,9 @@ public void rowContents1() { public void rowContents2() { Collection data = jsonDataImporter.getWith(new TafId("int", "TEst", "2")); assertEquals(1, data.size()); - Vector vData = new Vector<>(); - vData.addAll(data); + Vector vData = new Vector<>(data); assertEquals(2, vData.get(0).get("INTEGER").asInteger().intValue()); - assertEquals(new Double(2.2), vData.get(0).get("Double").asDouble()); + assertEquals(Double.valueOf(2.2), vData.get(0).get("Double").asDouble()); SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy"); try { System.out.println(vData.get(0).get("date").asDate()); @@ -81,11 +79,10 @@ public void rowContents2() { } @Test - public void rowContents3() throws URISyntaxException { + public void rowContents3() { Collection data = jsonDataImporter.getWith(new TafId("test", "othertest", "")); assertEquals(1, data.size()); - Vector vData = new Vector<>(); - vData.addAll(data); + Vector vData = new Vector<>(data); assertTrue(vData.get(0).get("INTEGER").isNull()); assertTrue(vData.get(0).get("double").isSkip()); assertTrue(vData.get(0).get("date").isEmpty()); @@ -98,8 +95,7 @@ public void rowContents3() throws URISyntaxException { public void rowContents4() { Collection data = jsonDataImporter.getWith(new TafId("test", "string", "")); assertEquals(1, data.size()); - Vector vData = new Vector<>(); - vData.addAll(data); + Vector vData = new Vector<>(data); assertTrue(vData.get(0).get("INTEGER") instanceof TafString); assertTrue(vData.get(0).get("double") instanceof TafString); @@ -109,8 +105,7 @@ public void rowContents4() { public void rowTafId() { Collection data = jsonDataImporter.getWith(new TafId("int", "TEst", "")); assertEquals(2, data.size()); - Vector vData = new Vector<>(); - vData.addAll(data); + Vector vData = new Vector<>(data); System.out.println(vData.get(0).getId().asIdDetailString()); assertTrue(vData.get(0).getId().asIdDetailString().equalsIgnoreCase("test-1")); assertTrue(vData.get(1).getId().asIdDetailString().equalsIgnoreCase("test-2")); diff --git a/taf-base/src/test/java/com/baloise/testautomation/taf/base/TestTafTypes.java b/taf-base/src/test/java/com/baloise/testautomation/taf/base/TestTafTypes.java index 9d02e2ac..2f27c457 100644 --- a/taf-base/src/test/java/com/baloise/testautomation/taf/base/TestTafTypes.java +++ b/taf-base/src/test/java/com/baloise/testautomation/taf/base/TestTafTypes.java @@ -1,9 +1,5 @@ package com.baloise.testautomation.taf.base; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - import java.text.DecimalFormatSymbols; import org.junit.Test; @@ -14,6 +10,8 @@ import com.baloise.testautomation.taf.base.types.TafInteger; import com.baloise.testautomation.taf.base.types.TafString; +import static org.junit.Assert.*; + public class TestTafTypes { @Test @@ -26,15 +24,15 @@ public void tafComboString() { assertTrue(cs.asTafDate().isNull()); cs = TafComboString.normalString("{Skip}"); assertTrue(cs.isSkip()); - assertEquals(null, cs.asString()); + assertNull(cs.asString()); } @Test public void tafInteger() { TafInteger i = TafInteger.normalInteger(111); - assertEquals(new Integer(111), i.asTafInteger().asInteger()); + assertEquals(Integer.valueOf(111), i.asTafInteger().asInteger()); assertEquals("111", i.asTafString().asString()); - assertEquals(new Double(111.0), i.asTafDouble().asDouble()); + assertEquals(Double.valueOf(111.0), i.asTafDouble().asDouble()); assertTrue(i.asTafDate().isNull()); assertTrue(i.asTafBoolean().isNull()); i = TafInteger.skipInteger(); @@ -43,22 +41,24 @@ public void tafInteger() { assertTrue(i.asTafDouble().isSkip()); assertTrue(i.asTafInteger().isSkip()); i = new TafInteger("124"); - assertEquals(i.asInteger(), new Integer(124)); + assertEquals(Integer.valueOf(124), i.asInteger()); i = new TafInteger("124" + DecimalFormatSymbols.getInstance().getDecimalSeparator() + "49"); - assertEquals(new Integer(124), i.asInteger()); + assertEquals(Integer.valueOf(124), i.asInteger()); i = new TafInteger("124" + DecimalFormatSymbols.getInstance().getDecimalSeparator() +"51"); - assertEquals(new Integer(125), i.asInteger()); + assertEquals(Integer.valueOf(125), i.asInteger()); try { - i = new TafInteger("abc"); + new TafInteger("abc"); fail(); } - catch (Throwable e) {} + catch (Throwable e) { + // ignore exception + } i = TafInteger.normalInteger("{custom}{test}"); - assertEquals(null, i.asInteger()); - assertEquals(null, i.asLong()); + assertNull(i.asInteger()); + assertNull(i.asLong()); assertEquals("{custom}{test}", i.asString()); - assertEquals(true, i.isCustom()); - assertEquals(true, i.asTafInteger().isCustom()); + assertTrue(i.isCustom()); + assertTrue(i.asTafInteger().isCustom()); assertEquals("{custom}{test}", i.asTafString().asString()); } @@ -81,7 +81,7 @@ public void tafString() { assertTrue(s.asTafInteger().isSkip()); s = new TafString("{sKip}"); assertTrue(s.isSkip()); - assertEquals(null, s.asString()); + assertNull(s.asString()); s = TafString.normalString("{custom}{test}"); assertEquals("{test}", s.getCustom()); assertEquals("{custom}{test}", s.asString()); @@ -94,10 +94,10 @@ public void tafString() { @Test public void tafDouble() { TafDouble d = TafDouble.normalDouble(2.2); - assertEquals(new Double(2.2), d.asDouble()); - assertEquals(new Integer(2), d.asInteger()); + assertEquals(Double.valueOf(2.2), d.asDouble()); + assertEquals(Integer.valueOf(2), d.asInteger()); d = TafDouble.normalDouble(2.6); - assertEquals(new Integer(2), d.asInteger()); + assertEquals(Integer.valueOf(2), d.asInteger()); d = TafDouble.normalDouble("{custom}{test}"); assertEquals("{custom}{test}", d.asString()); assertEquals("{test}", d.getCustom()); @@ -108,15 +108,15 @@ public void tafDouble() { public void tafBoolean() { TafBoolean b = TafBoolean.normalBoolean("{true}"); assertEquals(true, b.asBoolean()); - assertEquals(true, b.asPrimitiveBoolean()); + assertTrue(b.asPrimitiveBoolean()); b = TafBoolean.normalBoolean("{false}"); assertEquals(false, b.asBoolean()); - assertEquals(false, b.asPrimitiveBoolean()); + assertFalse(b.asPrimitiveBoolean()); b = TafBoolean.normalBoolean("{null}"); - assertEquals(null, b.asBoolean()); + assertNull(b.asBoolean()); b = TafBoolean.normalBoolean("{custom}{test}"); - assertEquals(true, b.isCustom()); - assertEquals(null, b.asBoolean()); + assertTrue(b.isCustom()); + assertNull(b.asBoolean()); assertEquals("{custom}{test}", b.asString()); assertEquals("{test}", b.getCustom()); assertEquals("{test}", b.asTafString().getCustom()); diff --git a/taf-browser/src/main/java/com/baloise/testautomation/taf/browser/elements/ABrInput.java b/taf-browser/src/main/java/com/baloise/testautomation/taf/browser/elements/ABrInput.java index 9e9a8fd2..f9acb4c9 100644 --- a/taf-browser/src/main/java/com/baloise/testautomation/taf/browser/elements/ABrInput.java +++ b/taf-browser/src/main/java/com/baloise/testautomation/taf/browser/elements/ABrInput.java @@ -31,7 +31,7 @@ public void check() { if (!checkValue.isSkip() && checkValue.isNotNull()) { String text = null; try { - int timeout = new Double(((Check)check).timeout() * 1000).intValue(); + int timeout = Double.valueOf(((Check) check).timeout() * 1000).intValue(); if (timeout > 0) { long time = System.currentTimeMillis(); while (System.currentTimeMillis() < time + timeout) { @@ -48,7 +48,9 @@ public void check() { } } } - catch (Exception e) {} + catch (Exception e) { + // ignore exception + } // find for non-timeout-case --> if it's an input --> value is needed if (text == null) { text = getFinder().safeInvoke(() -> find().getAttribute("value")); diff --git a/taf-browser/src/main/java/com/baloise/testautomation/taf/browser/elements/BrFinder.java b/taf-browser/src/main/java/com/baloise/testautomation/taf/browser/elements/BrFinder.java index fc54976d..01538130 100644 --- a/taf-browser/src/main/java/com/baloise/testautomation/taf/browser/elements/BrFinder.java +++ b/taf-browser/src/main/java/com/baloise/testautomation/taf/browser/elements/BrFinder.java @@ -36,9 +36,9 @@ public class BrFinder implements IBrowserFinder { - protected WebDriver driver = null; + protected WebDriver driver; - protected int timeoutInSeconds = 10; + protected int timeoutInSeconds; private Map, WebElementFinder> supportedFinders = new HashMap<>(); @@ -89,12 +89,6 @@ protected void assertDriverAssigned() { assertTrue("WebDriver not initialized", isDriverAssigned()); } -// TODO: this needs to be removed. The user can call isDriverAssigned and act upon it accordingly - public void assumeDriverAssigned() { -// assumeNotNull("WebDriver not initialized", driver); - assertDriverAssigned(); - } - @Override public WebElement find(Annotation annotation) { return find(null, annotation); @@ -265,7 +259,7 @@ public void setDefaultTimeoutInMsecs() { public void setTimeoutInMsecs(Long msecs) { currentTimeout = msecs; if (driver != null) { - driver.manage().timeouts().implicitlyWait(new Double(currentTimeout).intValue(), TimeUnit.MILLISECONDS); + driver.manage().timeouts().implicitlyWait(currentTimeout, TimeUnit.MILLISECONDS); } } diff --git a/taf-swing-client/src/main/java/com/baloise/testautomation/taf/swing/client/proxies/SwApplicationProxy.java b/taf-swing-client/src/main/java/com/baloise/testautomation/taf/swing/client/proxies/SwApplicationProxy.java index e5e62b2e..1ad3b64e 100644 --- a/taf-swing-client/src/main/java/com/baloise/testautomation/taf/swing/client/proxies/SwApplicationProxy.java +++ b/taf-swing-client/src/main/java/com/baloise/testautomation/taf/swing/client/proxies/SwApplicationProxy.java @@ -1,39 +1,24 @@ package com.baloise.testautomation.taf.swing.client.proxies; -import java.lang.annotation.Annotation; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.Hashtable; -import java.util.List; -import java.util.concurrent.Callable; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.baloise.testautomation.taf.base._interfaces.IAnnotations.ByLeftLabel; import com.baloise.testautomation.taf.base._interfaces.IAnnotations.ByText; import com.baloise.testautomation.taf.base._interfaces.IAnnotations.ByXpath; import com.baloise.testautomation.taf.common.interfaces.ISwApplication; import com.baloise.testautomation.taf.common.interfaces.ISwElement; import com.baloise.testautomation.taf.common.utils.TafProperties; -import com.baloise.testautomation.taf.swing.base._interfaces.ISwButton; -import com.baloise.testautomation.taf.swing.base._interfaces.ISwCheckBox; -import com.baloise.testautomation.taf.swing.base._interfaces.ISwComboBox; -import com.baloise.testautomation.taf.swing.base._interfaces.ISwDialog; -import com.baloise.testautomation.taf.swing.base._interfaces.ISwInput; -import com.baloise.testautomation.taf.swing.base._interfaces.ISwInternalFrame; -import com.baloise.testautomation.taf.swing.base._interfaces.ISwLabel; -import com.baloise.testautomation.taf.swing.base._interfaces.ISwList; -import com.baloise.testautomation.taf.swing.base._interfaces.ISwMenuItem; -import com.baloise.testautomation.taf.swing.base._interfaces.ISwRadioButton; -import com.baloise.testautomation.taf.swing.base._interfaces.ISwTabbedPane; -import com.baloise.testautomation.taf.swing.base._interfaces.ISwTable; -import com.baloise.testautomation.taf.swing.base._interfaces.ISwTextArea; -import com.baloise.testautomation.taf.swing.base._interfaces.ISwTree; +import com.baloise.testautomation.taf.swing.base._interfaces.*; import com.baloise.testautomation.taf.swing.base.client.interaction.InteractionController; import com.baloise.testautomation.taf.swing.base.client.interaction.MockInteractionController; import com.baloise.testautomation.taf.swing.base.client.interaction.RealInteractionController; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.lang.annotation.Annotation; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.Hashtable; +import java.util.List; +import java.util.concurrent.Callable; import static com.baloise.testautomation.taf.base._base.TafAssert.assertNotNull; import static com.baloise.testautomation.taf.base._base.TafAssert.fail; @@ -44,7 +29,7 @@ public final class SwApplicationProxy implements ISwApplication private static InteractionController interactionController = RealInteractionController.withoutJournal(); - private Long id = 0l; + private Long id; public int serverTimeoutInMsecs = 50000; @@ -122,7 +107,7 @@ public ISwElement find(ISwElement root, Annotation annotation) { if (root == null) { return basicFind(null, annotation); } - return basicFind((Long)root.getReference(), annotation); + return basicFind(root.getReference(), annotation); } public ISwElement findByLeftLabel(Long root, ByLeftLabel annotation) { @@ -161,7 +146,7 @@ private TafProperties execApplicationCommand(Long root, String xpath, Command co } private TafProperties execApplicationCommand(Long root, String xpath, Command command) { - return execApplicationCommand(root, xpath, command, new Long(serverTimeoutInMsecs)); + return execApplicationCommand(root, xpath, command, (long) serverTimeoutInMsecs); } @Override @@ -178,7 +163,7 @@ public ISwElement findElementByXpath(Long root, String xpath) { @Override public List> findElementsByXpath(Long root, String xpath) { - List> result = new ArrayList>(); + List> result = new ArrayList<>(); TafProperties props = execApplicationCommand(root, xpath, Command.findelementsbyxpath); for (String key : props.keySet()) { ISwElement element = getElement(props, key); @@ -188,15 +173,7 @@ public List> findElementsByXpath(Long root, String xpath) { } // Order elements according to their TID, to fit ordering in swing hierarchy - Comparator> comparator = new Comparator>() { - - @Override - public int compare(ISwElement element1, ISwElement element2) { - return (element1.getReference().intValue() - element2.getReference().intValue()); - } - - }; - Collections.sort(result, comparator); + result.sort(Comparator.comparingInt(element -> element.getReference().intValue())); return result; } @@ -205,10 +182,12 @@ private ISwElement getElement(TafProperties props, String key) { ISwElement element = createElement(props.getString(key)); if (element != null) { try { - element.setReference(new Long(Long.parseLong(key))); + element.setReference(Long.parseLong(key)); return element; } - catch (Exception e) {} + catch (Exception e) { + // ignore exception + } } return null; } @@ -400,7 +379,7 @@ public void setTimeoutInMsecs(Long msecs) { @Override public Long getTimeoutInMsecs() { - return new Long(serverTimeoutInMsecs); + return (long) serverTimeoutInMsecs; } @Override diff --git a/taf-swing-server/src/main/java/com/baloise/testautomation/taf/swing/server/main/SwApplication.java b/taf-swing-server/src/main/java/com/baloise/testautomation/taf/swing/server/main/SwApplication.java index 322b997d..9399799d 100644 --- a/taf-swing-server/src/main/java/com/baloise/testautomation/taf/swing/server/main/SwApplication.java +++ b/taf-swing-server/src/main/java/com/baloise/testautomation/taf/swing/server/main/SwApplication.java @@ -2,11 +2,7 @@ import static com.baloise.testautomation.taf.swing.server.utils.Encoder.asEscapedXmlString; -import java.awt.Component; -import java.awt.Container; -import java.awt.Dialog; -import java.awt.Frame; -import java.awt.KeyboardFocusManager; +import java.awt.*; import java.io.BufferedWriter; import java.io.ByteArrayOutputStream; import java.io.FileOutputStream; @@ -14,6 +10,7 @@ import java.io.StringReader; import java.io.Writer; import java.lang.annotation.Annotation; +import java.nio.charset.StandardCharsets; import java.util.Hashtable; import java.util.List; import java.util.Vector; @@ -94,8 +91,13 @@ public static boolean waitForWindowWithTitle(String windowTitle) { public void allCellsToXML(StringBuilder xml, JTable table) { info("Adding cells for: " + table); for (int c = 0; c < table.getColumnCount(); c++) { - xml.append("
"); + xml.append("
"); components.put(counter, new SwTableColumn(counter, c, table)); counter++; } @@ -108,8 +110,15 @@ public void allCellsToXML(StringBuilder xml, JTable table) { catch (Exception e) { info("cellText is null: row = " + r + ", column = " + c); } - xml.append(""); + xml.append(""); components.put(counter, new SwCell(counter, r, c, table)); counter++; } @@ -118,7 +127,7 @@ public void allCellsToXML(StringBuilder xml, JTable table) { public String allComponentsToXML(Component c) { xml = new StringBuilder(); - components = new Hashtable>(); + components = new Hashtable<>(); counter = 0; allComponentsToXML(xml, c); return xml.toString(); @@ -182,9 +191,6 @@ public void allComponentsToXML(StringBuilder xml, Component c) { } } } - else { - // System.out.println(c.toString()); - } // level--; xml.append(""; - s = s + System.getProperty("line.separator"); - s = s + "" + asEscapedXml(text) + ""; + s += System.getProperty("line.separator"); + s += "" + asEscapedXml(text) + ""; } catch (Exception e) { s = "" + e.getMessage() + ""; @@ -214,11 +220,12 @@ public void allTabsToXML(StringBuilder xml, JTabbedPane tabbedPane) { if (title.isEmpty()) { title = "untitled-" + i; } - xml.append(""); - xml.append(System.getProperty("line.separator")); + xml.append("") + .append(System.getProperty("line.separator")); allComponentsToXML(xml, tabbedPane.getComponentAt(i)); - xml.append(""); - xml.append(System.getProperty("line.separator")); + xml.append("") + .append(System.getProperty("line.separator")); } } @@ -236,35 +243,43 @@ private TafProperties execApplicationCommand(TafProperties props) { if (Command.findelementbyxpath.toString().equalsIgnoreCase(command)) { try { ASwElement element = (ASwElement)findElementByXpath(props.getLong(paramRoot), props.getString(paramXPath)); - result.putObject(new Long(element.getTID()).toString(), element.getType()); + result.putObject(Long.toString(element.getTID()), element.getType()); return result; } - catch (Exception e) {} + catch (Exception e) { + // ignore exception + } } if (Command.findelementsbyxpath.toString().equalsIgnoreCase(command)) { try { List> elements = findElementsByXpath(props.getLong(paramRoot), props.getString(paramXPath)); for (ISwElement element : elements) { - result.putObject(new Long(((ASwElement)element).getTID()).toString(), element.getType()); + result.putObject(Long.toString(((ASwElement) element).getTID()), element.getType()); } return result; } - catch (Exception e) {} + catch (Exception e) { + // ignore exception + } } if (Command.sendkeys.toString().equalsIgnoreCase(command)) { try { sendKeys(props.getString(paramKeys)); return result; } - catch (Exception e) {} + catch (Exception e) { + // ignore exception + } } if (Command.storehierarchy.toString().equalsIgnoreCase(command)) { try { storeHierarchy(props.getString(paramPath)); return result; } - catch (Exception e) {} + catch (Exception e) { + // ignore exception + } } Command c = getCommand(Command.class, command); switch (c) { @@ -302,7 +317,9 @@ private > T getCommand(Class c, String command) { try { return Enum.valueOf(c, command.trim().toLowerCase()); } - catch (IllegalArgumentException e) {} + catch (IllegalArgumentException e) { + // ignore exception + } } return null; } @@ -377,9 +394,8 @@ private NodeList findAllByXpath(Long root, String s) { return null; } // System.out.println("XML: " + xml); - NodeList result = (NodeList)expression.evaluate(new org.xml.sax.InputSource(new StringReader(xml)), + return (NodeList)expression.evaluate(new InputSource(new StringReader(xml)), XPathConstants.NODESET); - return result; } catch (XPathExpressionException e) { e.printStackTrace(); @@ -406,7 +422,7 @@ public List> findElementsByXpath(Long root, String s) { setRoot(); NodeList nl = findAllByXpath(root, s); if (nl.getLength() > 0) { - Vector> result = new Vector>(); + Vector> result = new Vector<>(); for (int i = 0; i < nl.getLength(); i++) { try { String l = nl.item(i).getAttributes().getNamedItem("tid").getNodeValue(); @@ -415,7 +431,9 @@ public List> findElementsByXpath(Long root, String s) { System.out.println(nl.item(i)); result.add(components.get(Long.parseLong(l))); } - catch (Exception e) {} + catch (Exception e) { + // ignore exception + } } return result; } @@ -423,14 +441,18 @@ public List> findElementsByXpath(Long root, String s) { try { Thread.sleep(100); } - catch (Exception e2) {} + catch (Exception e2) { + // ignore exception + } } } catch (Exception e) { try { Thread.sleep(100); } - catch (Exception e2) {} + catch (Exception e2) { + // ignore exception + } // e.printStackTrace(); } if (System.currentTimeMillis() > time + timeoutInMsecs) { @@ -438,7 +460,7 @@ public List> findElementsByXpath(Long root, String s) { } } info("timed out"); - return new Vector>(); + return new Vector<>(); } public ISwElement get(long tid) { @@ -454,7 +476,7 @@ private TafProperties getError(String statusMessage) { public ISwElement getSwElement(long tid, Component c) { if (c instanceof Frame) { - return new SwFrame(tid, (Frame)c); + return new SwFrame(tid, c); } if (c instanceof JInternalFrame) { return new SwInternalFrame(tid, (JInternalFrame)c); @@ -559,7 +581,7 @@ public String storeFormatted(Document xml, String path) throws Exception { } else { try { - Writer fw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path), "UTF-8")); + Writer fw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(path), StandardCharsets.UTF_8)); fw.write(xmlAsString); fw.close(); }