From 5bb41bb89180a3e1ac2f0ed9619d42b27e91a3b7 Mon Sep 17 00:00:00 2001 From: Pascal Bihler Date: Fri, 18 Mar 2022 12:24:30 +0100 Subject: [PATCH] Remove log4j and replace it with default java logger --- pom.xml | 16 +-------- .../automation/controls/AutomationBase.java | 5 ++- .../mmarquee/automation/controls/Tab.java | 4 +-- .../mmarquee/automation/controls/Window.java | 14 ++++---- .../automation/pattern/BasePattern.java | 5 ++- src/main/java/mmarquee/demo/ChromeDemo.java | 4 ++- src/main/java/mmarquee/demo/DemoCaching.java | 5 +-- .../java/mmarquee/demo/DemoEventHandler.java | 8 +++-- src/main/java/mmarquee/demo/DemoGrid.java | 7 ++-- .../java/mmarquee/demo/DemoPointOver.java | 4 ++- .../java/mmarquee/demo/DemoTreeWalker.java | 14 ++++---- src/main/java/mmarquee/demo/TestBase.java | 6 ++-- src/main/java/mmarquee/demo/TestExplorer.java | 4 +-- src/main/java/mmarquee/demo/TestMain.java | 12 ++++--- .../java/mmarquee/demo/TestMainExcel.java | 36 +++++++++---------- .../mmarquee/demo/TestMainPowerpoint.java | 2 +- src/main/java/mmarquee/demo/TestMainWPF.java | 15 ++++---- .../demo/TestMainWPFAutomationId.java | 6 ++-- src/main/java/mmarquee/demo/TestMainWord.java | 2 +- src/main/java/mmarquee/demo/TestNotepad.java | 10 +++--- src/main/resources/log4j.properties | 9 ----- .../controls/AutomationBaseTest.java | 27 +++++++------- .../AutomationControlFactoryTest.java | 16 ++++----- .../controls/AutomationStatusBarTest.java | 6 ++-- .../automation/controls/DataGridTest.java | 8 ++--- .../automation/controls/DataGridTest2.java | 15 ++++---- .../IUIAutomationElement3Test.java | 6 ++-- .../IUIAutomationElementTest.java | 6 ++-- .../uiautomation/IUIAutomationTest.java | 6 ++-- .../uiautomation/IUIWindowPatternTest.java | 6 ++-- ui-automation.iml | 2 -- 31 files changed, 135 insertions(+), 151 deletions(-) delete mode 100644 src/main/resources/log4j.properties diff --git a/pom.xml b/pom.xml index 6f4605f7..f919467b 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.github.mmarquee ui-automation - 0.7.0 + 0.8.0 jar ui-automation @@ -35,7 +35,6 @@ UTF-8 5.6.0 3.3.3 - 2.17.1 @@ -60,19 +59,6 @@ ${jna.version} - - - - org.apache.logging.log4j - log4j-api - ${log4j.version} - - - org.apache.logging.log4j - log4j-core - ${log4j.version} - - diff --git a/src/main/java/mmarquee/automation/controls/AutomationBase.java b/src/main/java/mmarquee/automation/controls/AutomationBase.java index 3f8d801f..bb71b5dc 100644 --- a/src/main/java/mmarquee/automation/controls/AutomationBase.java +++ b/src/main/java/mmarquee/automation/controls/AutomationBase.java @@ -25,14 +25,13 @@ import mmarquee.automation.pattern.*; import mmarquee.uiautomation.OrientationType; import mmarquee.uiautomation.TreeScope; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import java.lang.reflect.InvocationTargetException; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.logging.Logger; /** * The base for automation. @@ -47,7 +46,7 @@ public abstract class AutomationBase * The logger. */ private final Logger logger = - LogManager.getLogger(AutomationBase.class.getName()); + Logger.getLogger(AutomationBase.class.getName()); /** * Gets the logger. diff --git a/src/main/java/mmarquee/automation/controls/Tab.java b/src/main/java/mmarquee/automation/controls/Tab.java index 70f85489..24361bb8 100644 --- a/src/main/java/mmarquee/automation/controls/Tab.java +++ b/src/main/java/mmarquee/automation/controls/Tab.java @@ -53,7 +53,7 @@ public List getTabItems() { .automation(this.getAutomation()))); } } catch (AutomationException ex) { - getLogger().error(ex.getMessage()); + getLogger().severe(ex.getMessage()); } return tabItems; @@ -93,7 +93,7 @@ public void selectTabPage(final Pattern namePattern) throws AutomationException, for (TabItem item: this.getTabItems()) { final String name = item.getName(); - + if (name != null && namePattern.matcher(name).matches()) { found = true; item.selectItem(); diff --git a/src/main/java/mmarquee/automation/controls/Window.java b/src/main/java/mmarquee/automation/controls/Window.java index 91858764..488a400f 100644 --- a/src/main/java/mmarquee/automation/controls/Window.java +++ b/src/main/java/mmarquee/automation/controls/Window.java @@ -186,15 +186,15 @@ public Window getWindow(final String title) this.createControlTypeCondition( ControlType.Window))); } catch (ElementNotFoundException ex) { - getLogger().warn("Failed to find `" + title + "` window"); + getLogger().warning("Failed to find `" + title + "` window"); } if (item != null) { - getLogger().warn("Found window"); + getLogger().warning("Found window"); break; } else { try { - getLogger().warn( + getLogger().warning( "Did not find `" + title + "` window, retrying"); // Wait for it Thread.sleep(SLEEP_DURATION); @@ -227,7 +227,7 @@ public Window getWindow(Pattern titlePattern) this.findAll(new TreeScope(TreeScope.DESCENDANTS), this.createControlTypeCondition( ControlType.Window)); - + for (Element element : collection) { String name = element.getName(); @@ -236,12 +236,12 @@ public Window getWindow(Pattern titlePattern) break retry_loop; } } - + } catch (AutomationException ex) { getLogger().info("Failed"); } - getLogger().warn( + getLogger().warning( "Did not find window matching `" + titlePattern + "`, retrying"); // Wait for it try { @@ -251,7 +251,7 @@ public Window getWindow(Pattern titlePattern) getLogger().info("interrupted"); } } - + if (item == null) { throw new ElementNotFoundException( "matching " + titlePattern.toString()); diff --git a/src/main/java/mmarquee/automation/pattern/BasePattern.java b/src/main/java/mmarquee/automation/pattern/BasePattern.java index e4cdde65..67dbf7ca 100644 --- a/src/main/java/mmarquee/automation/pattern/BasePattern.java +++ b/src/main/java/mmarquee/automation/pattern/BasePattern.java @@ -25,10 +25,9 @@ import mmarquee.uiautomation.IUIAutomationElementArray; import mmarquee.uiautomation.IUIAutomationElementArrayConverter; import mmarquee.uiautomation.IUIAutomationElementConverter; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import java.util.function.Function; +import java.util.logging.Logger; /** * The base pattern functionality, shared for all patterns. @@ -42,7 +41,7 @@ public abstract class BasePattern /** * The logger. */ - final Logger logger = LogManager.getLogger(BasePattern.class.getName()); + final Logger logger = Logger.getLogger(BasePattern.class.getName()); /** * The guid of the pattern. diff --git a/src/main/java/mmarquee/demo/ChromeDemo.java b/src/main/java/mmarquee/demo/ChromeDemo.java index f3759142..8f45f981 100644 --- a/src/main/java/mmarquee/demo/ChromeDemo.java +++ b/src/main/java/mmarquee/demo/ChromeDemo.java @@ -1,5 +1,7 @@ package mmarquee.demo; +import java.util.logging.Level; + import mmarquee.automation.UIAutomation; import mmarquee.automation.controls.Application; import mmarquee.automation.controls.ElementBuilder; @@ -19,7 +21,7 @@ public void run() { try { chrome.launchOrAttach(); } catch (Throwable ex) { - logger.warn("Failed to find application", ex); + logger.log(Level.WARNING, "Failed to find application", ex); } } } diff --git a/src/main/java/mmarquee/demo/DemoCaching.java b/src/main/java/mmarquee/demo/DemoCaching.java index 45c83f9e..55373d3b 100644 --- a/src/main/java/mmarquee/demo/DemoCaching.java +++ b/src/main/java/mmarquee/demo/DemoCaching.java @@ -23,6 +23,7 @@ import mmarquee.uiautomation.TreeScope; import java.util.List; +import java.util.logging.Level; /** * Demo for the caching functionality. @@ -41,7 +42,7 @@ public void run() { application = automation.launchOrAttach("apps\\Project1.exe"); } catch (Throwable ex) { - logger.warn("Failed to find application", ex); + logger.log(Level.WARNING, "Failed to find application", ex); } try { @@ -49,7 +50,7 @@ public void run() { assert application != null; application.waitForInputIdle(Application.SHORT_TIMEOUT); } catch (Throwable ex) { - logger.error("Failed to wait properly"); + logger.log(Level.WARNING, "Failed to wait properly"); } try { diff --git a/src/main/java/mmarquee/demo/DemoEventHandler.java b/src/main/java/mmarquee/demo/DemoEventHandler.java index 3a363427..29cf1958 100644 --- a/src/main/java/mmarquee/demo/DemoEventHandler.java +++ b/src/main/java/mmarquee/demo/DemoEventHandler.java @@ -16,6 +16,8 @@ package mmarquee.demo; +import java.util.logging.Level; + import mmarquee.automation.UIAutomation; import mmarquee.automation.controls.Application; import mmarquee.automation.controls.Button; @@ -39,7 +41,7 @@ public void run() { try { application = automation.launchOrAttach("apps\\Project1.exe"); } catch (Throwable ex) { - logger.warn("Failed to find application", ex); + logger.log(Level.WARNING, "Failed to find application", ex); } try { @@ -47,7 +49,7 @@ public void run() { assert application != null; application.waitForInputIdle(Application.SHORT_TIMEOUT); } catch (Throwable ex) { - logger.error("Failed to wait properly"); + logger.severe("Failed to wait properly"); } try { @@ -64,7 +66,7 @@ public void run() { new AutomationEventHandler()); */ } catch (Throwable ex) { - logger.error("Failed to get window properly"); + logger.severe("Failed to get window properly"); } } } \ No newline at end of file diff --git a/src/main/java/mmarquee/demo/DemoGrid.java b/src/main/java/mmarquee/demo/DemoGrid.java index af54520b..39310c07 100644 --- a/src/main/java/mmarquee/demo/DemoGrid.java +++ b/src/main/java/mmarquee/demo/DemoGrid.java @@ -20,6 +20,7 @@ import mmarquee.automation.controls.*; import java.util.List; +import java.util.logging.Level; /** * @author Mark Humphreys @@ -41,11 +42,11 @@ public void run() { try { application.launchOrAttach(); } catch (Throwable ex) { - logger.warn("Failed to find application", ex); + logger.log(Level.WARNING, "Failed to find application", ex); } // Check that the attached issue is fixed. - logger.info(application.getIsAttached()); + logger.info("attached: " + application.getIsAttached()); // Wait for the process to start // This doesn't seem to wait for WPF examples @@ -77,7 +78,7 @@ public void run() { try { boolean val = applicationWindow.isModal(); - logger.info(val); + logger.info("isModal: " + val); } catch (Exception ex) { logger.info("Ouch"); } diff --git a/src/main/java/mmarquee/demo/DemoPointOver.java b/src/main/java/mmarquee/demo/DemoPointOver.java index 3b55f256..29b95350 100644 --- a/src/main/java/mmarquee/demo/DemoPointOver.java +++ b/src/main/java/mmarquee/demo/DemoPointOver.java @@ -22,6 +22,8 @@ import java.awt.*; +import java.util.logging.Level; + /** * Example for the PointOver functionality. * @@ -56,7 +58,7 @@ public final void run() { logger.info("From focus = " + elementFocus.getName()); } catch (Exception ex) { - logger.info(ex.getStackTrace()); + logger.log(Level.WARNING, "Exception", ex); } } while (true); } diff --git a/src/main/java/mmarquee/demo/DemoTreeWalker.java b/src/main/java/mmarquee/demo/DemoTreeWalker.java index f50de1df..db84f841 100644 --- a/src/main/java/mmarquee/demo/DemoTreeWalker.java +++ b/src/main/java/mmarquee/demo/DemoTreeWalker.java @@ -55,9 +55,9 @@ public void run() { AutomationElementVisitor logVisitor = new AutomationElementVisitor() { - + int level = 0; - + @Override public boolean visit(AutomationTreeWalker walker, Element element) @@ -73,26 +73,26 @@ public boolean visit(AutomationTreeWalker walker, indent, name, className); - + logger.info(message); - + if (recurseLevel > level) { level++; walker.walk(this, element); level--; } - + return true; } }; - + walker.walk(logVisitor, root); logger.info("All done"); } catch (Throwable ex) { // Smother - logger.error("Exception thrown - " + ex.toString()); + logger.severe("Exception thrown - " + ex.toString()); ex.printStackTrace(); } } diff --git a/src/main/java/mmarquee/demo/TestBase.java b/src/main/java/mmarquee/demo/TestBase.java index 6da6e4dc..0f9c62cd 100644 --- a/src/main/java/mmarquee/demo/TestBase.java +++ b/src/main/java/mmarquee/demo/TestBase.java @@ -1,8 +1,8 @@ package mmarquee.demo; +import java.util.logging.Logger; + import mmarquee.automation.controls.AutomationBase; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; /** * @author Mark Humphreys @@ -11,7 +11,7 @@ public class TestBase { protected Logger logger = - LogManager.getLogger(AutomationBase.class.getName()); + Logger.getLogger(AutomationBase.class.getName()); protected void rest() { try { diff --git a/src/main/java/mmarquee/demo/TestExplorer.java b/src/main/java/mmarquee/demo/TestExplorer.java index 4cdd1f2d..f2b2b02b 100644 --- a/src/main/java/mmarquee/demo/TestExplorer.java +++ b/src/main/java/mmarquee/demo/TestExplorer.java @@ -44,14 +44,14 @@ public final void run() { application = automation.launchOrAttach("explorer"); } catch (Throwable ex) { // Smother - logger.error("Failed to launch or attach"); + logger.severe("Failed to launch or attach"); } try { assert application != null; application.waitForInputIdle(Application.SHORT_TIMEOUT); } catch (Throwable ex) { - logger.error("Failed to wait for input idle for some reason"); + logger.severe("Failed to wait for input idle for some reason"); } // Get the main explorer window diff --git a/src/main/java/mmarquee/demo/TestMain.java b/src/main/java/mmarquee/demo/TestMain.java index 3468c8f7..65272c91 100644 --- a/src/main/java/mmarquee/demo/TestMain.java +++ b/src/main/java/mmarquee/demo/TestMain.java @@ -16,6 +16,8 @@ package mmarquee.demo; +import java.util.logging.Level; + import com.sun.jna.platform.win32.WinDef; import mmarquee.automation.*; import mmarquee.automation.controls.*; @@ -45,7 +47,7 @@ public final void run() { try { application.launchOrAttach(); } catch (Throwable ex) { - logger.warn("Failed to find application", ex); + logger.log(Level.WARNING, "Failed to find application", ex); } try { @@ -53,7 +55,7 @@ public final void run() { assert application != null; application.waitForInputIdle(Application.SHORT_TIMEOUT); } catch (Throwable ex) { - logger.error("Failed to wait properly"); + logger.severe("Failed to wait properly"); } try { @@ -163,7 +165,7 @@ public final void run() { logger.info("Text for AutomatedCombobox1 is " + txt); } catch (ElementNotFoundException ex) { - logger.error("Failed to find element"); + logger.severe("Failed to find element"); } try { @@ -180,7 +182,7 @@ public final void run() { logger.info("Changed value is " + value1); } catch (ElementNotFoundException ex) { - logger.error("Failed to find maskededit"); + logger.severe("Failed to find maskededit"); } try { @@ -194,7 +196,7 @@ public final void run() { java.util.List litems = cb0.getItems(); } catch (ElementNotFoundException ex) { - logger.error("Failed to find combobox"); + logger.severe("Failed to find combobox"); } // Now string grids diff --git a/src/main/java/mmarquee/demo/TestMainExcel.java b/src/main/java/mmarquee/demo/TestMainExcel.java index 75de83e5..4c3b11e2 100644 --- a/src/main/java/mmarquee/demo/TestMainExcel.java +++ b/src/main/java/mmarquee/demo/TestMainExcel.java @@ -47,7 +47,7 @@ public final void run() { "C:\\Program Files (x86)\\Microsoft Office\\root\\Office16\\EXCEL.EXE"); } catch (Throwable ex) { // Smother - logger.error("Failed to launch or attach"); + logger.severe("Failed to launch or attach"); } // 1. Load a file in excel @@ -70,7 +70,7 @@ public final void run() { List items = tab.getTabItems(); - logger.info(items.size()); + logger.info("size: " + items.size()); for(TabItem item : items) { logger.info(item.getName()); @@ -84,26 +84,26 @@ public final void run() { DataGridCell cell = grid.getItem( Search.getBuilder(0,0).build()); - logger.info(cell.getName()); - logger.info(cell.getValue()); - logger.info(cell.getColumn()); - logger.info(cell.getRow()); + logger.info("name: " + cell.getName()); + logger.info("value: " + cell.getValue()); + logger.info("col: " + cell.getColumn()); + logger.info("row: " + cell.getRow()); DataGridCell cell1 = grid.getItem( Search.getBuilder(1,1).build()); - logger.info(cell1.getName()); - logger.info(cell1.getValue()); - logger.info(cell1.getColumn()); - logger.info(cell1.getRow()); + logger.info("name: " + cell1.getName()); + logger.info("value: " + cell1.getValue()); + logger.info("col: " + cell1.getColumn()); + logger.info("row: " + cell1.getRow()); DataGridCell cell2 = grid.getItem( Search.getBuilder(2,2).build()); - logger.info(cell2.getName()); - logger.info(cell2.getValue()); - logger.info(cell2.getColumn()); - logger.info(cell2.getRow()); + logger.info("name: " + cell2.getName()); + logger.info("value: " + cell2.getValue()); + logger.info("col: " + cell2.getColumn()); + logger.info("row: " + cell2.getRow()); // 3.5 Set some data cell2.setValue("XYZ"); @@ -112,8 +112,8 @@ public final void run() { DataGridCell cell3 = grid.getItem( Search.getBuilder(3,3).build()); - logger.info(cell3.getName()); - logger.info(cell3.getValue()); + logger.info("name: " + cell3.getName()); + logger.info("value: " + cell3.getValue()); if (grid.canSelectMultiple()) { // Play with selection - doesn't seem to be working yet @@ -123,13 +123,13 @@ public final void run() { // something List items0 = grid.getSelection(); - logger.info(items0.size()); + logger.info("size: " + items0.size()); cell2.removeFromSelection(); // something again - should be different List items1 = grid.getSelection(); - logger.info(items1.size()); + logger.info("size: " + items1.size()); } else { logger.info("Multiple selection not allowed"); } diff --git a/src/main/java/mmarquee/demo/TestMainPowerpoint.java b/src/main/java/mmarquee/demo/TestMainPowerpoint.java index 8f4b793d..56d66cba 100644 --- a/src/main/java/mmarquee/demo/TestMainPowerpoint.java +++ b/src/main/java/mmarquee/demo/TestMainPowerpoint.java @@ -44,7 +44,7 @@ public final void run() { "C:\\Program Files (x86)\\Microsoft Office\\root\\Office16\\POWERPNT.EXE\""); } catch (Throwable ex) { // Smother - logger.error("Failed to launch or attach Powerpoint"); + logger.severe("Failed to launch or attach Powerpoint"); } // 1. Load the file diff --git a/src/main/java/mmarquee/demo/TestMainWPF.java b/src/main/java/mmarquee/demo/TestMainWPF.java index d1b1a0bb..85697d05 100644 --- a/src/main/java/mmarquee/demo/TestMainWPF.java +++ b/src/main/java/mmarquee/demo/TestMainWPF.java @@ -26,6 +26,7 @@ import mmarquee.uiautomation.RowOrColumnMajor; import mmarquee.uiautomation.ToggleState; +import java.util.logging.Level; import java.util.regex.Pattern; /** @@ -48,7 +49,7 @@ public final void run() { try { application.launchOrAttach(); } catch (Throwable ex) { - logger.warn("Failed to find application", ex); + logger.log(Level.WARNING, "Failed to find application", ex); } // Wait for the process to start @@ -97,7 +98,7 @@ public final void run() { try { boolean val = applicationWindow.isModal(); - logger.info(val); + logger.info("isModal: " + val); } catch (Exception ex) { logger.info("Ouch"); } @@ -129,7 +130,7 @@ public final void run() { file.expand(); this.rest(); - + logger.info("Items = " + file.getItems().size()); MenuItem exit = file.getItems().get(3); @@ -304,7 +305,7 @@ public final void run() { // String txt = cb0.text(); // logger.info("Text for Combobox is `" + txt + "`"); } catch (ElementNotFoundException ex) { - logger.error("Failed to find element"); + logger.severe("Failed to find element"); } // EDITTABLE COMBOBOX ************************************ @@ -324,7 +325,7 @@ public final void run() { logger.info("Text for Combobox is now `" + cb1.getValue() + "`"); } catch (ElementNotFoundException ex) { - logger.error("Failed to find element"); + logger.severe("Failed to find element"); } // DATAGRIDS *********************************************************** @@ -624,8 +625,8 @@ public final void run() { WinDef.POINT clickPoint = rightClickBtn.getClickablePoint(); - logger.info(clickPoint.x); - logger.info(clickPoint.y); + logger.info("x: " + clickPoint.x); + logger.info("y: " + clickPoint.y); WinDef.RECT rect0 = rightClickBtn.getBoundingRectangle(); diff --git a/src/main/java/mmarquee/demo/TestMainWPFAutomationId.java b/src/main/java/mmarquee/demo/TestMainWPFAutomationId.java index cea729fd..208b7b51 100644 --- a/src/main/java/mmarquee/demo/TestMainWPFAutomationId.java +++ b/src/main/java/mmarquee/demo/TestMainWPFAutomationId.java @@ -15,6 +15,8 @@ */ package mmarquee.demo; +import java.util.logging.Level; + import com.sun.jna.platform.win32.WinDef; import mmarquee.automation.UIAutomation; import mmarquee.automation.controls.Application; @@ -42,7 +44,7 @@ public final void run() { application = automation.launchOrAttach( "apps\\WpfApplicationWithAutomationIds.exe"); } catch (Throwable ex) { - logger.warn("Failed to find application", ex); + logger.log(Level.WARNING, "Failed to find application", ex); } // Wait for the process to start @@ -78,7 +80,7 @@ public final void run() { try { boolean val = applicationWindow.isModal(); - logger.info(val); + logger.info("isModal: " + val); } catch (Exception ex) { logger.info("Ouch"); } diff --git a/src/main/java/mmarquee/demo/TestMainWord.java b/src/main/java/mmarquee/demo/TestMainWord.java index 89745b20..4280009f 100644 --- a/src/main/java/mmarquee/demo/TestMainWord.java +++ b/src/main/java/mmarquee/demo/TestMainWord.java @@ -38,7 +38,7 @@ public final void run() { application = automation.launchOrAttach("C:\\Program Files (x86)\\Microsoft Office\\root\\Office16\\WINWORD.EXE"); } catch (Throwable ex) { // Smother - logger.error("Failed to launch or attach"); + logger.severe("Failed to launch or attach"); } // 1. Load a file in Word diff --git a/src/main/java/mmarquee/demo/TestNotepad.java b/src/main/java/mmarquee/demo/TestNotepad.java index 98b4f0a1..ea5e32db 100644 --- a/src/main/java/mmarquee/demo/TestNotepad.java +++ b/src/main/java/mmarquee/demo/TestNotepad.java @@ -21,9 +21,9 @@ import mmarquee.automation.controls.*; import mmarquee.automation.controls.MainMenu; import mmarquee.automation.controls.MenuItem; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import java.util.logging.Level; +import java.util.logging.Logger; import java.util.regex.Pattern; /** @@ -41,7 +41,7 @@ public final void run() { UIAutomation automation = UIAutomation.getInstance(); Logger logger = - LogManager.getLogger(AutomationBase.class.getName()); + Logger.getLogger(AutomationBase.class.getName()); Application application = new Application( @@ -52,13 +52,13 @@ public final void run() { try { application.launchOrAttach(); } catch (Throwable ex) { - logger.warn("Failed to find notepad application", ex); + logger.log(Level.WARNING, "Failed to find notepad application", ex); } try { logger.info(Application.getVersionNumber("notepad.exe")); } catch (Throwable ex) { - logger.warn("Failed to get version information", ex); + logger.log(Level.WARNING, "Failed to get version information", ex); } // Wait for the process to start diff --git a/src/main/resources/log4j.properties b/src/main/resources/log4j.properties deleted file mode 100644 index 63cba917..00000000 --- a/src/main/resources/log4j.properties +++ /dev/null @@ -1,9 +0,0 @@ -# Set root logger level to DEBUG and its only appender to A1. -log4j.rootLogger=INFO, A1 - -# A1 is set to be a ConsoleAppender. -log4j.appender.A1=org.apache.log4j.ConsoleAppender - -# A1 uses PatternLayout. -log4j.appender.A1.layout=org.apache.log4j.PatternLayout -log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n diff --git a/src/test/java/mmarquee/automation/controls/AutomationBaseTest.java b/src/test/java/mmarquee/automation/controls/AutomationBaseTest.java index f5345e35..cd167b1c 100644 --- a/src/test/java/mmarquee/automation/controls/AutomationBaseTest.java +++ b/src/test/java/mmarquee/automation/controls/AutomationBaseTest.java @@ -27,10 +27,9 @@ import java.util.ArrayList; import java.util.List; +import java.util.logging.Logger; import mmarquee.automation.*; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.junit.Assume; import org.junit.Before; import org.junit.BeforeClass; @@ -68,7 +67,7 @@ */ public class AutomationBaseTest { protected Logger logger = - LogManager.getLogger(AutomationBaseTest.class.getName()); + Logger.getLogger(AutomationBaseTest.class.getName()); @BeforeClass public static void checkOs() throws Exception { @@ -90,7 +89,7 @@ private static boolean isWindows() { static { ClassLoader.getSystemClassLoader().setDefaultAssertionStatus(true); } - + // Helper to test the abstract class static class ConcreteAutomationBase extends AutomationBase { @@ -198,7 +197,7 @@ public void testGetFrameworkId_Gets_Value_From_Element() throws Exception { @Test public void testIsAutomationPatternAvailablePatternID () throws Exception { - + Window window = new Window(new ElementBuilder(element)); when(element.getPropertyValue(PropertyID.IsGridItemPatternAvailable.getValue())).thenReturn(1); @@ -209,10 +208,10 @@ public void testIsAutomationPatternAvailablePatternID () throws Exception { @Test public void testIsAutomationPatternAvailableAllDefinedPatternID_no_Exception () throws Exception { - + Window window = new Window(new ElementBuilder(element)); when(element.getPropertyValue(anyInt())).thenReturn(0); - + for (final PatternID patternId: PatternID.values()) { window.isAutomationPatternAvailable(patternId); } @@ -232,7 +231,7 @@ public void testIsAutomationPatternAvailablePatternID_when_not_available () thro @Test public void testIsAutomationPatternAvailableInt () throws Exception { - + Window window = new Window(new ElementBuilder(element)); when(element.getPropertyValue(PropertyID.IsWindowPatternAvailable.getValue())).thenReturn(1); @@ -244,7 +243,7 @@ public void testIsAutomationPatternAvailableInt () throws Exception { @Test public void testIsAutomationPatternAvailableIntSecondVersion () throws Exception { - + Window window = new Window(new ElementBuilder(element)); when(element.getPropertyValue(PropertyID.IsTextPattern2Available.getValue())).thenReturn(1); @@ -271,10 +270,10 @@ public void testIsAutomationPatternAvailableInt_when_bad_number () throws Except window.isAutomationPatternAvailable(-815); } - + @Test public void testIsAutomationPatternAvailableBasePatternClass () throws Exception { - + MultipleView pattern = Mockito.mock(MultipleView.class); when(pattern.isAvailable()).thenReturn(true); @@ -287,7 +286,7 @@ public void testIsAutomationPatternAvailableBasePatternClass () throws Exception @Test public void testIsAutomationPatternAvailableBasePatternClass_when_not_available () throws Exception { - + Dock pattern = Mockito.mock(Dock.class); when(pattern.isAvailable()).thenReturn(false); @@ -297,10 +296,10 @@ public void testIsAutomationPatternAvailableBasePatternClass_when_not_available assertFalse(value); } - + @Test public void testIsMultipleViewPatternAvailable () throws Exception { - + MultipleView pattern = Mockito.mock(MultipleView.class); when(pattern.isAvailable()).thenReturn(true); diff --git a/src/test/java/mmarquee/automation/controls/AutomationControlFactoryTest.java b/src/test/java/mmarquee/automation/controls/AutomationControlFactoryTest.java index 17ac90cd..e6d50b42 100644 --- a/src/test/java/mmarquee/automation/controls/AutomationControlFactoryTest.java +++ b/src/test/java/mmarquee/automation/controls/AutomationControlFactoryTest.java @@ -19,9 +19,9 @@ import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.when; +import java.util.logging.Logger; + import mmarquee.uiautomation.IUIAutomationElement; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.junit.Assume; import org.junit.Before; import org.junit.BeforeClass; @@ -55,8 +55,8 @@ private static boolean isWindows() { } protected Logger logger = - LogManager.getLogger(AutomationControlFactoryTest.class.getName()); - + Logger.getLogger(AutomationControlFactoryTest.class.getName()); + private AutomationBase parent; private Element parentElement; private Element element; @@ -65,7 +65,7 @@ private static boolean isWindows() { static { ClassLoader.getSystemClassLoader().setDefaultAssertionStatus(true); } - + @Before public void setUp() { parent = Mockito.mock(AutomationBase.class); @@ -74,7 +74,7 @@ public void setUp() { iuielement = Mockito.mock(IUIAutomationElement.class); element = new Element(iuielement); } - + @Test public void get_returns_AutomationContainer_on_None() throws Exception { @@ -335,12 +335,12 @@ private AutomationBase testGet(ControlType controlType, Class expectedClass) throws AutomationException, PatternNotFoundException { BaseAutomationTest.answerIntByReference(controlType.getValue()).when(iuielement).getCurrentControlType(any()); BaseAutomationTest.answerStringByReference(className).when(iuielement).getCurrentClassName(any()); - + AutomationBase control = AutomationControlFactory.get(parent, element); assertEquals(expectedClass, control.getClass()); assertEquals(element,control.getElement()); diff --git a/src/test/java/mmarquee/automation/controls/AutomationStatusBarTest.java b/src/test/java/mmarquee/automation/controls/AutomationStatusBarTest.java index e74e2627..cc7057cc 100644 --- a/src/test/java/mmarquee/automation/controls/AutomationStatusBarTest.java +++ b/src/test/java/mmarquee/automation/controls/AutomationStatusBarTest.java @@ -19,21 +19,21 @@ import mmarquee.automation.UIAutomation; import mmarquee.automation.pattern.ItemContainer; import mmarquee.uiautomation.IUIAutomation; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.junit.Test; import org.mockito.Mockito; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.when; +import java.util.logging.Logger; + /** * @author Mark Humphreys * Date 02/12/2016. */ public class AutomationStatusBarTest { protected Logger logger = - LogManager.getLogger(RadioButtonTest.class.getName()); + Logger.getLogger(RadioButtonTest.class.getName()); @Test public void testName_Gets_Name_From_Element() throws Exception { diff --git a/src/test/java/mmarquee/automation/controls/DataGridTest.java b/src/test/java/mmarquee/automation/controls/DataGridTest.java index c9f01662..da559d5f 100644 --- a/src/test/java/mmarquee/automation/controls/DataGridTest.java +++ b/src/test/java/mmarquee/automation/controls/DataGridTest.java @@ -23,8 +23,6 @@ import mmarquee.automation.pattern.Value; import mmarquee.uiautomation.IUIAutomation; import mmarquee.uiautomation.RowOrColumnMajor; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.junit.Ignore; import org.junit.Test; import org.mockito.Mockito; @@ -32,6 +30,8 @@ import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.when; +import java.util.logging.Logger; + /** * @author Mark Humphreys * Date 28/11/2016. @@ -39,7 +39,7 @@ public class DataGridTest { protected Logger logger = - LogManager.getLogger(DataGridTest.class.getName()); + Logger.getLogger(DataGridTest.class.getName()); static { ClassLoader.getSystemClassLoader().setDefaultAssertionStatus(true); @@ -79,7 +79,7 @@ public void testGetValue_Gets_Value_From_Value_Pattern() throws Exception { when(value.isAvailable()).thenReturn(true); when(grid.isAvailable()).thenReturn(true); when(table.isAvailable()).thenReturn(true); - + when(value.value()).thenReturn("VALUE"); IUIAutomation mocked_automation = Mockito.mock(IUIAutomation.class); diff --git a/src/test/java/mmarquee/automation/controls/DataGridTest2.java b/src/test/java/mmarquee/automation/controls/DataGridTest2.java index 282c2540..2ae2772c 100644 --- a/src/test/java/mmarquee/automation/controls/DataGridTest2.java +++ b/src/test/java/mmarquee/automation/controls/DataGridTest2.java @@ -22,10 +22,9 @@ import java.util.ArrayList; import java.util.List; +import java.util.logging.Logger; import mmarquee.automation.Element; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.junit.Assume; import org.junit.BeforeClass; import org.junit.Ignore; @@ -55,7 +54,7 @@ private static boolean isWindows() { } protected Logger logger = - LogManager.getLogger(DataGridTest2.class.getName()); + Logger.getLogger(DataGridTest2.class.getName()); static { ClassLoader.getSystemClassLoader().setDefaultAssertionStatus(true); @@ -71,7 +70,7 @@ public void testGetCell_For_DataGrid() throws Exception { when(grid.isAvailable()).thenReturn(true); when(table.isAvailable()).thenReturn(true); - + IUIAutomation mocked_automation = Mockito.mock(IUIAutomation.class); UIAutomation instance = new UIAutomation(mocked_automation); @@ -94,7 +93,7 @@ public void testGetColumnHeaders_Returns_Correct_Size() throws Exception { when(grid.isAvailable()).thenReturn(true); when(table.isAvailable()).thenReturn(true); - + List elementList = new ArrayList<>(); Element element1 = Mockito.mock(Element.class); Element element2 = Mockito.mock(Element.class); @@ -125,7 +124,7 @@ public void testGetColumnHeader() throws Exception { when(grid.isAvailable()).thenReturn(true); when(table.isAvailable()).thenReturn(true); - + List elementList = new ArrayList<>(); Element element1 = Mockito.mock(Element.class); Element element2 = Mockito.mock(Element.class); @@ -162,7 +161,7 @@ public void testGetColumnHeaders_Returns_Size_As_ColumnCount() throws Exception when(grid.isAvailable()).thenReturn(true); when(table.isAvailable()).thenReturn(true); - + List elementList = new ArrayList<>(); Element element1 = Mockito.mock(Element.class); Element element2 = Mockito.mock(Element.class); @@ -194,7 +193,7 @@ public void testSelected() throws Exception { when(grid.isAvailable()).thenReturn(true); when(table.isAvailable()).thenReturn(true); - + List elementList = new ArrayList<>(); Element element1 = Mockito.mock(Element.class); Element element2 = Mockito.mock(Element.class); diff --git a/src/test/java/mmarquee/uiautomation/IUIAutomationElement3Test.java b/src/test/java/mmarquee/uiautomation/IUIAutomationElement3Test.java index 8d6aa3d3..e27dd6ef 100644 --- a/src/test/java/mmarquee/uiautomation/IUIAutomationElement3Test.java +++ b/src/test/java/mmarquee/uiautomation/IUIAutomationElement3Test.java @@ -22,8 +22,6 @@ import com.sun.jna.ptr.IntByReference; import com.sun.jna.ptr.PointerByReference; import mmarquee.automation.*; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.junit.*; import org.mockito.Mockito; @@ -32,6 +30,8 @@ import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.when; +import java.util.logging.Logger; + /** * @author Mark Humphreys * Date 01/06/2017. @@ -52,7 +52,7 @@ private static boolean isWindows() { } private Logger logger = - LogManager.getLogger(IUIAutomationTest.class.getName()); + Logger.getLogger(IUIAutomationTest.class.getName()); static { ClassLoader.getSystemClassLoader().setDefaultAssertionStatus(true); diff --git a/src/test/java/mmarquee/uiautomation/IUIAutomationElementTest.java b/src/test/java/mmarquee/uiautomation/IUIAutomationElementTest.java index 16a2188f..75a0d528 100644 --- a/src/test/java/mmarquee/uiautomation/IUIAutomationElementTest.java +++ b/src/test/java/mmarquee/uiautomation/IUIAutomationElementTest.java @@ -22,8 +22,6 @@ import com.sun.jna.ptr.IntByReference; import com.sun.jna.ptr.PointerByReference; import mmarquee.automation.*; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.junit.*; import org.mockito.Mockito; @@ -33,6 +31,8 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.atLeastOnce; +import java.util.logging.Logger; + /** * @author Mark Humphreys * Date 18/10/2016. @@ -53,7 +53,7 @@ private static boolean isWindows() { } private Logger logger = - LogManager.getLogger(IUIAutomationTest.class.getName()); + Logger.getLogger(IUIAutomationTest.class.getName()); static { ClassLoader.getSystemClassLoader().setDefaultAssertionStatus(true); diff --git a/src/test/java/mmarquee/uiautomation/IUIAutomationTest.java b/src/test/java/mmarquee/uiautomation/IUIAutomationTest.java index 29d9d64b..6eeea61a 100644 --- a/src/test/java/mmarquee/uiautomation/IUIAutomationTest.java +++ b/src/test/java/mmarquee/uiautomation/IUIAutomationTest.java @@ -21,8 +21,6 @@ import com.sun.jna.platform.win32.COM.Unknown; import com.sun.jna.ptr.IntByReference; import com.sun.jna.ptr.PointerByReference; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.junit.Assume; import org.junit.Before; import org.junit.BeforeClass; @@ -31,6 +29,8 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import java.util.logging.Logger; + /** * @author Mark Humphreys * Date 13/10/2016. @@ -49,7 +49,7 @@ private static boolean isWindows() { } protected Logger logger = - LogManager.getLogger(IUIAutomationTest.class.getName()); + Logger.getLogger(IUIAutomationTest.class.getName()); static { ClassLoader.getSystemClassLoader().setDefaultAssertionStatus(true); diff --git a/src/test/java/mmarquee/uiautomation/IUIWindowPatternTest.java b/src/test/java/mmarquee/uiautomation/IUIWindowPatternTest.java index c513a6dc..f0461c10 100644 --- a/src/test/java/mmarquee/uiautomation/IUIWindowPatternTest.java +++ b/src/test/java/mmarquee/uiautomation/IUIWindowPatternTest.java @@ -21,13 +21,13 @@ import com.sun.jna.platform.win32.COM.Unknown; import com.sun.jna.ptr.PointerByReference; import mmarquee.automation.*; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.junit.*; import static org.junit.Assert.assertFalse; import static org.junit.Assert.fail; +import java.util.logging.Logger; + /** * @author Mark Humphreys * Date 20/11/2016. @@ -48,7 +48,7 @@ private static boolean isWindows() { } protected Logger logger = - LogManager.getLogger(IUIWindowPatternTest.class.getName()); + Logger.getLogger(IUIWindowPatternTest.class.getName()); static { ClassLoader.getSystemClassLoader().setDefaultAssertionStatus(true); diff --git a/ui-automation.iml b/ui-automation.iml index e707d7e7..00d48571 100644 --- a/ui-automation.iml +++ b/ui-automation.iml @@ -24,8 +24,6 @@ - -