diff --git a/azure-pipelines.yml b/azure-pipelines.yml index bdabf17..5268db1 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -1,13 +1,16 @@ -# Maven - trigger: - master pool: vmImage: 'windows-latest' -steps: +jobs: +- job: sonar + displayName: Analyse code with SonarQube + + steps: - task: SonarCloudPrepare@1 + displayName: 'Prepare SonarCloud analysis' inputs: SonarCloud: 'SonarCloud' organization: 'aqualityautomation' @@ -15,7 +18,34 @@ steps: configMode: 'file' extraProperties: | sonar.coverage.exclusions=**/** + + - task: Maven@3 + displayName: 'Build project' + inputs: + mavenPomFile: 'pom.xml' + mavenOptions: '-Xmx3072m' + javaHomeOption: 'JDKVersion' + jdkVersionOption: '1.8' + jdkArchitectureOption: 'x64' + publishJUnitResults: true + testResultsFiles: '**/surefire-reports/TEST-*.xml' + goals: 'clean' + + - task: SonarCloudAnalyze@1 + displayName: 'Run SonarCloud code analysis' + continueOnError: true + + - task: SonarCloudPublish@1 + displayName: 'Publish SonarCloud quality gate results' + inputs: + pollingTimeoutSec: '300' + +- job: tests + displayName: Run tests + + steps: - task: ScreenResolutionUtility@1 + displayName: 'Set optimal screen resolution' inputs: displaySettings: 'optimal' @@ -25,6 +55,7 @@ steps: OperationType: 'Start' - task: Maven@3 + displayName: 'Run tests' inputs: mavenPomFile: 'pom.xml' mavenOptions: '-Xmx3072m' @@ -35,13 +66,7 @@ steps: testResultsFiles: '**/surefire-reports/TEST-*.xml' goals: 'clean test -Dprofile=local' - - task: SonarCloudAnalyze@1 - - - task: SonarCloudPublish@1 - inputs: - pollingTimeoutSec: '300' - - task: Windows Application Driver@0 - displayName: stop WinAppDriver + displayName: 'Stop WinAppDriver' inputs: OperationType: 'Stop' diff --git a/pom.xml b/pom.xml index e64e784..ff55168 100644 --- a/pom.xml +++ b/pom.xml @@ -3,13 +3,16 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 + com.github.aquality-automation aquality-selenium-core - 1.0.0 + 1.0.1 + jar Aquality Selenium Core Library with core functions simplifying work with Selenium-controlled applications. https://github.com/aquality-automation/aquality-selenium-core-java + UTF-8 UTF-8 @@ -113,155 +116,124 @@ test - - - default - - true - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.1 + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.8 + 1.8 + + + + org.jacoco + jacoco-maven-plugin + 0.8.4 + + + pre-unit-test + + prepare-agent + - 1.8 - 1.8 + ${project.build.directory}/jacoco/jacoco-ut.exec + surefireArgLine - - - org.jacoco - jacoco-maven-plugin - 0.8.4 - - - pre-unit-test - - prepare-agent - - - ${project.build.directory}/jacoco/jacoco-ut.exec - surefireArgLine - - - - post-unit-test - test - - report - - - ${project.build.directory}/jacoco/jacoco-ut.exec - ${project.build.directory}/coverage-report - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.20 + + + post-unit-test + test + + report + - ${surefireArgLine} -Dfile.encoding=UTF-8 - false - - src/test/resources/TestSuite.xml - + ${project.build.directory}/jacoco/jacoco-ut.exec + ${project.build.directory}/coverage-report - - - org.apache.maven.plugins - maven-assembly-plugin - - - - attached - - package - - - jar-with-dependencies - - - - - - - org.apache.maven.plugins - maven-source-plugin - - - attach-sources - - jar - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - - - attach-javadocs - - jar - - - - - - org.apache.maven.plugins - maven-gpg-plugin - 1.6 - - - sign-artifacts - verify - - sign - - - - - - org.sonatype.plugins - nexus-staging-maven-plugin - 1.6.8 - true + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.20 + + ${surefireArgLine} -Dfile.encoding=UTF-8 + false + + src/test/resources/TestSuite.xml + + + + + org.apache.maven.plugins + maven-assembly-plugin + + + + attached + + package - ossrh - https://oss.sonatype.org/ - true + + jar-with-dependencies + - - - - - - sonar - - - - - org.sonarsource.scanner.maven - sonar-maven-plugin - 3.6.0.1398 - - - - - - http://172.20.68.34:9000 - a9d71a45706333578fa9d518a0aa82d89ecbe3ce - sonar.selenium-core-java - src/main - src/test - java - . - UTF-8 - - - + + + + + org.apache.maven.plugins + maven-source-plugin + + + attach-sources + + jar + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.6 + + + sign-artifacts + verify + + sign + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.8 + true + + ossrh + https://oss.sonatype.org/ + true + + + + diff --git a/src/main/java/aquality/selenium/core/utilities/ActionRetrier.java b/src/main/java/aquality/selenium/core/utilities/ActionRetrier.java index 16d8415..0a50450 100644 --- a/src/main/java/aquality/selenium/core/utilities/ActionRetrier.java +++ b/src/main/java/aquality/selenium/core/utilities/ActionRetrier.java @@ -4,7 +4,6 @@ import com.google.inject.Inject; import java.util.Collection; -import java.util.Optional; import java.util.function.Supplier; public class ActionRetrier implements IActionRetrier { @@ -28,10 +27,10 @@ public void doWithRetry(Runnable runnable, Collection @Override public T doWithRetry(Supplier function, Collection> handledExceptions) { int retryAttemptsLeft = retryConfiguration.getNumber(); - Optional result = Optional.empty(); + T result = null; while (retryAttemptsLeft >= 0) { try { - result = Optional.of(function.get()); + result = function.get(); break; } catch (Exception exception) { if (isExceptionHandled(handledExceptions, exception) && retryAttemptsLeft != 0) { @@ -46,7 +45,7 @@ public T doWithRetry(Supplier function, Collection> handledExceptions, Exception exception) { diff --git a/src/test/java/tests/utilities/ActionRetrierTests.java b/src/test/java/tests/utilities/ActionRetrierTests.java index 5331a1e..e854f00 100644 --- a/src/test/java/tests/utilities/ActionRetrierTests.java +++ b/src/test/java/tests/utilities/ActionRetrierTests.java @@ -17,9 +17,14 @@ public class ActionRetrierTests extends RetrierTest { private static final Collection> handledExceptions = Collections.singleton(IllegalStateException.class); private static final ActionRetrier ACTION_RETRIER = new ActionRetrier(RETRY_CONFIGURATION); + @Test + public void testRetrierShouldWorkWhenSupplierReturnsNull() { + Assert.assertNull(ACTION_RETRIER.doWithRetry(() -> null, Collections.emptyList())); + } + @Test public void testRetrierShouldWorkOnceIfMethodSucceeded() { - checkRetrierShouldWorkOnceIfMethodSucceeded(() -> ACTION_RETRIER.doWithRetry(() -> "", Collections.emptyList())); + checkRetrierShouldWorkOnceIfMethodSucceeded(() -> ACTION_RETRIER.doWithRetry(() -> System.out.println(""), Collections.emptyList())); } @Test diff --git a/src/test/java/tests/utilities/ElementActionRetrierTests.java b/src/test/java/tests/utilities/ElementActionRetrierTests.java index 92eccb7..0e4de9e 100644 --- a/src/test/java/tests/utilities/ElementActionRetrierTests.java +++ b/src/test/java/tests/utilities/ElementActionRetrierTests.java @@ -8,6 +8,7 @@ import org.testng.annotations.DataProvider; import org.testng.annotations.Test; +import java.util.Collections; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; @@ -25,9 +26,14 @@ private Object[][] handledExceptions() { }; } + @Test + public void testElementRetrierShouldWorkWhenSupplierReturnsNull() { + Assert.assertNull(ELEMENT_ACTION_RETRIER.doWithRetry(() -> null, Collections.emptyList())); + } + @Test public void testElementRetrierShouldWorkOnceIfMethodSucceeded() { - checkRetrierShouldWorkOnceIfMethodSucceeded(() -> ELEMENT_ACTION_RETRIER.doWithRetry(() -> "")); + checkRetrierShouldWorkOnceIfMethodSucceeded(() -> ELEMENT_ACTION_RETRIER.doWithRetry(() -> System.out.println(""))); } @Test