From 630cb41d75aab3098a16a8e0a7a183b858f0112e Mon Sep 17 00:00:00 2001 From: Mikolaj Manski Date: Fri, 31 Mar 2017 15:45:37 +0200 Subject: [PATCH 1/7] sonar fixes --- .../qa/bb/aem/content/ContentInstaller.java | 8 ++- .../qa/bb/aem/content/WcmCommandHandler.java | 26 ++++---- .../componentconfigs/ComponentConfigs.java | 6 +- .../ComponentConfiguration.java | 6 +- .../touch/pageobjects/pages/AuthorPage.java | 4 +- .../touch/pageobjects/pages/PublishPage.java | 6 +- .../aem/touch/pageobjects/touchui/Parsys.java | 2 +- .../touch/siteadmin/aem61/SiteadminPage.java | 60 ++++++++----------- .../aem61/calendar/YearMonthPicker.java | 2 +- .../siteadmin/aem61/list/ChildPageWindow.java | 6 +- .../siteadmin/aem62/ChildPageWindow.java | 2 +- .../aem62/PageActivationStatusImpl.java | 2 +- .../touch/siteadmin/aem62/SiteadminPage.java | 22 ++----- .../aem62/calendar/YearMonthPicker.java | 2 +- .../qa/bb/aem/touch/util/Conditions.java | 7 +++ .../qa/bb/aem/touch/util/YamlReader.java | 2 +- .../bb/processors/PageObjectTreeScanner.java | 2 +- .../PageObjectInvocationTracker.java | 3 +- .../hierarchy/WebElementInterceptor.java | 3 +- .../util/LoadableComponentsUtil.java | 2 +- .../field/PageObjectListProxyProvider.java | 3 +- .../field/PageObjectProviderHelper.java | 11 ++-- .../PageObjectSelectorListProxyProvider.java | 4 +- .../field/ScopedPageObjectProvider.java | 3 +- .../qa/bb/provider/selenium/BobcatWait.java | 1 + .../qa/bb/qualifier/FindPageObject.java | 3 +- .../NestedSelectorScopedElementLocator.java | 3 +- .../SelectorScopedElementLocator.java | 3 +- .../qa/bb/utils/AnnotationsHelper.java | 8 +-- .../com/cognifide/qa/bb/utils/AopUtil.java | 6 +- .../cognifide/qa/bb/utils/PropertyUtils.java | 4 +- .../java/com/cognifide/qa/bb/ConfigKeys.java | 2 +- .../qa/bb/cumber/BobcumberListener.java | 9 ++- .../qa/bb/cumber/StatisticsHelper.java | 5 +- .../bb/junit/concurrent/ReportingHandler.java | 1 + .../bb/logging/BrowserLogEntryCollector.java | 7 ++- .../qa/bb/logging/TestEventCollectorImpl.java | 3 +- .../bb/proxy/analyzer/AnalyzerCallable.java | 6 +- .../bb/proxy/analyzer/DispatchingFuture.java | 6 +- .../qa/bb/proxy/record/AnalyticsWait.java | 1 + .../bb/proxy/record/TrafficLogContains.java | 4 +- 41 files changed, 129 insertions(+), 137 deletions(-) diff --git a/bb-aem-common/src/main/java/com/cognifide/qa/bb/aem/content/ContentInstaller.java b/bb-aem-common/src/main/java/com/cognifide/qa/bb/aem/content/ContentInstaller.java index 47b1fff3..b2e68031 100644 --- a/bb-aem-common/src/main/java/com/cognifide/qa/bb/aem/content/ContentInstaller.java +++ b/bb-aem-common/src/main/java/com/cognifide/qa/bb/aem/content/ContentInstaller.java @@ -70,10 +70,14 @@ public void installAemPackage(String packageName) throws IOException { * @param packageName Name of the package to be activated. * @throws IOException Thrown when AEM instance returns NOK response. */ - public void activateAemPackage(String packageName) throws IOException { + public void activateAemPackage(String packageName) throws IOException, IllegalArgumentException { HttpPost upload = builder.createUploadRequest(); MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create(); - entityBuilder.addBinaryBody("package", new File(CONTENT_PATH, packageName), + File file = new File(CONTENT_PATH, packageName); + if(!file.exists()) { + throw new IllegalArgumentException("The provided package doesn't exist: " + file.getPath()); + } + entityBuilder.addBinaryBody("package", file, ContentType.DEFAULT_BINARY, packageName); entityBuilder.addTextBody("force", "true"); upload.setEntity(entityBuilder.build()); diff --git a/bb-aem-common/src/main/java/com/cognifide/qa/bb/aem/content/WcmCommandHandler.java b/bb-aem-common/src/main/java/com/cognifide/qa/bb/aem/content/WcmCommandHandler.java index fe252f9b..21e32bdd 100644 --- a/bb-aem-common/src/main/java/com/cognifide/qa/bb/aem/content/WcmCommandHandler.java +++ b/bb-aem-common/src/main/java/com/cognifide/qa/bb/aem/content/WcmCommandHandler.java @@ -84,9 +84,9 @@ public class WcmCommandHandler { */ public void activatePage(String assetPath) throws IOException { triggerAction(Maps.newHashMap(new ImmutableMap.Builder() - .put(PATH_PROPERTY, assetPath) - .put(CMD_PROPERTY, ACTIVATE) - .put(CHARSET_PROPERTY, UTF_8).build()), REPLICATE_URL, + .put(PATH_PROPERTY, assetPath) + .put(CMD_PROPERTY, ACTIVATE) + .put(CHARSET_PROPERTY, UTF_8).build()), REPLICATE_URL, REPLICATION_STARTED_MESSAGE + assetPath); } @@ -98,9 +98,9 @@ public void activatePage(String assetPath) throws IOException { */ public void deactivatePage(String assetPath) throws IOException { triggerAction(Maps.newHashMap(new ImmutableMap.Builder() - .put(PATH_PROPERTY, assetPath) - .put(CMD_PROPERTY, DEACTIVATE) - .put(CHARSET_PROPERTY, UTF_8).build()), REPLICATE_URL, + .put(PATH_PROPERTY, assetPath) + .put(CMD_PROPERTY, DEACTIVATE) + .put(CHARSET_PROPERTY, UTF_8).build()), REPLICATE_URL, REPLICATION_STARTED_MESSAGE + assetPath); } @@ -129,9 +129,9 @@ public void createPage(String parentPath, String title, String template) throws */ public void deletePage(String path) throws IOException { triggerAction(Maps.newHashMap(new ImmutableMap.Builder() - .put(CMD_PROPERTY, DELETE_PAGE_COMMAND) - .put(CHARSET_PROPERTY, UTF_8) - .put(PATH_PROPERTY, path.toLowerCase()).build()), WCM_COMMAND_URL, + .put(CMD_PROPERTY, DELETE_PAGE_COMMAND) + .put(CHARSET_PROPERTY, UTF_8) + .put(PATH_PROPERTY, path.toLowerCase()).build()), WCM_COMMAND_URL, String.format(PAGE_DELETED_SUCCESS_MESSAGE_FORMAT, path.toLowerCase())); } @@ -140,7 +140,7 @@ public void deletePage(String path) throws IOException { * * @param postProperties properties map to send * @param successMessage expected success message - * @param commandUrl command + * @param commandUrl command * @throws IOException if response doesn't contain desired message */ public void triggerAction(Map postProperties, String commandUrl, @@ -149,9 +149,9 @@ public void triggerAction(Map postProperties, String commandUrl, HttpPost request = new HttpPost(String.format(commandUrl, authorIp)); List params = new ArrayList<>(); postProperties.entrySet().stream(). - forEach((property) -> { - params.add(new BasicNameValuePair(property.getKey(), property.getValue())); - }); + forEach((property) -> + params.add(new BasicNameValuePair(property.getKey(), property.getValue())) + ); request.setEntity(new UrlEncodedFormEntity(params, Consts.UTF_8)); sender.sendCrxRequest(request, successMessage); } diff --git a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/data/componentconfigs/ComponentConfigs.java b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/data/componentconfigs/ComponentConfigs.java index f93dafe4..a36a5963 100644 --- a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/data/componentconfigs/ComponentConfigs.java +++ b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/data/componentconfigs/ComponentConfigs.java @@ -52,9 +52,9 @@ public Map getConfigs(String component) { configsData.keySet().stream().forEach((configName) -> { Map> data = configsData.get(configName); List tabsConfig = new ArrayList<>(); - data.entrySet().stream().forEach((entry) -> { - tabsConfig.add(new TabConfig(entry.getKey(), entry.getValue())); - }); + data.entrySet().stream().forEach((entry) -> + tabsConfig.add(new TabConfig(entry.getKey(), entry.getValue())) + ); result.put(configName, new ComponentConfiguration(tabsConfig)); }); diff --git a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/data/componentconfigs/ComponentConfiguration.java b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/data/componentconfigs/ComponentConfiguration.java index 0632a728..93bccc3b 100644 --- a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/data/componentconfigs/ComponentConfiguration.java +++ b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/data/componentconfigs/ComponentConfiguration.java @@ -49,11 +49,10 @@ public List getConfigurationForTab(String tab) { * Returns first {@link FieldConfig} with provided label * * @param tabName Tab name in the dialog window - * @param configurationKey key of yaml component configuration * @param label field label * @return */ - public FieldConfig getFieldConfigByLabel(String tabName, String configurationKey, String label) { + public FieldConfig getFieldConfigByLabel(String tabName, String label) { return getConfigurationForTab(tabName).stream() .filter(t -> StringUtils.equals(t.getLabel(), label)) .findFirst() @@ -63,11 +62,10 @@ public FieldConfig getFieldConfigByLabel(String tabName, String configurationKey /** * * @param tabName Tab name in the dialog window - * @param configurationKey onfigurationKey key of yaml configuration * @param type field type provided in yaml component configuration * @return */ - public List getFieldConfigsByType(String tabName, String configurationKey, String type) { + public List getFieldConfigsByType(String tabName, String type) { return getConfigurationForTab(tabName).stream() .filter(t -> StringUtils.equals(t.getType(), type)) .collect(Collectors.toList()); diff --git a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/pageobjects/pages/AuthorPage.java b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/pageobjects/pages/AuthorPage.java index 9fc5810a..6de0046b 100644 --- a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/pageobjects/pages/AuthorPage.java +++ b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/pageobjects/pages/AuthorPage.java @@ -229,12 +229,10 @@ private void verifyParsysRerendered(String parsys) { } private void retryLoad() { - conditions.verify(new ExpectedCondition() { - @Nullable @Override public Object apply(WebDriver driver) { + conditions.verify(ignored -> { LOG.debug("Retrying page open"); driver.navigate().refresh(); return isLoadedCondition(); - } }, Timeouts.MEDIUM); } diff --git a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/pageobjects/pages/PublishPage.java b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/pageobjects/pages/PublishPage.java index 0b979261..f5f7df77 100644 --- a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/pageobjects/pages/PublishPage.java +++ b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/pageobjects/pages/PublishPage.java @@ -103,11 +103,11 @@ public T fromPage(Class component) { scope = webDriver.findElement(By.cssSelector(selector)); } catch (IllegalAccessException e) { LOG.info( - "CSS not accessible, page object injected with default scope: {}", component.getName()); + "CSS not accessible, page object injected with default scope: {} Exception: {}", component.getName(), e); } catch (NoSuchFieldException e) { LOG.info( - "CSS field not present in the page object, page object injected with default scope: {}", - component.getName()); + "CSS field not present in the page object, page object injected with default scope: {} Exception: {}", + component.getName(), e); } return scope == null ? pageObjectInjector.inject(component) : diff --git a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/pageobjects/touchui/Parsys.java b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/pageobjects/touchui/Parsys.java index 060b8b0c..6895dbcf 100644 --- a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/pageobjects/touchui/Parsys.java +++ b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/pageobjects/touchui/Parsys.java @@ -219,7 +219,7 @@ private void tryToOpenInsertWindow() { try { boolean isInsertButtonPresent = driver .findElements(By.cssSelector(INSERT_BUTTON_SELECTOR)) - .size() > 0; + .isEmpty(); if(!isInsertButtonPresent) { // AEM 6.1 actions.doubleClick(dropArea).perform(); diff --git a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem61/SiteadminPage.java b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem61/SiteadminPage.java index 840c37ec..daba4e36 100644 --- a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem61/SiteadminPage.java +++ b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem61/SiteadminPage.java @@ -1,17 +1,15 @@ /* * Copyright 2016 Cognifide Ltd.. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ package com.cognifide.qa.bb.aem.touch.siteadmin.aem61; @@ -76,7 +74,8 @@ public class SiteadminPage implements Loadable, SiteadminActions { @LoadableComponent(condClass = IsLoadedCondition.class) private ChildPageWindow childPageWindow; - @FindBy(css = "nav.foundation-layout-mode2-item.endor-ActionBar.js-granite-endor-ActionBar > div.endor-ActionBar-left") + @FindBy( + css = "nav.foundation-layout-mode2-item.endor-ActionBar.js-granite-endor-ActionBar > div.endor-ActionBar-left") private SiteadminToolbar toolbar; @Override @@ -120,14 +119,12 @@ public SiteadminActions copyPage(String title, String destination) { @Override public SiteadminActions waitForPageCount(int pageCount) { - boolean conditionNotMet = !webElementUtils.isConditionMet(new ExpectedCondition() { - @Nullable @Override public Object apply(@Nullable WebDriver webDriver) { - try { - return (pageCount == getChildPageWindow().getPageCount()); - } catch (StaleElementReferenceException e) { - webDriver.navigate().refresh(); - return false; - } + boolean conditionNotMet = !webElementUtils.isConditionMet(webDriver -> { + try { + return (pageCount == getChildPageWindow().getPageCount()); + } catch (StaleElementReferenceException e) { + webDriver.navigate().refresh(); + return false; } }, Timeouts.SMALL); if (conditionNotMet) { @@ -231,23 +228,18 @@ private String getSiteAdminUrl() { } private void waitForExpectedStatus(final String title, ActivationStatus status) { - wait.withTimeout(Timeouts.MEDIUM).until(new ExpectedCondition() { - @Nullable @Override public Boolean apply(@Nullable WebDriver webDriver) { - webDriver.navigate().refresh(); - ChildPageRow childPage = getChildPageWindow().getChildPageRow(title); - PageActivationStatus pageActivationStatusCell = childPage.getPageActivationStatus(); - ActivationStatus activationStatus = pageActivationStatusCell.getActivationStatus(); - return activationStatus.equals(status); - } + wait.withTimeout(Timeouts.MEDIUM).until(webDriver -> { + webDriver.navigate().refresh(); + ChildPageRow childPage = getChildPageWindow().getChildPageRow(title); + PageActivationStatus pageActivationStatusCell = childPage.getPageActivationStatus(); + ActivationStatus activationStatus = pageActivationStatusCell.getActivationStatus(); + return activationStatus.equals(status); }, Timeouts.SMALL); } private void waitForPageToAppearOnTheList(final String title) { - wait.withTimeout(Timeouts.MEDIUM).until(new ExpectedCondition() { - @Nullable @Override public Boolean apply(@Nullable WebDriver webDriver) { - return getChildPageWindow().containsPage(title); - } - }, Timeouts.SMALL); + wait.withTimeout(Timeouts.MEDIUM).until(webDriver -> getChildPageWindow().containsPage(title), + Timeouts.SMALL); } private ChildPageWindow getChildPageWindow() { @@ -257,15 +249,11 @@ private ChildPageWindow getChildPageWindow() { } private void retryLoad() { - conditions.verify(new ExpectedCondition() { - @Nullable - @Override - public Object apply(WebDriver driver) { + conditions.verify(driver -> { if (!isLoadedCondition()) { driver.navigate().refresh(); } return isLoadedCondition(); - } }, Timeouts.MEDIUM); } diff --git a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem61/calendar/YearMonthPicker.java b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem61/calendar/YearMonthPicker.java index de967548..f118c502 100644 --- a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem61/calendar/YearMonthPicker.java +++ b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem61/calendar/YearMonthPicker.java @@ -42,7 +42,7 @@ public void selectDate(int year, Month month) { private boolean isDesiredDateSelected(int year, Month month) { String[] headerParts = yearMonthHeader.getText().toUpperCase().split(" "); Month selectedMonth = Month.valueOf(headerParts[0]); - int selectedYear = Integer.valueOf(headerParts[1].toUpperCase()); + int selectedYear = Integer.parseInt(headerParts[1].toUpperCase()); return year == selectedYear && selectedMonth.equals(month); } } diff --git a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem61/list/ChildPageWindow.java b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem61/list/ChildPageWindow.java index 514ba0cc..dbd20efb 100644 --- a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem61/list/ChildPageWindow.java +++ b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem61/list/ChildPageWindow.java @@ -68,16 +68,14 @@ public boolean isLoaded() { } public boolean containsPage(String title) { - return webElementUtils.isConditionMet(new ExpectedCondition() { - @Nullable @Override public Object apply(@Nullable WebDriver weDriver) { + return webElementUtils.isConditionMet(webDriver -> { try { return childPages.stream().filter(t -> t.getTitle().equals(title)).findFirst() .isPresent(); } catch (StaleElementReferenceException e) { - weDriver.navigate().refresh(); + webDriver.navigate().refresh(); return false; } - } }, Timeouts.SMALL); } diff --git a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem62/ChildPageWindow.java b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem62/ChildPageWindow.java index 5cfcba21..c8eed5b4 100644 --- a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem62/ChildPageWindow.java +++ b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem62/ChildPageWindow.java @@ -51,7 +51,7 @@ public boolean isLoaded() { } public boolean containsPage(String title) { - return childPageRows.size() > 0 && childPageRows.stream() + return !childPageRows.isEmpty() && childPageRows.stream() .filter(t -> t.getTitle().equals(title)).findFirst().isPresent(); } diff --git a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem62/PageActivationStatusImpl.java b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem62/PageActivationStatusImpl.java index c0e3b5eb..5798fd36 100644 --- a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem62/PageActivationStatusImpl.java +++ b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem62/PageActivationStatusImpl.java @@ -55,7 +55,7 @@ public ActivationStatus getActivationStatus() { if (displayed) { return ActivationStatus.SCHEDULED; } - if (currentScope.getAttribute("value").equals("0")) { + if ("0".equals(currentScope.getAttribute("value"))) { return ActivationStatus.NOT_PUBLISHED; } return ActivationStatus.PUBLISHED; diff --git a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem62/SiteadminPage.java b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem62/SiteadminPage.java index d346cece..f12e2c09 100644 --- a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem62/SiteadminPage.java +++ b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem62/SiteadminPage.java @@ -226,16 +226,12 @@ public boolean isLoaded() { @Override public SiteadminActions waitForPageCount(int pageCount) { - boolean conditionNotMet = !webElementUtils.isConditionMet(new ExpectedCondition() { - @Nullable - @Override - public Object apply(@Nullable WebDriver webDriver) { + boolean conditionNotMet = !webElementUtils.isConditionMet(webDriver -> { try { - return (pageCount == getChildPageWindow().getPageCount()); + return pageCount == getChildPageWindow().getPageCount(); } catch (StaleElementReferenceException e) { webDriver.navigate().refresh(); return false; - } } }, Timeouts.SMALL); if (conditionNotMet) { @@ -245,16 +241,12 @@ public Object apply(@Nullable WebDriver webDriver) { } private void waitForExpectedStatus(final String title, ActivationStatus status) { - wait.withTimeout(Timeouts.MEDIUM).until(new ExpectedCondition() { - @Nullable - @Override - public Boolean apply(@Nullable WebDriver webDriver) { + wait.withTimeout(Timeouts.MEDIUM).until(webDriver -> { webDriver.navigate().refresh(); ChildPageRow childPageRow = getChildPageWindow().getChildPageRow(title); PageActivationStatus pageActivationStatusCell = childPageRow.getPageActivationStatus(); ActivationStatus activationStatus = pageActivationStatusCell.getActivationStatus(); return activationStatus.equals(status); - } }, Timeouts.MINIMAL); } @@ -264,13 +256,9 @@ private ChildPageWindow getChildPageWindow() { } private void retryLoad() { - conditions.verify(new ExpectedCondition() { - @Nullable - @Override - public Object apply(WebDriver driver) { + conditions.verify(driver -> { driver.navigate().refresh(); return isLoadedCondition(); - } }, Timeouts.MEDIUM); } @@ -288,7 +276,7 @@ private void navigateInteractively(String destination) { goForwardToDestination(currentUrl, destination); } wait.withTimeout(Timeouts.SMALL).until((ExpectedCondition) input -> - ((JavascriptExecutor) driver).executeScript("return $.active").toString().equals("0") + "0".equals(((JavascriptExecutor) driver).executeScript("return $.active").toString()) ); navigateInteractively(destination); } diff --git a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem62/calendar/YearMonthPicker.java b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem62/calendar/YearMonthPicker.java index ad46b473..1eb96c7d 100644 --- a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem62/calendar/YearMonthPicker.java +++ b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem62/calendar/YearMonthPicker.java @@ -40,7 +40,7 @@ public void selectDate(int year, Month month) { private boolean isDesiredDateSelected(int year, Month month) { String[] headerParts = yearMonthHeader.getText().toUpperCase().split(" "); Month selectedMonth = Month.valueOf(headerParts[0]); - int selectedYear = Integer.valueOf(headerParts[1].toUpperCase()); + int selectedYear = Integer.parseInt(headerParts[1].toUpperCase()); return year == selectedYear && selectedMonth.equals(month); } diff --git a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/util/Conditions.java b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/util/Conditions.java index e29718ab..73ff5eca 100644 --- a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/util/Conditions.java +++ b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/util/Conditions.java @@ -29,12 +29,16 @@ import com.cognifide.qa.bb.constants.Timeouts; import com.cognifide.qa.bb.aem.touch.pageobjects.touchui.AuthorLoader; import com.google.inject.Inject; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Class contains conditions for web components. */ public class Conditions { + private static final Logger LOG = LoggerFactory.getLogger(Conditions.class); + @Inject private BobcatWait bobcatWait; @@ -121,6 +125,7 @@ public Object optionalWait(ExpectedCondition condition) { try { return bobcatWait.withTimeout(Timeouts.SMALL).until(condition); } catch (TimeoutException ignored) { + LOG.warn("Condition failed, returing null: {}", ignored); return null; } } @@ -137,6 +142,7 @@ public WebElement elementReady(WebElement element) { try { return element.isDisplayed() ? element : null; } catch (StaleElementReferenceException e) { + LOG.warn("Condition failed, returning null: {}", e); return null; } }); @@ -155,6 +161,7 @@ public T staleSafe(WebElement element, WebElementCallable elementCallable try { return elementCallable.call(element); } catch (StaleElementReferenceException e) { + LOG.warn("Condition failed, returing null: {}", e); return null; } }, Timeouts.MEDIUM); diff --git a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/util/YamlReader.java b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/util/YamlReader.java index 2a640be5..c1a17d3c 100644 --- a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/util/YamlReader.java +++ b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/util/YamlReader.java @@ -59,7 +59,7 @@ public static T read(String path, TypeReference typeReference) { File file = Paths.get(uri).toFile(); return mapper.readValue(file, typeReference); } catch (IOException | URISyntaxException e) { - LOG.error("Could not read YAML file: {}", path); + LOG.error("Could not read YAML file: {} {}", path, e); throw new IllegalStateException("YAML file could not be read"); } } diff --git a/bb-annotations/src/main/java/com/cognifide/qa/bb/processors/PageObjectTreeScanner.java b/bb-annotations/src/main/java/com/cognifide/qa/bb/processors/PageObjectTreeScanner.java index e3aa6a92..83b124aa 100644 --- a/bb-annotations/src/main/java/com/cognifide/qa/bb/processors/PageObjectTreeScanner.java +++ b/bb-annotations/src/main/java/com/cognifide/qa/bb/processors/PageObjectTreeScanner.java @@ -109,7 +109,7 @@ private boolean containsField(JCTree.JCClassDecl classDef, Name name) { return classDef.defs.stream() .filter(t -> t instanceof JCVariableDecl) .map((elem) -> (JCVariableDecl) elem) - .anyMatch((var) -> (var.getName().equals(name))); + .anyMatch((var) -> var.getName().equals(name)); } } diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/PageObjectInvocationTracker.java b/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/PageObjectInvocationTracker.java index 729e02f1..e7049e0d 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/PageObjectInvocationTracker.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/PageObjectInvocationTracker.java @@ -16,6 +16,7 @@ package com.cognifide.qa.bb.loadable.hierarchy; import java.util.LinkedList; +import java.util.List; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -28,7 +29,7 @@ public class PageObjectInvocationTracker { private final Supplier> supplier = () -> new LinkedList<>(); - public LinkedList getSubjectStack() { + public List getSubjectStack() { return subjectStack.stream().map(element -> element.getSubject()).collect(Collectors. toCollection(supplier)); } diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/WebElementInterceptor.java b/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/WebElementInterceptor.java index 222565fe..03cb3a41 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/WebElementInterceptor.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/WebElementInterceptor.java @@ -24,6 +24,7 @@ import com.google.inject.Inject; import java.util.Collections; +import java.util.LinkedList; import java.util.List; import org.aopalliance.intercept.MethodInterceptor; @@ -67,7 +68,7 @@ public Object invoke(MethodInvocation methodInvocation) throws Throwable { ClassFieldContext directContext = acquireDirectContext(caller); ConditionStack loadableContextHierarchy = loadableCondsExplorer. - discoverLoadableContextHierarchy(directContext, pageObjectInvocationTracker. + discoverLoadableContextHierarchy(directContext, (LinkedList) pageObjectInvocationTracker. getSubjectStack()); loadConditionChainRunner.chainCheck(loadableContextHierarchy); diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/util/LoadableComponentsUtil.java b/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/util/LoadableComponentsUtil.java index 58b1197d..911b8b00 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/util/LoadableComponentsUtil.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/util/LoadableComponentsUtil.java @@ -22,7 +22,7 @@ import java.util.ArrayList; import java.util.List; -public class LoadableComponentsUtil { +public final class LoadableComponentsUtil { private LoadableComponentsUtil() { // util class diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/mapper/field/PageObjectListProxyProvider.java b/bb-core/src/main/java/com/cognifide/qa/bb/mapper/field/PageObjectListProxyProvider.java index c308a931..883b4d52 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/mapper/field/PageObjectListProxyProvider.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/mapper/field/PageObjectListProxyProvider.java @@ -1,5 +1,3 @@ -package com.cognifide.qa.bb.mapper.field; - /*- * #%L * Bobcat @@ -19,6 +17,7 @@ * limitations under the License. * #L% */ +package com.cognifide.qa.bb.mapper.field; import java.lang.reflect.Field; import java.lang.reflect.Proxy; diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/mapper/field/PageObjectProviderHelper.java b/bb-core/src/main/java/com/cognifide/qa/bb/mapper/field/PageObjectProviderHelper.java index fb929248..aca26ea9 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/mapper/field/PageObjectProviderHelper.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/mapper/field/PageObjectProviderHelper.java @@ -1,5 +1,3 @@ -package com.cognifide.qa.bb.mapper.field; - /*- * #%L * Bobcat Parent @@ -19,6 +17,7 @@ * limitations under the License. * #L% */ +package com.cognifide.qa.bb.mapper.field; import java.lang.reflect.Field; import java.lang.reflect.ParameterizedType; @@ -33,7 +32,7 @@ /** * Helper class for Page Objects */ -public class PageObjectProviderHelper { +public final class PageObjectProviderHelper { private PageObjectProviderHelper() { // Empty for helper class @@ -41,7 +40,7 @@ private PageObjectProviderHelper() { /** * Gets selector from {@link PageObject} if class annoted by this annotation is used in list - * + * * @param field class field * @return selector */ @@ -51,7 +50,7 @@ public static By getSelectorFromGenericPageObject(Field field) { /** * Gets selector from {@link PageObject} - * + * * @param field class field * @return selector */ @@ -61,7 +60,7 @@ public static By getSelectorFromPageObject(Field field) { /** * Gets generic type from field (if field type is {@link ParameterizedType}) - * + * * @param field class field * @return generic type */ diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/mapper/field/PageObjectSelectorListProxyProvider.java b/bb-core/src/main/java/com/cognifide/qa/bb/mapper/field/PageObjectSelectorListProxyProvider.java index c96603c4..abbdae13 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/mapper/field/PageObjectSelectorListProxyProvider.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/mapper/field/PageObjectSelectorListProxyProvider.java @@ -1,5 +1,3 @@ -package com.cognifide.qa.bb.mapper.field; - /*- * #%L * Bobcat Parent @@ -19,6 +17,8 @@ * limitations under the License. * #L% */ +package com.cognifide.qa.bb.mapper.field; + import java.lang.reflect.Field; import java.lang.reflect.Proxy; import java.util.List; diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/mapper/field/ScopedPageObjectProvider.java b/bb-core/src/main/java/com/cognifide/qa/bb/mapper/field/ScopedPageObjectProvider.java index ab860479..c2d809ad 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/mapper/field/ScopedPageObjectProvider.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/mapper/field/ScopedPageObjectProvider.java @@ -1,5 +1,3 @@ -package com.cognifide.qa.bb.mapper.field; - /*- * #%L * Bobcat @@ -19,6 +17,7 @@ * limitations under the License. * #L% */ +package com.cognifide.qa.bb.mapper.field; import java.lang.reflect.Field; import java.util.Optional; diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/provider/selenium/BobcatWait.java b/bb-core/src/main/java/com/cognifide/qa/bb/provider/selenium/BobcatWait.java index 85b93195..bbab730f 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/provider/selenium/BobcatWait.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/provider/selenium/BobcatWait.java @@ -69,6 +69,7 @@ public static void sleep(double durationInSec) { TimeUnit.MILLISECONDS.sleep((long) (durationInSec * 1000)); } catch (InterruptedException e) { LOG.error("Sleep was interrupted", e); + Thread.currentThread().interrupt(); } } diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/qualifier/FindPageObject.java b/bb-core/src/main/java/com/cognifide/qa/bb/qualifier/FindPageObject.java index 33f5dda3..ba5d28cc 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/qualifier/FindPageObject.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/qualifier/FindPageObject.java @@ -1,5 +1,3 @@ -package com.cognifide.qa.bb.qualifier; - /*- * #%L * Bobcat Parent @@ -19,6 +17,7 @@ * limitations under the License. * #L% */ +package com.cognifide.qa.bb.qualifier; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/scope/nestedselector/NestedSelectorScopedElementLocator.java b/bb-core/src/main/java/com/cognifide/qa/bb/scope/nestedselector/NestedSelectorScopedElementLocator.java index 8b430c45..25570201 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/scope/nestedselector/NestedSelectorScopedElementLocator.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/scope/nestedselector/NestedSelectorScopedElementLocator.java @@ -1,5 +1,3 @@ -package com.cognifide.qa.bb.scope.nestedselector; - /*- * #%L * Bobcat Parent @@ -19,6 +17,7 @@ * limitations under the License. * #L% */ +package com.cognifide.qa.bb.scope.nestedselector; import static java.util.stream.Collectors.toList; diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/scope/selector/SelectorScopedElementLocator.java b/bb-core/src/main/java/com/cognifide/qa/bb/scope/selector/SelectorScopedElementLocator.java index 4c12767d..bfd72411 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/scope/selector/SelectorScopedElementLocator.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/scope/selector/SelectorScopedElementLocator.java @@ -1,5 +1,3 @@ -package com.cognifide.qa.bb.scope.selector; - /*- * #%L * Bobcat @@ -19,6 +17,7 @@ * limitations under the License. * #L% */ +package com.cognifide.qa.bb.scope.selector; import static java.util.stream.Collectors.toList; diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/utils/AnnotationsHelper.java b/bb-core/src/main/java/com/cognifide/qa/bb/utils/AnnotationsHelper.java index 280bfe52..5b541382 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/utils/AnnotationsHelper.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/utils/AnnotationsHelper.java @@ -35,7 +35,7 @@ /** * Helper class with methods for managing annotations. */ -public class AnnotationsHelper { +public final class AnnotationsHelper { private static final Class[] FIND_ANNOTATIONS = new Class[] {FindAll.class, FindBy.class, FindBys.class}; @@ -46,7 +46,7 @@ private AnnotationsHelper() { /** * Checks if field contains {@link FindPageObject} annotation - * + * * @param field field to check * @return if annotation is present */ @@ -56,7 +56,7 @@ public static boolean isFindPageObjectAnnotationPresent(Field field) { /** * Checks if field contains one of {@link FindAll} {@link FindBy} {@link FindBys} annotation - * + * * @param field field to check * @return if one pf annotations is present */ @@ -71,7 +71,7 @@ public static boolean isFindByAnnotationPresent(Field field) { /** * Checks if field contains {@link Global} annotation - * + * * @param field field to check * @return if annotation is present */ diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/utils/AopUtil.java b/bb-core/src/main/java/com/cognifide/qa/bb/utils/AopUtil.java index 44764b21..5171c3fe 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/utils/AopUtil.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/utils/AopUtil.java @@ -15,7 +15,11 @@ */ package com.cognifide.qa.bb.utils; -public class AopUtil { +public final class AopUtil { + + private AopUtil() { + //util class + } /** * @param object object diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/utils/PropertyUtils.java b/bb-core/src/main/java/com/cognifide/qa/bb/utils/PropertyUtils.java index 89d71acc..77172399 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/utils/PropertyUtils.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/utils/PropertyUtils.java @@ -39,13 +39,13 @@ /** * This class contains utility methods for loading properties from classpath and system. */ -public class PropertyUtils { +public final class PropertyUtils { private static final Logger LOG = LoggerFactory.getLogger(PropertyUtils.class); private static final String[] PREFIXES = new String[] {"webdriver.", "phantomjs."}; - private static Properties properties = null; + private static volatile Properties properties = null; private PropertyUtils() { // util class... diff --git a/bb-cumber/src/main/java/com/cognifide/qa/bb/ConfigKeys.java b/bb-cumber/src/main/java/com/cognifide/qa/bb/ConfigKeys.java index 25bea3e7..656b0ba9 100644 --- a/bb-cumber/src/main/java/com/cognifide/qa/bb/ConfigKeys.java +++ b/bb-cumber/src/main/java/com/cognifide/qa/bb/ConfigKeys.java @@ -19,7 +19,7 @@ */ package com.cognifide.qa.bb; -public class ConfigKeys { +public final class ConfigKeys { private ConfigKeys() { //Config class... diff --git a/bb-cumber/src/main/java/com/cognifide/qa/bb/cumber/BobcumberListener.java b/bb-cumber/src/main/java/com/cognifide/qa/bb/cumber/BobcumberListener.java index a84a492b..93a1d020 100644 --- a/bb-cumber/src/main/java/com/cognifide/qa/bb/cumber/BobcumberListener.java +++ b/bb-cumber/src/main/java/com/cognifide/qa/bb/cumber/BobcumberListener.java @@ -20,9 +20,12 @@ package com.cognifide.qa.bb.cumber; import java.io.BufferedWriter; +import java.io.FileOutputStream; import java.io.FileWriter; import java.io.IOException; +import java.io.OutputStreamWriter; import java.io.PrintWriter; +import java.nio.charset.StandardCharsets; import java.util.concurrent.atomic.AtomicInteger; import org.apache.commons.lang3.CharEncoding; @@ -93,8 +96,10 @@ private String normalizeTrace(String trace) { } private synchronized void addScenario(String failedScenario) throws IOException { - try (PrintWriter out = new PrintWriter( - new BufferedWriter(new FileWriter(bobcumber.getFeatureFile(), false)))) { + try (PrintWriter out = + new PrintWriter( + new BufferedWriter(new OutputStreamWriter(new FileOutputStream( + bobcumber.getFeatureFile(), false), StandardCharsets.UTF_8)))) { featureMap.addFeature(failedScenario); featureMap.writeFeatures(out); } diff --git a/bb-cumber/src/main/java/com/cognifide/qa/bb/cumber/StatisticsHelper.java b/bb-cumber/src/main/java/com/cognifide/qa/bb/cumber/StatisticsHelper.java index f70a5e5f..c55190e8 100644 --- a/bb-cumber/src/main/java/com/cognifide/qa/bb/cumber/StatisticsHelper.java +++ b/bb-cumber/src/main/java/com/cognifide/qa/bb/cumber/StatisticsHelper.java @@ -21,6 +21,7 @@ import java.io.File; import java.io.FileNotFoundException; +import java.nio.charset.StandardCharsets; import java.util.Scanner; import org.slf4j.Logger; @@ -40,7 +41,7 @@ private int getNumberOfTests(File file) { private int getNumberOfTests(File file, int defaultValue) { int returnValue = defaultValue; try { - Scanner scanner = new Scanner(file); + Scanner scanner = new Scanner(file, StandardCharsets.UTF_8.name()); returnValue = nextInt(scanner); } catch (FileNotFoundException e) { LOG.warn(NO_STATISTICS_FILE_FOUND_MESSAGE); @@ -55,7 +56,7 @@ int getNumberOfFailedTests(File file) { int getNumberOfFailedTests(File file, int defaultValue) { int returnValue = defaultValue; try { - Scanner scanner = new Scanner(file); + Scanner scanner = new Scanner(file, StandardCharsets.UTF_8.name()); if (scanner.hasNext()) { scanner.nextLine(); returnValue = nextInt(scanner); diff --git a/bb-junit/src/main/java/com/cognifide/qa/bb/junit/concurrent/ReportingHandler.java b/bb-junit/src/main/java/com/cognifide/qa/bb/junit/concurrent/ReportingHandler.java index 7c601baf..21de8e1a 100644 --- a/bb-junit/src/main/java/com/cognifide/qa/bb/junit/concurrent/ReportingHandler.java +++ b/bb-junit/src/main/java/com/cognifide/qa/bb/junit/concurrent/ReportingHandler.java @@ -111,6 +111,7 @@ public void run() { TimeUnit.MILLISECONDS.sleep(DEFAULT_SLEEP_TIME); } catch (InterruptedException e) { LOG.error("Sleep was interrupted", e); + Thread.currentThread().interrupt(); } } } diff --git a/bb-reports/src/main/java/com/cognifide/qa/bb/logging/BrowserLogEntryCollector.java b/bb-reports/src/main/java/com/cognifide/qa/bb/logging/BrowserLogEntryCollector.java index e40e7480..18fd7fdc 100644 --- a/bb-reports/src/main/java/com/cognifide/qa/bb/logging/BrowserLogEntryCollector.java +++ b/bb-reports/src/main/java/com/cognifide/qa/bb/logging/BrowserLogEntryCollector.java @@ -47,9 +47,10 @@ public List getBrowserLogEntries() { webDriver.manage().logs().get(LogType.BROWSER) .filter(Level.SEVERE); browserEntries.stream(). - forEach((browserEntry) -> { - toReturn.add(new BrowserLogEntry(browserEntry.toString())); - }); + forEach((browserEntry) -> + toReturn.add(new BrowserLogEntry(browserEntry.toString())) + ); + return toReturn; } diff --git a/bb-reports/src/main/java/com/cognifide/qa/bb/logging/TestEventCollectorImpl.java b/bb-reports/src/main/java/com/cognifide/qa/bb/logging/TestEventCollectorImpl.java index 0d6be930..1a824920 100644 --- a/bb-reports/src/main/java/com/cognifide/qa/bb/logging/TestEventCollectorImpl.java +++ b/bb-reports/src/main/java/com/cognifide/qa/bb/logging/TestEventCollectorImpl.java @@ -130,6 +130,7 @@ public void fail(String errorMessage) { * * @param message info message */ + @Override public void info(String message) { currentTest.get().info(message); } @@ -278,7 +279,7 @@ public void softAssertion(String message) { public Date getStartingDate() { return (Date) startingDate.clone(); } - + @Override public void removeLastEntry() { testInfoEntries.remove(currentTest.get()); diff --git a/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/analyzer/AnalyzerCallable.java b/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/analyzer/AnalyzerCallable.java index 1846e3e6..2bc74a80 100644 --- a/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/analyzer/AnalyzerCallable.java +++ b/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/analyzer/AnalyzerCallable.java @@ -106,8 +106,8 @@ private void fireFoundEvent() { private void fireWaitingEvent() { proxyListeners.stream(). - forEach((listener) -> { - listener.waitingForRequest(requestPredicate, closestHarEntryElector); - }); + forEach((listener) -> + listener.waitingForRequest(requestPredicate, closestHarEntryElector) + ); } } diff --git a/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/analyzer/DispatchingFuture.java b/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/analyzer/DispatchingFuture.java index bfbd4fd6..aea4af6c 100644 --- a/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/analyzer/DispatchingFuture.java +++ b/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/analyzer/DispatchingFuture.java @@ -61,8 +61,8 @@ public Boolean get(long timeout, TimeUnit unit) throws InterruptedException, Exe private void dispatch() { proxyListeners.stream(). - forEach((listener) -> { - listener.dispatch(); - }); + forEach((listener) -> + listener.dispatch() + ); } } diff --git a/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/record/AnalyticsWait.java b/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/record/AnalyticsWait.java index e527c630..6ceaf1dd 100644 --- a/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/record/AnalyticsWait.java +++ b/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/record/AnalyticsWait.java @@ -67,6 +67,7 @@ public synchronized void waitForAnalyticsCall() { this.wait(timeout); } catch (InterruptedException e) { LOG.error("Sleep was interrupted", e); + Thread.currentThread().interrupt(); } } diff --git a/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/record/TrafficLogContains.java b/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/record/TrafficLogContains.java index 17c4775f..0c121caf 100644 --- a/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/record/TrafficLogContains.java +++ b/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/record/TrafficLogContains.java @@ -52,8 +52,8 @@ public void describeTo(Description description) { @Override protected boolean matchesSafely(TrafficLog item) { return item.getHars().stream(). - anyMatch((har) -> (har.getLog().getEntries().stream(). - anyMatch((entry) -> (harEntryMatchesPredicates(entry))))); + anyMatch((har) -> har.getLog().getEntries().stream(). + anyMatch((entry) -> harEntryMatchesPredicates(entry))); } private boolean harEntryMatchesPredicates(HarEntry entry) { From a87c763395acf0f44f4b3de2653b1b2e2222e7d4 Mon Sep 17 00:00:00 2001 From: Mikolaj Manski Date: Fri, 31 Mar 2017 17:27:30 +0200 Subject: [PATCH 2/7] sonar fixes --- .../touch/siteadmin/aem61/SiteadminPage.java | 12 ++--- .../touch/siteadmin/aem62/SiteadminPage.java | 8 +-- .../loadable/context/ClassFieldContext.java | 22 ++++---- .../hierarchy/ConditionChainRunner.java | 3 +- .../bb/loadable/hierarchy/ConditionStack.java | 11 ++-- .../hierarchy/ConditionsExplorer.java | 52 ++++++++++--------- .../tracker/ConditionProgressTracker.java | 5 +- .../NestedSelectorScopedLocatorFactory.java | 3 +- .../com/cognifide/qa/bb/cumber/Bobcumber.java | 4 +- .../cognifide/qa/bb/cumber/FeatureMap.java | 4 +- .../qa/bb/cumber/StatisticsHelper.java | 4 +- .../cognifide/qa/bb/logging/ProxyLogger.java | 6 +-- 12 files changed, 68 insertions(+), 66 deletions(-) diff --git a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem61/SiteadminPage.java b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem61/SiteadminPage.java index daba4e36..bb741468 100644 --- a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem61/SiteadminPage.java +++ b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem61/SiteadminPage.java @@ -121,7 +121,7 @@ public SiteadminActions copyPage(String title, String destination) { public SiteadminActions waitForPageCount(int pageCount) { boolean conditionNotMet = !webElementUtils.isConditionMet(webDriver -> { try { - return (pageCount == getChildPageWindow().getPageCount()); + return pageCount == getChildPageWindow().getPageCount(); } catch (StaleElementReferenceException e) { webDriver.navigate().refresh(); return false; @@ -249,11 +249,11 @@ private ChildPageWindow getChildPageWindow() { } private void retryLoad() { - conditions.verify(driver -> { - if (!isLoadedCondition()) { - driver.navigate().refresh(); - } - return isLoadedCondition(); + conditions.verify(webDriver -> { + if (!isLoadedCondition()) { + webDriver.navigate().refresh(); + } + return isLoadedCondition(); }, Timeouts.MEDIUM); } diff --git a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem62/SiteadminPage.java b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem62/SiteadminPage.java index f12e2c09..676024d9 100644 --- a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem62/SiteadminPage.java +++ b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem62/SiteadminPage.java @@ -251,13 +251,13 @@ private void waitForExpectedStatus(final String title, ActivationStatus status) } private ChildPageWindow getChildPageWindow() { - WebElement childPageWindow = driver.findElement(By.cssSelector(CHILD_PAGE_WINDOW_SELECTOR)); - return pageObjectInjector.inject(ChildPageWindow.class, childPageWindow); + WebElement chldPageWindow = driver.findElement(By.cssSelector(CHILD_PAGE_WINDOW_SELECTOR)); + return pageObjectInjector.inject(ChildPageWindow.class, chldPageWindow); } private void retryLoad() { - conditions.verify(driver -> { - driver.navigate().refresh(); + conditions.verify(webDriver -> { + webDriver.navigate().refresh(); return isLoadedCondition(); }, Timeouts.MEDIUM); } diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/loadable/context/ClassFieldContext.java b/bb-core/src/main/java/com/cognifide/qa/bb/loadable/context/ClassFieldContext.java index 954577d5..706762cc 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/loadable/context/ClassFieldContext.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/loadable/context/ClassFieldContext.java @@ -1,17 +1,15 @@ /* * Copyright 2016 Cognifide Ltd.. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ package com.cognifide.qa.bb.loadable.context; @@ -38,9 +36,9 @@ public ClassFieldContext(Object subject, List conditionData) { public List toLoadableContextList() { List result = new ArrayList<>(); conditionData.stream(). - forEach((loadableComponentData) -> { - result.add(new LoadableComponentContext(subject, subjectClass, loadableComponentData)); - }); + forEach((loadableComponentData) -> + result.add(new LoadableComponentContext(subject, subjectClass, loadableComponentData)) + ); return result; } diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/ConditionChainRunner.java b/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/ConditionChainRunner.java index 8d861754..d6905dea 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/ConditionChainRunner.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/ConditionChainRunner.java @@ -25,6 +25,7 @@ import com.google.inject.Injector; import com.google.inject.Singleton; +import java.util.Deque; import java.util.Stack; /** @@ -44,7 +45,7 @@ public class ConditionChainRunner { * @throws LoadableConditionException when some condition fails */ public void chainCheck(ConditionStack conditionStack) throws LoadableConditionException { - Stack stack = conditionStack.getLoadableContextStack(); + Deque stack = conditionStack.getLoadableContextStack(); ConditionProgressTracker progressTracker = new ConditionProgressTracker(stack); while (!stack.isEmpty()) { diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/ConditionStack.java b/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/ConditionStack.java index 613a9dd6..6599af2a 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/ConditionStack.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/ConditionStack.java @@ -17,18 +17,20 @@ import com.cognifide.qa.bb.loadable.context.LoadableComponentContext; +import java.util.ArrayDeque; +import java.util.Deque; import java.util.Stack; public class ConditionStack { - private final Stack stack; + private final Deque stack; /** * * @param stack Stack with {@link LoadableComponentContext}. Hierarchy of conditions should be taken into account when * building this stack. */ - public ConditionStack(Stack stack) { + public ConditionStack(Deque stack) { this.stack = stack; } @@ -36,8 +38,7 @@ public ConditionStack(Stack stack) { * * @return Stack with {@link LoadableComponentContext} */ - public Stack getLoadableContextStack() { - // please note that this is not Object#clone - return (Stack) stack.clone(); + public Deque getLoadableContextStack() { + return new ArrayDeque<>(stack); } } diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/ConditionsExplorer.java b/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/ConditionsExplorer.java index 6463856b..01acf742 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/ConditionsExplorer.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/ConditionsExplorer.java @@ -1,17 +1,15 @@ /* * Copyright 2016 Cognifide Ltd.. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ package com.cognifide.qa.bb.loadable.hierarchy; @@ -24,8 +22,10 @@ import com.google.inject.Singleton; import java.lang.reflect.Field; +import java.util.ArrayDeque; import java.util.Arrays; import java.util.Collections; +import java.util.Deque; import java.util.LinkedList; import java.util.List; import java.util.Objects; @@ -42,10 +42,8 @@ /** * This runs after a test class is initialized and explores the hierarchy of {@link PageObject} - * elements which - * is needed to control hierarchical evaluation of {@link PageObject} and {@link WebElement} - * fields annotated - * with {@link LoadableComponent} annotation. + * elements which is needed to control hierarchical evaluation of {@link PageObject} and + * {@link WebElement} fields annotated with {@link LoadableComponent} annotation. */ @Singleton public class ConditionsExplorer { @@ -56,8 +54,7 @@ public class ConditionsExplorer { /** * Discovers the hierarchy of Loadable Conditions form provided class up to the root class - * which is usually - * the test class which have run the test. + * which is usually the test class which have run the test. * * @param directClassFieldContext context of the class field that have called the * {@link WebElement} method. @@ -69,15 +66,19 @@ public class ConditionsExplorer { */ public ConditionStack discoverLoadableContextHierarchy(ClassFieldContext directClassFieldContext, LinkedList subjectStack) { - Stack stack = new Stack<>(); + Deque stack = new ArrayDeque<>(); if (directClassFieldContext != null) { - directClassFieldContext.toLoadableContextList().forEach(stack::add); + directClassFieldContext.toLoadableContextList().forEach(stack::addFirst); } while (!subjectStack.isEmpty()) { ConditionHierarchyNode node = findNode(treeRootNode, subjectStack.pollLast()); if (node != null) { - stack.addAll(node.getLoadableFieldContext().toLoadableContextList()); + for (LoadableComponentContext loadableComponentContext : node.getLoadableFieldContext() + .toLoadableContextList()) { + stack.addFirst(loadableComponentContext); + } + } } @@ -113,14 +114,15 @@ private void processLoadableContextForClass(Class clazz, ConditionHierarchyNode LOG.error(ex.getMessage(), ex); } ConditionHierarchyNode node = addChild(parent, new ClassFieldContext(subjectInstance, - LoadableComponentsUtil.getConditionsFormField(field))); + LoadableComponentsUtil.getConditionsFormField(field))); String className = node.getLoadableFieldContext().getSubjectClass().getCanonicalName(); - if(node.equals(findFirstOccurrence(node))) { + if (node.equals(findFirstOccurrence(node))) { LOG.debug("Building loadable components hierarchy tree for " + className); processLoadableContextForClass(field.getType(), node, subjectInstance); } else { - LOG.debug("Loadable components hierarchy tree for " + className + " has already been built, skipping."); + LOG.debug("Loadable components hierarchy tree for " + className + + " has already been built, skipping."); } }); } @@ -152,10 +154,10 @@ private ConditionHierarchyNode findFirstOccurrence(ConditionHierarchyNode node) return treeRootNode; } else { return treeRootNode.getChildren().stream() // - .map(temp -> findNode(temp, node.getLoadableFieldContext().getSubject())) // - .filter(Objects::nonNull) // - .findFirst() // - .orElse(null); + .map(temp -> findNode(temp, node.getLoadableFieldContext().getSubject())) // + .filter(Objects::nonNull) // + .findFirst() // + .orElse(null); } } } diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/loadable/tracker/ConditionProgressTracker.java b/bb-core/src/main/java/com/cognifide/qa/bb/loadable/tracker/ConditionProgressTracker.java index 50043514..2ed96b1c 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/loadable/tracker/ConditionProgressTracker.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/loadable/tracker/ConditionProgressTracker.java @@ -19,6 +19,7 @@ import com.cognifide.qa.bb.loadable.context.LoadableComponentContext; import com.cognifide.qa.bb.loadable.context.ConditionContext; +import java.util.Deque; import java.util.LinkedList; import java.util.Stack; @@ -34,9 +35,9 @@ public class ConditionProgressTracker { private final LinkedList progressData; - private final Stack conditionHierarchy; + private final Deque conditionHierarchy; - public ConditionProgressTracker(Stack conditionHierarchy) { + public ConditionProgressTracker(Deque conditionHierarchy) { this.conditionHierarchy = conditionHierarchy; this.progressData = new LinkedList<>(); } diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/scope/nestedselector/NestedSelectorScopedLocatorFactory.java b/bb-core/src/main/java/com/cognifide/qa/bb/scope/nestedselector/NestedSelectorScopedLocatorFactory.java index e11fb48c..31830a74 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/scope/nestedselector/NestedSelectorScopedLocatorFactory.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/scope/nestedselector/NestedSelectorScopedLocatorFactory.java @@ -1,5 +1,3 @@ -package com.cognifide.qa.bb.scope.nestedselector; - /*- * #%L * Bobcat Parent @@ -19,6 +17,7 @@ * limitations under the License. * #L% */ +package com.cognifide.qa.bb.scope.nestedselector; import java.lang.reflect.Field; diff --git a/bb-cumber/src/main/java/com/cognifide/qa/bb/cumber/Bobcumber.java b/bb-cumber/src/main/java/com/cognifide/qa/bb/cumber/Bobcumber.java index a4ccd884..e74f1360 100644 --- a/bb-cumber/src/main/java/com/cognifide/qa/bb/cumber/Bobcumber.java +++ b/bb-cumber/src/main/java/com/cognifide/qa/bb/cumber/Bobcumber.java @@ -145,8 +145,8 @@ private void shutdownRerun(RunNotifier notifier) { private boolean canRerunFailedTests() { int failedTestsNumber = statisticsHelper.getNumberOfFailedTests(statisticsFile); double percentageOfFailedTests = statisticsHelper.getPercentageOfFailedTests(statisticsFile); - boolean haveNoTests = (failedTestsNumber == 0); - boolean haveTooManyTests = (percentageOfFailedTests > maxFailedTestPercentage); + boolean haveNoTests = failedTestsNumber == 0; + boolean haveTooManyTests = percentageOfFailedTests > maxFailedTestPercentage; return !haveNoTests && !haveTooManyTests; } diff --git a/bb-cumber/src/main/java/com/cognifide/qa/bb/cumber/FeatureMap.java b/bb-cumber/src/main/java/com/cognifide/qa/bb/cumber/FeatureMap.java index 25b69e33..8b590438 100644 --- a/bb-cumber/src/main/java/com/cognifide/qa/bb/cumber/FeatureMap.java +++ b/bb-cumber/src/main/java/com/cognifide/qa/bb/cumber/FeatureMap.java @@ -47,9 +47,9 @@ void addFeature(String failedScenario) { } void writeFeatures(PrintWriter out) { - for (String feature : addedFeatures.keySet()) { + for (Map.Entry> feature : addedFeatures.entrySet()) { out.print(feature); - Set lines = addedFeatures.get(feature); + Set lines = feature.getValue(); for (String line : lines) { out.print(COLON + line); } diff --git a/bb-cumber/src/main/java/com/cognifide/qa/bb/cumber/StatisticsHelper.java b/bb-cumber/src/main/java/com/cognifide/qa/bb/cumber/StatisticsHelper.java index c55190e8..05c98e3e 100644 --- a/bb-cumber/src/main/java/com/cognifide/qa/bb/cumber/StatisticsHelper.java +++ b/bb-cumber/src/main/java/com/cognifide/qa/bb/cumber/StatisticsHelper.java @@ -44,7 +44,7 @@ private int getNumberOfTests(File file, int defaultValue) { Scanner scanner = new Scanner(file, StandardCharsets.UTF_8.name()); returnValue = nextInt(scanner); } catch (FileNotFoundException e) { - LOG.warn(NO_STATISTICS_FILE_FOUND_MESSAGE); + LOG.warn(NO_STATISTICS_FILE_FOUND_MESSAGE, e); } return returnValue; } @@ -62,7 +62,7 @@ int getNumberOfFailedTests(File file, int defaultValue) { returnValue = nextInt(scanner); } } catch (FileNotFoundException e) { - LOG.warn(NO_STATISTICS_FILE_FOUND_MESSAGE); + LOG.warn(NO_STATISTICS_FILE_FOUND_MESSAGE, e); } return returnValue; } diff --git a/bb-reports/src/main/java/com/cognifide/qa/bb/logging/ProxyLogger.java b/bb-reports/src/main/java/com/cognifide/qa/bb/logging/ProxyLogger.java index 33b94d38..7e3d1fb3 100644 --- a/bb-reports/src/main/java/com/cognifide/qa/bb/logging/ProxyLogger.java +++ b/bb-reports/src/main/java/com/cognifide/qa/bb/logging/ProxyLogger.java @@ -116,9 +116,9 @@ public void timeout() { @Override public void dispatch() { entries.stream(). - forEach((e) -> { - eventCollector.getCurrentTest().addLogEntry(e); - }); + forEach((e) -> + eventCollector.getCurrentTest().addLogEntry(e) + ); entries.clear(); } } From 9c125e4563b1f9b36adb7534ba4f64d119fffb6f Mon Sep 17 00:00:00 2001 From: Mikolaj Manski Date: Mon, 3 Apr 2017 10:19:25 +0200 Subject: [PATCH 3/7] sonar fixes --- .../cognifide/qa/bb/constants/ConfigKeys.java | 8 ------ .../cognifide/qa/bb/constants/Timeouts.java | 25 +++---------------- .../cognifide/qa/bb/utils/PropertyUtils.java | 9 ------- 3 files changed, 4 insertions(+), 38 deletions(-) diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/constants/ConfigKeys.java b/bb-core/src/main/java/com/cognifide/qa/bb/constants/ConfigKeys.java index ed9fc068..8b8de4ba 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/constants/ConfigKeys.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/constants/ConfigKeys.java @@ -68,14 +68,6 @@ public final class ConfigKeys { public static final String JUNIT_RERUNS = "junit.reruns"; - public static final String TIMEOUTS_BIG = "timeouts.big"; - - public static final String TIMEOUTS_MEDIUM = "timeouts.medium"; - - public static final String TIMEOUTS_SMALL = "timeouts.small"; - - public static final String TIMEOUTS_MINIMAL = "timeouts.minimal"; - private ConfigKeys() { } diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/constants/Timeouts.java b/bb-core/src/main/java/com/cognifide/qa/bb/constants/Timeouts.java index 13e66922..857cb68f 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/constants/Timeouts.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/constants/Timeouts.java @@ -21,29 +21,12 @@ public final class Timeouts { - public static int BIG = 30; + public static final int BIG = 30; - public static int MEDIUM = 15; + public static final int MEDIUM = 15; - public static int SMALL = 5; + public static final int SMALL = 5; - public static int MINIMAL = 1; - - private static Timeouts instance; - - private Timeouts() { - } - - public Timeouts(int big, int medium, int small, int minimal) { - synchronized (this) { - if (instance == null) { - BIG = big; - SMALL = small; - MEDIUM = medium; - MINIMAL = minimal; - instance = this; - } - } - } + public static final int MINIMAL = 1; } diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/utils/PropertyUtils.java b/bb-core/src/main/java/com/cognifide/qa/bb/utils/PropertyUtils.java index 77172399..c9c9ac5c 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/utils/PropertyUtils.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/utils/PropertyUtils.java @@ -69,7 +69,6 @@ public static Properties gatherProperties() { } overrideFromSystemProperties(properties); setSystemProperties(properties); - overrideTimeouts(properties); } catch (IOException e) { LOG.error("Can't bind properties", e); } @@ -77,14 +76,6 @@ public static Properties gatherProperties() { return properties; } - private static void overrideTimeouts(Properties properties) { - int big = Integer.parseInt(properties.getProperty(ConfigKeys.TIMEOUTS_BIG)); - int medium = Integer.parseInt(properties.getProperty(ConfigKeys.TIMEOUTS_MEDIUM)); - int small = Integer.parseInt(properties.getProperty(ConfigKeys.TIMEOUTS_SMALL)); - int minimal = Integer.parseInt(properties.getProperty(ConfigKeys.TIMEOUTS_MINIMAL)); - new Timeouts(big, medium, small, minimal); - } - private static Properties loadDefaultProperties() throws IOException { Properties properties = new Properties(); try (InputStream is = PropertyBinder.class.getClassLoader() From aa792ee3876da2f6bf98d1014e9e297e15ae47c8 Mon Sep 17 00:00:00 2001 From: Mikolaj Manski Date: Mon, 3 Apr 2017 12:55:55 +0200 Subject: [PATCH 4/7] sonar fixes --- .../bb/aem/dialog/classic/field/RtButton.java | 2 +- .../com/cognifide/qa/bb/aem/ui/AemDialog.java | 1 - .../qa/bb/aem/ui/sidekick/ModeIcon.java | 2 +- .../qa/bb/aem/ui/sidekick/PageOperation.java | 2 +- .../qa/bb/aem/ui/sidekick/SidekickGrid.java | 1 - .../qa/bb/aem/ui/sidekick/SidekickTab.java | 2 +- .../qa/bb/aem/content/ContentInstaller.java | 2 +- .../qa/bb/aem/content/WcmCommandHandler.java | 2 +- .../componentconfigs/ComponentConfigs.java | 4 +- .../componentproperties/ComponentState.java | 2 +- .../touch/pageobjects/pages/AuthorPage.java | 3 -- .../aem/touch/siteadmin/SiteadminActions.java | 2 +- .../touch/siteadmin/aem61/SiteadminPage.java | 3 -- .../siteadmin/aem61/SiteadminToolbar.java | 2 - .../aem61/calendar/YearMonthPicker.java | 2 +- .../siteadmin/aem61/list/ChildPageWindow.java | 4 -- .../touch/siteadmin/aem62/ContentToolbar.java | 2 +- .../touch/siteadmin/aem62/SiteadminPage.java | 4 +- .../aem62/calendar/YearMonthPicker.java | 2 +- .../qa/bb/aem/touch/util/ContentHelper.java | 3 +- .../bb/processors/PageObjectTreeScanner.java | 4 +- .../cognifide/qa/bb/constants/Timeouts.java | 4 ++ .../qa/bb/dragdrop/DraggableWebElement.java | 2 +- .../qa/bb/guice/ThreadLocalScope.java | 4 +- .../loadable/context/ClassFieldContext.java | 2 +- .../hierarchy/ConditionChainRunner.java | 7 ++- .../hierarchy/ConditionsExplorer.java | 23 +++++----- .../PageObjectInvocationTracker.java | 4 +- .../tracker/ConditionProgressTracker.java | 43 ++++++++++--------- .../bb/loadable/tracker/ConditionStatus.java | 2 +- .../selenium/webdriver/WebDriverType.java | 4 +- .../selenium/webdriver/WebDriverWrapper.java | 14 +++--- .../qa/bb/scope/frame/type/IndexedFrame.java | 2 +- .../qa/bb/scope/frame/type/NamedFrame.java | 2 +- .../cognifide/qa/bb/utils/PropertyUtils.java | 3 +- .../qa/bb/webelement/BobcatWebElement.java | 2 +- .../java/com/cognifide/qa/bb/ConfigKeys.java | 7 +-- .../com/cognifide/qa/bb/cumber/Bobcumber.java | 4 +- .../qa/bb/cumber/BobcumberListener.java | 6 +-- .../qa/bb/junit/TestEventCollector.java | 4 +- .../bb/junit/concurrent/ReportingHandler.java | 4 +- .../bb/logging/BrowserLogEntryCollector.java | 2 +- .../cognifide/qa/bb/logging/ProxyLogger.java | 2 +- .../com/cognifide/qa/bb/logging/TestInfo.java | 1 - .../qa/bb/logging/entries/LogEntry.java | 4 +- .../bb/proxy/analyzer/AnalyzerCallable.java | 2 +- .../bb/proxy/analyzer/DispatchingFuture.java | 4 +- .../qa/bb/proxy/record/TrafficLog.java | 8 ++-- .../bb/proxy/record/TrafficLogContains.java | 4 +- 49 files changed, 99 insertions(+), 122 deletions(-) diff --git a/bb-aem-classic/src/main/java/com/cognifide/qa/bb/aem/dialog/classic/field/RtButton.java b/bb-aem-classic/src/main/java/com/cognifide/qa/bb/aem/dialog/classic/field/RtButton.java index 0c8c9e97..1a0f81f5 100644 --- a/bb-aem-classic/src/main/java/com/cognifide/qa/bb/aem/dialog/classic/field/RtButton.java +++ b/bb-aem-classic/src/main/java/com/cognifide/qa/bb/aem/dialog/classic/field/RtButton.java @@ -42,7 +42,7 @@ public enum RtButton { private final String css; - private RtButton(String css) { + RtButton(String css) { this.css = css; } diff --git a/bb-aem-classic/src/main/java/com/cognifide/qa/bb/aem/ui/AemDialog.java b/bb-aem-classic/src/main/java/com/cognifide/qa/bb/aem/ui/AemDialog.java index 5006f495..073f1c97 100644 --- a/bb-aem-classic/src/main/java/com/cognifide/qa/bb/aem/ui/AemDialog.java +++ b/bb-aem-classic/src/main/java/com/cognifide/qa/bb/aem/ui/AemDialog.java @@ -31,7 +31,6 @@ import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.interactions.Actions; -import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.ui.ExpectedCondition; import org.openqa.selenium.support.ui.ExpectedConditions; import org.slf4j.Logger; diff --git a/bb-aem-classic/src/main/java/com/cognifide/qa/bb/aem/ui/sidekick/ModeIcon.java b/bb-aem-classic/src/main/java/com/cognifide/qa/bb/aem/ui/sidekick/ModeIcon.java index 18f123ba..7d41ebc5 100644 --- a/bb-aem-classic/src/main/java/com/cognifide/qa/bb/aem/ui/sidekick/ModeIcon.java +++ b/bb-aem-classic/src/main/java/com/cognifide/qa/bb/aem/ui/sidekick/ModeIcon.java @@ -28,7 +28,7 @@ public enum ModeIcon { private final String iconName; - private ModeIcon(final String iconName) { + ModeIcon(final String iconName) { this.iconName = iconName; } diff --git a/bb-aem-classic/src/main/java/com/cognifide/qa/bb/aem/ui/sidekick/PageOperation.java b/bb-aem-classic/src/main/java/com/cognifide/qa/bb/aem/ui/sidekick/PageOperation.java index bbaf55e6..1d2a2ecb 100644 --- a/bb-aem-classic/src/main/java/com/cognifide/qa/bb/aem/ui/sidekick/PageOperation.java +++ b/bb-aem-classic/src/main/java/com/cognifide/qa/bb/aem/ui/sidekick/PageOperation.java @@ -54,7 +54,7 @@ public enum PageOperation { private final SidekickSection section; - private PageOperation(final SidekickTab tab, final SidekickSection section, + PageOperation(final SidekickTab tab, final SidekickSection section, final String operationName) { this.tab = tab; this.section = section; diff --git a/bb-aem-classic/src/main/java/com/cognifide/qa/bb/aem/ui/sidekick/SidekickGrid.java b/bb-aem-classic/src/main/java/com/cognifide/qa/bb/aem/ui/sidekick/SidekickGrid.java index e19f7a29..91d6344d 100644 --- a/bb-aem-classic/src/main/java/com/cognifide/qa/bb/aem/ui/sidekick/SidekickGrid.java +++ b/bb-aem-classic/src/main/java/com/cognifide/qa/bb/aem/ui/sidekick/SidekickGrid.java @@ -23,7 +23,6 @@ import com.cognifide.qa.bb.qualifier.FindPageObject; import org.openqa.selenium.WebElement; -import org.openqa.selenium.support.FindBy; import com.cognifide.qa.bb.qualifier.Frame; import com.cognifide.qa.bb.qualifier.PageObject; diff --git a/bb-aem-classic/src/main/java/com/cognifide/qa/bb/aem/ui/sidekick/SidekickTab.java b/bb-aem-classic/src/main/java/com/cognifide/qa/bb/aem/ui/sidekick/SidekickTab.java index 5a9830e5..03d2c8b1 100644 --- a/bb-aem-classic/src/main/java/com/cognifide/qa/bb/aem/ui/sidekick/SidekickTab.java +++ b/bb-aem-classic/src/main/java/com/cognifide/qa/bb/aem/ui/sidekick/SidekickTab.java @@ -28,7 +28,7 @@ public enum SidekickTab { private final String tabName; - private SidekickTab(final String tabName) { + SidekickTab(final String tabName) { this.tabName = tabName; } diff --git a/bb-aem-common/src/main/java/com/cognifide/qa/bb/aem/content/ContentInstaller.java b/bb-aem-common/src/main/java/com/cognifide/qa/bb/aem/content/ContentInstaller.java index b2e68031..d99360b8 100644 --- a/bb-aem-common/src/main/java/com/cognifide/qa/bb/aem/content/ContentInstaller.java +++ b/bb-aem-common/src/main/java/com/cognifide/qa/bb/aem/content/ContentInstaller.java @@ -70,7 +70,7 @@ public void installAemPackage(String packageName) throws IOException { * @param packageName Name of the package to be activated. * @throws IOException Thrown when AEM instance returns NOK response. */ - public void activateAemPackage(String packageName) throws IOException, IllegalArgumentException { + public void activateAemPackage(String packageName) throws IOException { HttpPost upload = builder.createUploadRequest(); MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create(); File file = new File(CONTENT_PATH, packageName); diff --git a/bb-aem-common/src/main/java/com/cognifide/qa/bb/aem/content/WcmCommandHandler.java b/bb-aem-common/src/main/java/com/cognifide/qa/bb/aem/content/WcmCommandHandler.java index 21e32bdd..86a1e379 100644 --- a/bb-aem-common/src/main/java/com/cognifide/qa/bb/aem/content/WcmCommandHandler.java +++ b/bb-aem-common/src/main/java/com/cognifide/qa/bb/aem/content/WcmCommandHandler.java @@ -149,7 +149,7 @@ public void triggerAction(Map postProperties, String commandUrl, HttpPost request = new HttpPost(String.format(commandUrl, authorIp)); List params = new ArrayList<>(); postProperties.entrySet().stream(). - forEach((property) -> + forEach(property -> params.add(new BasicNameValuePair(property.getKey(), property.getValue())) ); request.setEntity(new UrlEncodedFormEntity(params, Consts.UTF_8)); diff --git a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/data/componentconfigs/ComponentConfigs.java b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/data/componentconfigs/ComponentConfigs.java index a36a5963..eac28695 100644 --- a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/data/componentconfigs/ComponentConfigs.java +++ b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/data/componentconfigs/ComponentConfigs.java @@ -49,10 +49,10 @@ public Map getConfigs(String component) { Map result = new HashMap<>(); - configsData.keySet().stream().forEach((configName) -> { + configsData.keySet().stream().forEach(configName -> { Map> data = configsData.get(configName); List tabsConfig = new ArrayList<>(); - data.entrySet().stream().forEach((entry) -> + data.entrySet().stream().forEach(entry -> tabsConfig.add(new TabConfig(entry.getKey(), entry.getValue())) ); result.put(configName, new ComponentConfiguration(tabsConfig)); diff --git a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/data/componentproperties/ComponentState.java b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/data/componentproperties/ComponentState.java index 3a867101..2685f4cf 100644 --- a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/data/componentproperties/ComponentState.java +++ b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/data/componentproperties/ComponentState.java @@ -86,7 +86,7 @@ public Map getExpected(ComponentConfiguration config, final Map result = new HashMap<>(); config.getTabs().stream() - .forEach((tab) -> { + .forEach(tab -> { List fieldConfigs = config.getConfigurationForTab(tab.getTabName()); result.putAll(fieldConfigs.stream() .filter(fieldConfig -> fieldConfig.getValue() instanceof String) diff --git a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/pageobjects/pages/AuthorPage.java b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/pageobjects/pages/AuthorPage.java index 6de0046b..841058ef 100644 --- a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/pageobjects/pages/AuthorPage.java +++ b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/pageobjects/pages/AuthorPage.java @@ -22,18 +22,15 @@ import static org.openqa.selenium.support.ui.ExpectedConditions.not; import java.util.List; -import java.util.Map; import java.util.Objects; import com.cognifide.qa.bb.qualifier.FindPageObject; -import javax.annotation.Nullable; import org.apache.commons.lang3.StringUtils; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; -import org.openqa.selenium.support.ui.ExpectedCondition; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/SiteadminActions.java b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/SiteadminActions.java index 1953584d..b9465bcc 100644 --- a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/SiteadminActions.java +++ b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/SiteadminActions.java @@ -160,6 +160,6 @@ public interface SiteadminActions { * @param title * @return */ - public SiteadminChildPage getPageFromList(String title); + SiteadminChildPage getPageFromList(String title); } diff --git a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem61/SiteadminPage.java b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem61/SiteadminPage.java index bb741468..08003743 100644 --- a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem61/SiteadminPage.java +++ b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem61/SiteadminPage.java @@ -15,14 +15,11 @@ import java.time.LocalDateTime; -import javax.annotation.Nullable; - import org.openqa.selenium.By; import org.openqa.selenium.StaleElementReferenceException; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; -import org.openqa.selenium.support.ui.ExpectedCondition; import com.cognifide.qa.bb.aem.touch.siteadmin.SiteadminActions; import com.cognifide.qa.bb.aem.touch.siteadmin.aem61.list.ChildPageRow; diff --git a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem61/SiteadminToolbar.java b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem61/SiteadminToolbar.java index 0c83f698..ca57437a 100644 --- a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem61/SiteadminToolbar.java +++ b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem61/SiteadminToolbar.java @@ -24,8 +24,6 @@ import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; -import com.cognifide.qa.bb.loadable.annotation.LoadableComponent; -import com.cognifide.qa.bb.loadable.condition.impl.VisibilityCondition; import com.cognifide.qa.bb.constants.Timeouts; import com.cognifide.qa.bb.provider.selenium.BobcatWait; import com.cognifide.qa.bb.qualifier.Global; diff --git a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem61/calendar/YearMonthPicker.java b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem61/calendar/YearMonthPicker.java index f118c502..a66525ae 100644 --- a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem61/calendar/YearMonthPicker.java +++ b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem61/calendar/YearMonthPicker.java @@ -43,6 +43,6 @@ private boolean isDesiredDateSelected(int year, Month month) { String[] headerParts = yearMonthHeader.getText().toUpperCase().split(" "); Month selectedMonth = Month.valueOf(headerParts[0]); int selectedYear = Integer.parseInt(headerParts[1].toUpperCase()); - return year == selectedYear && selectedMonth.equals(month); + return year == selectedYear && selectedMonth == month; } } diff --git a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem61/list/ChildPageWindow.java b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem61/list/ChildPageWindow.java index dbd20efb..b614c181 100644 --- a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem61/list/ChildPageWindow.java +++ b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem61/list/ChildPageWindow.java @@ -17,13 +17,9 @@ import java.util.List; -import javax.annotation.Nullable; - import org.openqa.selenium.StaleElementReferenceException; -import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; -import org.openqa.selenium.support.ui.ExpectedCondition; import com.cognifide.qa.bb.constants.Timeouts; import com.cognifide.qa.bb.qualifier.Global; diff --git a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem62/ContentToolbar.java b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem62/ContentToolbar.java index 5d9fec6b..3999e720 100644 --- a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem62/ContentToolbar.java +++ b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem62/ContentToolbar.java @@ -55,7 +55,7 @@ public CreatePageWizard getCreatePageWizard() { public WebElement getCreateButton() { List buttonsLabels = driver.findElements( By.cssSelector("button.coral-Button--primary coral-button-label.coral-Button-label")); - return buttonsLabels.stream().filter(label -> label.getText().equals(CREATE_BTN_LABEL)) + return buttonsLabels.stream().filter(label -> CREATE_BTN_LABEL.equals(label.getText())) .findFirst() .orElseThrow(() -> new IllegalStateException("Expected element is not found")); } diff --git a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem62/SiteadminPage.java b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem62/SiteadminPage.java index 676024d9..fc4b00b6 100644 --- a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem62/SiteadminPage.java +++ b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem62/SiteadminPage.java @@ -18,8 +18,6 @@ import java.util.function.Function; import java.util.stream.Collectors; -import javax.annotation.Nullable; - import org.apache.commons.lang3.StringUtils; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; @@ -246,7 +244,7 @@ private void waitForExpectedStatus(final String title, ActivationStatus status) ChildPageRow childPageRow = getChildPageWindow().getChildPageRow(title); PageActivationStatus pageActivationStatusCell = childPageRow.getPageActivationStatus(); ActivationStatus activationStatus = pageActivationStatusCell.getActivationStatus(); - return activationStatus.equals(status); + return activationStatus == status; }, Timeouts.MINIMAL); } diff --git a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem62/calendar/YearMonthPicker.java b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem62/calendar/YearMonthPicker.java index 1eb96c7d..97a9c229 100644 --- a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem62/calendar/YearMonthPicker.java +++ b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/siteadmin/aem62/calendar/YearMonthPicker.java @@ -41,7 +41,7 @@ private boolean isDesiredDateSelected(int year, Month month) { String[] headerParts = yearMonthHeader.getText().toUpperCase().split(" "); Month selectedMonth = Month.valueOf(headerParts[0]); int selectedYear = Integer.parseInt(headerParts[1].toUpperCase()); - return year == selectedYear && selectedMonth.equals(month); + return year == selectedYear && selectedMonth == month; } } diff --git a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/util/ContentHelper.java b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/util/ContentHelper.java index c5edf407..0b02ef0f 100644 --- a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/util/ContentHelper.java +++ b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/util/ContentHelper.java @@ -20,6 +20,7 @@ package com.cognifide.qa.bb.aem.touch.util; import static com.cognifide.qa.bb.jcr.JcrExpectedConditions.nodeExist; +import static javax.jcr.Property.JCR_TITLE; import static org.apache.commons.lang3.StringUtils.substringAfterLast; import static org.apache.commons.lang3.StringUtils.substringBeforeLast; @@ -48,8 +49,6 @@ public class ContentHelper { private static final String SEPARATOR = "/"; - private static final String JCR_TITLE = "jcr:title"; - private final JcrHelper jcrHelper; private final Session session; diff --git a/bb-annotations/src/main/java/com/cognifide/qa/bb/processors/PageObjectTreeScanner.java b/bb-annotations/src/main/java/com/cognifide/qa/bb/processors/PageObjectTreeScanner.java index 83b124aa..a93208b0 100644 --- a/bb-annotations/src/main/java/com/cognifide/qa/bb/processors/PageObjectTreeScanner.java +++ b/bb-annotations/src/main/java/com/cognifide/qa/bb/processors/PageObjectTreeScanner.java @@ -108,8 +108,8 @@ private Type getType(Class clazz) { private boolean containsField(JCTree.JCClassDecl classDef, Name name) { return classDef.defs.stream() .filter(t -> t instanceof JCVariableDecl) - .map((elem) -> (JCVariableDecl) elem) - .anyMatch((var) -> var.getName().equals(name)); + .map(elem -> (JCVariableDecl) elem) + .anyMatch(var -> var.getName().equals(name)); } } diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/constants/Timeouts.java b/bb-core/src/main/java/com/cognifide/qa/bb/constants/Timeouts.java index 857cb68f..96f503bd 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/constants/Timeouts.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/constants/Timeouts.java @@ -29,4 +29,8 @@ public final class Timeouts { public static final int MINIMAL = 1; + private Timeouts() { + //class with constants + } + } diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/dragdrop/DraggableWebElement.java b/bb-core/src/main/java/com/cognifide/qa/bb/dragdrop/DraggableWebElement.java index c82115f7..691932c5 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/dragdrop/DraggableWebElement.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/dragdrop/DraggableWebElement.java @@ -111,7 +111,7 @@ private void performMovement(int movement, Orientantion orientantion, Actions bu int movementDirection = Integer.signum(movement); while (movementRemains > 0) { int movementStep = movementRemains >= MOVEMENT_STEP ? MOVEMENT_STEP : 1; - if (orientantion.equals(Orientantion.VERTICAL)) { + if (orientantion == Orientantion.VERTICAL) { builder.moveByOffset(0, movementDirection * movementStep); } else { builder.moveByOffset(movementDirection * movementStep, 0); diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/guice/ThreadLocalScope.java b/bb-core/src/main/java/com/cognifide/qa/bb/guice/ThreadLocalScope.java index ea7d6e6a..774aea03 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/guice/ThreadLocalScope.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/guice/ThreadLocalScope.java @@ -44,9 +44,7 @@ public Provider scope(final Key key, final Provider unscoped) { threadScopedObjects.put(key, newInstance); } - @SuppressWarnings("unchecked") - T instance = (T) threadScopedObjects.get(key); - return instance; + return (T) threadScopedObjects.get(key); }; } diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/loadable/context/ClassFieldContext.java b/bb-core/src/main/java/com/cognifide/qa/bb/loadable/context/ClassFieldContext.java index 706762cc..8fc865cb 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/loadable/context/ClassFieldContext.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/loadable/context/ClassFieldContext.java @@ -36,7 +36,7 @@ public ClassFieldContext(Object subject, List conditionData) { public List toLoadableContextList() { List result = new ArrayList<>(); conditionData.stream(). - forEach((loadableComponentData) -> + forEach(loadableComponentData -> result.add(new LoadableComponentContext(subject, subjectClass, loadableComponentData)) ); return result; diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/ConditionChainRunner.java b/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/ConditionChainRunner.java index d6905dea..941d58ef 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/ConditionChainRunner.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/ConditionChainRunner.java @@ -44,7 +44,7 @@ public class ConditionChainRunner { * @param conditionStack Stack of conditions to be evaluated * @throws LoadableConditionException when some condition fails */ - public void chainCheck(ConditionStack conditionStack) throws LoadableConditionException { + public void chainCheck(ConditionStack conditionStack) { Deque stack = conditionStack.getLoadableContextStack(); ConditionProgressTracker progressTracker = new ConditionProgressTracker(stack); @@ -73,8 +73,7 @@ private LoadableComponentCondition produceInitializedCondition(LoadableComponent } private void evaluateCondition(LoadableComponentCondition componentCondition, Object subject, - LoadableComponentContext loadableContext, ConditionProgressTracker progressTracker) throws - LoadableConditionException { + LoadableComponentContext loadableContext, ConditionProgressTracker progressTracker) { boolean result = false; Exception exception = null; try { @@ -87,7 +86,7 @@ private void evaluateCondition(LoadableComponentCondition componentCondition, Ob } private void manageEvaluationResult(boolean result, Exception exception, - ConditionProgressTracker progressTracker) throws LoadableConditionException { + ConditionProgressTracker progressTracker) { if (result == false || exception != null) { progressTracker.provideStepResult(ConditionStatus.FAIL); throw new LoadableConditionException(progressTracker.produceConditionTraceInfo(exception)); diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/ConditionsExplorer.java b/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/ConditionsExplorer.java index 01acf742..fb0a4024 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/ConditionsExplorer.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/ConditionsExplorer.java @@ -53,16 +53,15 @@ public class ConditionsExplorer { private final ConditionHierarchyNode treeRootNode = new ConditionHierarchyNode(null); /** - * Discovers the hierarchy of Loadable Conditions form provided class up to the root class - * which is usually the test class which have run the test. + * Discovers the hierarchy of Loadable Conditions form provided class up to the root class which + * is usually the test class which have run the test. * * @param directClassFieldContext context of the class field that have called the - * {@link WebElement} method. - * @param subjectStack stack of subjects which taken part in invocation of - * WebElement's method - * @return Stack of hierarchical conditions from {@link LoadableComponent} annotated fields - * from the test - * class down to the "clazz" parameter with "directClassFieldContext" from that class. + * {@link WebElement} method. + * @param subjectStack stack of subjects which taken part in invocation of WebElement's method + * @return Stack of hierarchical conditions from {@link LoadableComponent} annotated fields from + * the test class down to the "clazz" parameter with "directClassFieldContext" from that + * class. */ public ConditionStack discoverLoadableContextHierarchy(ClassFieldContext directClassFieldContext, LinkedList subjectStack) { @@ -105,7 +104,7 @@ private void processLoadableContextForClass(Class clazz, ConditionHierarchyNode .filter(f -> f.getType().isAnnotationPresent(PageObject.class)) .collect(Collectors.toList()); - applicableFields.forEach((field) -> { + applicableFields.forEach(field -> { field.setAccessible(true); Object subjectInstance = null; try { @@ -118,11 +117,11 @@ private void processLoadableContextForClass(Class clazz, ConditionHierarchyNode String className = node.getLoadableFieldContext().getSubjectClass().getCanonicalName(); if (node.equals(findFirstOccurrence(node))) { - LOG.debug("Building loadable components hierarchy tree for " + className); + LOG.debug("Building loadable components hierarchy tree for {}", className); processLoadableContextForClass(field.getType(), node, subjectInstance); } else { - LOG.debug("Loadable components hierarchy tree for " + className - + " has already been built, skipping."); + LOG.debug("Loadable components hierarchy tree for {} has already been built, skipping.", + className); } }); } diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/PageObjectInvocationTracker.java b/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/PageObjectInvocationTracker.java index e7049e0d..56a67c0c 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/PageObjectInvocationTracker.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/PageObjectInvocationTracker.java @@ -27,10 +27,10 @@ public class PageObjectInvocationTracker { private final LinkedList subjectStack = new LinkedList<>(); - private final Supplier> supplier = () -> new LinkedList<>(); + private final Supplier> supplier = LinkedList::new; public List getSubjectStack() { - return subjectStack.stream().map(element -> element.getSubject()).collect(Collectors. + return subjectStack.stream().map(RuntimeContext::getSubject).collect(Collectors. toCollection(supplier)); } diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/loadable/tracker/ConditionProgressTracker.java b/bb-core/src/main/java/com/cognifide/qa/bb/loadable/tracker/ConditionProgressTracker.java index 2ed96b1c..9a79a5f4 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/loadable/tracker/ConditionProgressTracker.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/loadable/tracker/ConditionProgressTracker.java @@ -1,17 +1,15 @@ /* * Copyright 2016 Cognifide Ltd.. * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. */ package com.cognifide.qa.bb.loadable.tracker; @@ -21,7 +19,6 @@ import java.util.Deque; import java.util.LinkedList; -import java.util.Stack; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -45,11 +42,12 @@ public ConditionProgressTracker(Deque conditionHierarc /** * Register start of an step evaluation * - * @param context The context of {@link LoadableComponent} annotation which is currently under processing + * @param context The context of {@link LoadableComponent} annotation which is currently under + * processing */ public void stepStart(LoadableComponentContext context) { String info = produceLoadableComponentInfo(context.getConditionContext()); - LOG.debug("Started lodable component condition evaluation: " + info); + LOG.debug("Started lodable component condition evaluation: {}", info); progressData.add(new ConditionProgressStep(info)); } @@ -59,18 +57,20 @@ public void stepStart(LoadableComponentContext context) { * @param status Condition evaluation status */ public void provideStepResult(ConditionStatus status) { - LOG.debug("Evaluated loadable condition " - + progressData.peekLast().getLoadableComponentInfo() + " with status " + status.getMessage()); + ConditionProgressStep lastStep = progressData.peekLast(); + LOG.debug("Evaluated loadable condition {} with status {}", lastStep.getLoadableComponentInfo(), + status.getMessage()); - progressData.peekLast().setStepStatus(status); + lastStep.setStepStatus(status); } /** * * @param rootCause Exception that caused the error - * @return String containing the information about conditions that have been run in hierarchical order - * starting from the top. The output is in the following format: - * [class that uses the field annotated with {@link LoadableComponent}] - [fieldName] ~ [condition class that have been under evaluation] (Status) + * @return String containing the information about conditions that have been run in hierarchical + * order starting from the top. The output is in the following format: [class that uses + * the field annotated with {@link LoadableComponent}] - [fieldName] ~ [condition class + * that have been under evaluation] (Status) */ public String produceConditionTraceInfo(Exception rootCause) { StringBuilder sb = new StringBuilder("Loadable conditions trace info:"); @@ -93,14 +93,15 @@ public String produceConditionTraceInfo(Exception rootCause) { if (rootCause != null) { sb.append("Root cause: "); sb.append(System.lineSeparator()); - sb.append(rootCause.toString()); + sb.append(rootCause); } return sb.toString(); } private String produceLoadableComponentInfo(ConditionContext loadableComponentData) { - return loadableComponentData.getDeclaringClassName() + " -> " + loadableComponentData.getFieldName() - + " ~ " + loadableComponentData.getLoadableComponent().condClass().getName(); + return loadableComponentData.getDeclaringClassName() + " -> " + + loadableComponentData.getFieldName() + + " ~ " + loadableComponentData.getLoadableComponent().condClass().getName(); } } diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/loadable/tracker/ConditionStatus.java b/bb-core/src/main/java/com/cognifide/qa/bb/loadable/tracker/ConditionStatus.java index d3463dd7..d867456e 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/loadable/tracker/ConditionStatus.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/loadable/tracker/ConditionStatus.java @@ -28,7 +28,7 @@ public enum ConditionStatus { private final String message; - private ConditionStatus(String message) { + ConditionStatus(String message) { this.message = message; } diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/provider/selenium/webdriver/WebDriverType.java b/bb-core/src/main/java/com/cognifide/qa/bb/provider/selenium/webdriver/WebDriverType.java index ff3c6944..0116103b 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/provider/selenium/webdriver/WebDriverType.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/provider/selenium/webdriver/WebDriverType.java @@ -149,6 +149,8 @@ public WebDriver create(Capabilities capabilities, Properties properties) { } }; + private static final Logger LOG = LoggerFactory.getLogger(WebDriverType.class); + private static WebDriver getWebDriverWithProxyCookieSupport(Properties properties, WebDriver driver) { if (Boolean.valueOf(properties.getProperty(ConfigKeys.WEBDRIVER_PROXY_COOKIE))) { driver.get(properties.getProperty(ConfigKeys.BASE_URL)); @@ -162,8 +164,6 @@ private static WebDriver getWebDriverWithProxyCookieSupport(Properties propertie return driver; } - private static final Logger LOG = LoggerFactory.getLogger(WebDriverType.class); - public abstract WebDriver create(Capabilities capabilities, Properties properties); /** diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/provider/selenium/webdriver/WebDriverWrapper.java b/bb-core/src/main/java/com/cognifide/qa/bb/provider/selenium/webdriver/WebDriverWrapper.java index 7a19ad47..1e10a374 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/provider/selenium/webdriver/WebDriverWrapper.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/provider/selenium/webdriver/WebDriverWrapper.java @@ -73,12 +73,10 @@ * This class is a "simple" extension of Selenium's EventFiringWebDriver that additionally * implements several useful interfaces. */ -public class WebDriverWrapper extends EventFiringWebDriver implements FindsById, FindsByClassName, - FindsByLinkText, FindsByName, FindsByCssSelector, FindsByTagName, FindsByXPath, - HasCapabilities, MobileDriver, Rotatable, LocationContext, ContextAware, - TouchShortcuts, InteractsWithApps, AndroidDeviceActionShortcuts, HasAppStrings, +public class WebDriverWrapper extends EventFiringWebDriver implements + HasCapabilities, MobileDriver, AndroidDeviceActionShortcuts, HasNetworkConnection, PushesFiles, StartsActivity, FindsByAndroidUIAutomator, - IOSDeviceActionShortcuts, FindsByIosUIAutomation, HasIdentity, PerformsTouchActions { + IOSDeviceActionShortcuts, FindsByIosUIAutomation, HasIdentity { private final FrameSwitcher frameSwitcher; @@ -430,7 +428,7 @@ public List findElementsByAndroidUIAutomator(String using) { @Override public void startActivity(String appPackage, String appActivity, String appWaitPackage, - String appWaitActivity, boolean stopApp) throws IllegalArgumentException { + String appWaitActivity, boolean stopApp) { ((StartsActivity) super.getWrappedDriver()).startActivity(appPackage, appActivity, appWaitPackage, appWaitActivity, stopApp); } @@ -450,7 +448,7 @@ public void startActivity(String appPackage, String appActivity) { @Override public void startActivity(String appPackage, String appActivity, String appWaitPackage, String appWaitActivity, String intentAction, String intentCategory, String intentFlags, - String intentOptionalArgs) throws IllegalArgumentException { + String intentOptionalArgs) { ((StartsActivity) super.getWrappedDriver()).startActivity(appPackage, appActivity, appWaitPackage, appWaitActivity, intentAction, intentCategory, intentFlags, intentOptionalArgs); @@ -460,7 +458,7 @@ public void startActivity(String appPackage, String appActivity, String appWaitP @Override public void startActivity(String appPackage, String appActivity, String appWaitPackage, String appWaitActivity, String intentAction, String intentCategory, String intentFlags, - String intentOptionalArgs, boolean stopApp) throws IllegalArgumentException { + String intentOptionalArgs, boolean stopApp) { ((StartsActivity) super.getWrappedDriver()).startActivity(appPackage, appActivity, appWaitPackage, appWaitActivity, intentAction, intentCategory, intentFlags, intentOptionalArgs, stopApp); diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/scope/frame/type/IndexedFrame.java b/bb-core/src/main/java/com/cognifide/qa/bb/scope/frame/type/IndexedFrame.java index ddbfd74e..d5fbdfa8 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/scope/frame/type/IndexedFrame.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/scope/frame/type/IndexedFrame.java @@ -48,7 +48,7 @@ public IndexedFrame(int index) { @Override public void switchTo(WebDriver webDriver, BobcatWait bobcatWait) { - LOG.debug("Switching to " + index); + LOG.debug("Switching to {}", index); webDriver.switchTo().frame(index); } diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/scope/frame/type/NamedFrame.java b/bb-core/src/main/java/com/cognifide/qa/bb/scope/frame/type/NamedFrame.java index f44c03db..a347c328 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/scope/frame/type/NamedFrame.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/scope/frame/type/NamedFrame.java @@ -50,7 +50,7 @@ public NamedFrame(String frameLocator) { @Override public void switchTo(WebDriver webDriver, BobcatWait bobcatWait) { - LOG.debug("Switching to " + name); + LOG.debug("Switching to {}", name); bobcatWait.withTimeout(Timeouts.SMALL) .until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(name)); } diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/utils/PropertyUtils.java b/bb-core/src/main/java/com/cognifide/qa/bb/utils/PropertyUtils.java index c9c9ac5c..ae236905 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/utils/PropertyUtils.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/utils/PropertyUtils.java @@ -34,7 +34,6 @@ import com.cognifide.qa.bb.PropertyBinder; import com.cognifide.qa.bb.constants.ConfigKeys; -import com.cognifide.qa.bb.constants.Timeouts; /** * This class contains utility methods for loading properties from classpath and system. @@ -110,7 +109,7 @@ private static void loadProperties(File file, Properties properties) throws IOEx } private static void overrideFromSystemProperties(Properties properties) { - properties.stringPropertyNames().stream().forEach((key) -> { + properties.stringPropertyNames().stream().forEach(key -> { String systemProperty = System.getProperty(key); if (StringUtils.isNotBlank(systemProperty)) { properties.setProperty(key, systemProperty); diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/webelement/BobcatWebElement.java b/bb-core/src/main/java/com/cognifide/qa/bb/webelement/BobcatWebElement.java index 6fa2cc62..9e484bf0 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/webelement/BobcatWebElement.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/webelement/BobcatWebElement.java @@ -173,7 +173,7 @@ public WebElement getWrappedElement() { } @Override - public T getScreenshotAs(OutputType target) throws WebDriverException { + public T getScreenshotAs(OutputType target) { return element.getScreenshotAs(target); } diff --git a/bb-cumber/src/main/java/com/cognifide/qa/bb/ConfigKeys.java b/bb-cumber/src/main/java/com/cognifide/qa/bb/ConfigKeys.java index 656b0ba9..618bfa0a 100644 --- a/bb-cumber/src/main/java/com/cognifide/qa/bb/ConfigKeys.java +++ b/bb-cumber/src/main/java/com/cognifide/qa/bb/ConfigKeys.java @@ -21,11 +21,12 @@ public final class ConfigKeys { + public static final String BOBCAT_REPORT_STATISTICS_PATH = "bobcat.report.statistics.path"; + + public static final String BOBCAT_REPORT_STATISTICS_PERCENTAGE = "bobcat.report.statistics.retryPercentage"; + private ConfigKeys() { //Config class... } - public static final String BOBCAT_REPORT_STATISTICS_PATH = "bobcat.report.statistics.path"; - - public static final String BOBCAT_REPORT_STATISTICS_PERCENTAGE = "bobcat.report.statistics.retryPercentage"; } diff --git a/bb-cumber/src/main/java/com/cognifide/qa/bb/cumber/Bobcumber.java b/bb-cumber/src/main/java/com/cognifide/qa/bb/cumber/Bobcumber.java index e74f1360..f4bfedfc 100644 --- a/bb-cumber/src/main/java/com/cognifide/qa/bb/cumber/Bobcumber.java +++ b/bb-cumber/src/main/java/com/cognifide/qa/bb/cumber/Bobcumber.java @@ -24,10 +24,10 @@ import java.io.IOException; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.util.Collection; import java.util.Properties; -import org.apache.commons.lang3.CharEncoding; import org.apache.commons.lang3.reflect.FieldUtils; import org.junit.runner.Description; import org.junit.runner.notification.Failure; @@ -104,7 +104,7 @@ public void run(RunNotifier notifier) { private File createFile(String path) throws FileNotFoundException, UnsupportedEncodingException { File file = new File(path); if (!file.exists()) { - PrintWriter writer = new PrintWriter(file, CharEncoding.UTF_8); + PrintWriter writer = new PrintWriter(file, StandardCharsets.UTF_8.name()); writer.close(); } return file; diff --git a/bb-cumber/src/main/java/com/cognifide/qa/bb/cumber/BobcumberListener.java b/bb-cumber/src/main/java/com/cognifide/qa/bb/cumber/BobcumberListener.java index 93a1d020..57040777 100644 --- a/bb-cumber/src/main/java/com/cognifide/qa/bb/cumber/BobcumberListener.java +++ b/bb-cumber/src/main/java/com/cognifide/qa/bb/cumber/BobcumberListener.java @@ -21,7 +21,6 @@ import java.io.BufferedWriter; import java.io.FileOutputStream; -import java.io.FileWriter; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.PrintWriter; @@ -64,7 +63,8 @@ class BobcumberListener extends RunListener { @Override public void testRunFinished(Result result) throws Exception { - try (PrintWriter writer = new PrintWriter(bobcumber.getStatisticsFile(), CharEncoding.UTF_8)) { + try (PrintWriter writer = + new PrintWriter(bobcumber.getStatisticsFile(), StandardCharsets.UTF_8.name())) { writer.println(scenarioCounter.get()); writer.println(testFailureCounter.get()); } @@ -92,7 +92,7 @@ public void testFailure(Failure failure) throws Exception { } private String normalizeTrace(String trace) { - return trace.substring(trace.lastIndexOf("(") + 1, trace.lastIndexOf(")")); + return trace.substring(trace.lastIndexOf('(') + 1, trace.lastIndexOf(')')); } private synchronized void addScenario(String failedScenario) throws IOException { diff --git a/bb-junit/src/main/java/com/cognifide/qa/bb/junit/TestEventCollector.java b/bb-junit/src/main/java/com/cognifide/qa/bb/junit/TestEventCollector.java index 4c642f8f..e423cda6 100644 --- a/bb-junit/src/main/java/com/cognifide/qa/bb/junit/TestEventCollector.java +++ b/bb-junit/src/main/java/com/cognifide/qa/bb/junit/TestEventCollector.java @@ -49,10 +49,10 @@ public interface TestEventCollector { * * @param message info message */ - public void info(String message); + void info(String message); /** * Remove information about test which is now collected */ - public void removeLastEntry(); + void removeLastEntry(); } diff --git a/bb-junit/src/main/java/com/cognifide/qa/bb/junit/concurrent/ReportingHandler.java b/bb-junit/src/main/java/com/cognifide/qa/bb/junit/concurrent/ReportingHandler.java index 21de8e1a..f336d3bf 100644 --- a/bb-junit/src/main/java/com/cognifide/qa/bb/junit/concurrent/ReportingHandler.java +++ b/bb-junit/src/main/java/com/cognifide/qa/bb/junit/concurrent/ReportingHandler.java @@ -133,9 +133,9 @@ private void setThreadName() { private void report() { injector.findBindingsByType(ACTIVE_REPORTERS).stream() - .map(binding -> binding.getProvider()) + .map(Binding::getProvider) .flatMap(provider -> provider.get().stream()) - .forEach(reporter -> reporter.generateReport()); + .forEach(Reporter::generateReport); logReportProviders(injector); } diff --git a/bb-reports/src/main/java/com/cognifide/qa/bb/logging/BrowserLogEntryCollector.java b/bb-reports/src/main/java/com/cognifide/qa/bb/logging/BrowserLogEntryCollector.java index 18fd7fdc..60fe3c61 100644 --- a/bb-reports/src/main/java/com/cognifide/qa/bb/logging/BrowserLogEntryCollector.java +++ b/bb-reports/src/main/java/com/cognifide/qa/bb/logging/BrowserLogEntryCollector.java @@ -47,7 +47,7 @@ public List getBrowserLogEntries() { webDriver.manage().logs().get(LogType.BROWSER) .filter(Level.SEVERE); browserEntries.stream(). - forEach((browserEntry) -> + forEach(browserEntry -> toReturn.add(new BrowserLogEntry(browserEntry.toString())) ); diff --git a/bb-reports/src/main/java/com/cognifide/qa/bb/logging/ProxyLogger.java b/bb-reports/src/main/java/com/cognifide/qa/bb/logging/ProxyLogger.java index 7e3d1fb3..bc4737ab 100644 --- a/bb-reports/src/main/java/com/cognifide/qa/bb/logging/ProxyLogger.java +++ b/bb-reports/src/main/java/com/cognifide/qa/bb/logging/ProxyLogger.java @@ -116,7 +116,7 @@ public void timeout() { @Override public void dispatch() { entries.stream(). - forEach((e) -> + forEach(e -> eventCollector.getCurrentTest().addLogEntry(e) ); entries.clear(); diff --git a/bb-reports/src/main/java/com/cognifide/qa/bb/logging/TestInfo.java b/bb-reports/src/main/java/com/cognifide/qa/bb/logging/TestInfo.java index 8d20c7da..fec2548a 100644 --- a/bb-reports/src/main/java/com/cognifide/qa/bb/logging/TestInfo.java +++ b/bb-reports/src/main/java/com/cognifide/qa/bb/logging/TestInfo.java @@ -32,7 +32,6 @@ import com.cognifide.qa.bb.provider.selenium.webdriver.close.ClosingAwareWebDriverWrapper; import io.appium.java_client.AppiumDriver; -import io.appium.java_client.MobileDriver; import org.openqa.selenium.Capabilities; import org.openqa.selenium.HasCapabilities; import org.openqa.selenium.WebDriver; diff --git a/bb-reports/src/main/java/com/cognifide/qa/bb/logging/entries/LogEntry.java b/bb-reports/src/main/java/com/cognifide/qa/bb/logging/entries/LogEntry.java index ec90c7f4..7b0fe1b2 100644 --- a/bb-reports/src/main/java/com/cognifide/qa/bb/logging/entries/LogEntry.java +++ b/bb-reports/src/main/java/com/cognifide/qa/bb/logging/entries/LogEntry.java @@ -25,7 +25,7 @@ /** * Base class for all types of log entries. */ -public abstract class LogEntry { +public class LogEntry { private static final AtomicInteger ENTRY_INDEX = new AtomicInteger(); @@ -38,7 +38,7 @@ public abstract class LogEntry { /** * Constructs the LogEntry and sets its timestamp to NOW. */ - public LogEntry() { + protected LogEntry() { index = ENTRY_INDEX.getAndIncrement(); time = System.currentTimeMillis(); } diff --git a/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/analyzer/AnalyzerCallable.java b/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/analyzer/AnalyzerCallable.java index 2bc74a80..712e7c6a 100644 --- a/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/analyzer/AnalyzerCallable.java +++ b/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/analyzer/AnalyzerCallable.java @@ -106,7 +106,7 @@ private void fireFoundEvent() { private void fireWaitingEvent() { proxyListeners.stream(). - forEach((listener) -> + forEach(listener -> listener.waitingForRequest(requestPredicate, closestHarEntryElector) ); } diff --git a/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/analyzer/DispatchingFuture.java b/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/analyzer/DispatchingFuture.java index aea4af6c..c69c0593 100644 --- a/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/analyzer/DispatchingFuture.java +++ b/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/analyzer/DispatchingFuture.java @@ -61,8 +61,6 @@ public Boolean get(long timeout, TimeUnit unit) throws InterruptedException, Exe private void dispatch() { proxyListeners.stream(). - forEach((listener) -> - listener.dispatch() - ); + forEach(ProxyEventListener::dispatch); } } diff --git a/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/record/TrafficLog.java b/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/record/TrafficLog.java index 605f2c31..afb83793 100644 --- a/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/record/TrafficLog.java +++ b/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/record/TrafficLog.java @@ -56,11 +56,9 @@ private int countItems() { if (hars == null || hars.isEmpty()) { return 0; } - int itemCount = 0; - itemCount = hars.stream(). - map((har) -> har.getLog().getEntries().size()). - reduce(itemCount, Integer::sum); - return itemCount; + return hars.stream(). + map(har -> har.getLog().getEntries().size()). + reduce(0, Integer::sum); } } diff --git a/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/record/TrafficLogContains.java b/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/record/TrafficLogContains.java index 0c121caf..dbcaa713 100644 --- a/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/record/TrafficLogContains.java +++ b/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/record/TrafficLogContains.java @@ -52,8 +52,8 @@ public void describeTo(Description description) { @Override protected boolean matchesSafely(TrafficLog item) { return item.getHars().stream(). - anyMatch((har) -> har.getLog().getEntries().stream(). - anyMatch((entry) -> harEntryMatchesPredicates(entry))); + anyMatch(har -> har.getLog().getEntries().stream(). + anyMatch(this::harEntryMatchesPredicates)); } private boolean harEntryMatchesPredicates(HarEntry entry) { From 7ce50738c578cdd0af1eb2e2d6c1d7ae5e8e1268 Mon Sep 17 00:00:00 2001 From: Mikolaj Manski Date: Thu, 6 Apr 2017 16:38:25 +0200 Subject: [PATCH 5/7] sonar-fixes - fixed openDialog method in touch ui --- .../cognifide/qa/bb/aem/touch/pageobjects/touchui/Parsys.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/pageobjects/touchui/Parsys.java b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/pageobjects/touchui/Parsys.java index 6895dbcf..7d6d4d34 100644 --- a/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/pageobjects/touchui/Parsys.java +++ b/bb-aem-touch-ui/src/main/java/com/cognifide/qa/bb/aem/touch/pageobjects/touchui/Parsys.java @@ -217,7 +217,7 @@ private void tryToSelect() { private void tryToOpenInsertWindow() { conditions.verify(ignored -> { try { - boolean isInsertButtonPresent = driver + boolean isInsertButtonPresent = !driver .findElements(By.cssSelector(INSERT_BUTTON_SELECTOR)) .isEmpty(); if(!isInsertButtonPresent) { From 949834d9efbdfb53bb137bd8f7fbef736ff8491c Mon Sep 17 00:00:00 2001 From: Mikolaj Manski Date: Mon, 10 Apr 2017 13:06:19 +0200 Subject: [PATCH 6/7] sonar fixes --- .../cognifide/qa/bb/proxy/analyzer/AnalyzerCallable.java | 9 +++++---- .../com/cognifide/qa/bb/proxy/record/AnalyticsWait.java | 8 ++++++-- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/analyzer/AnalyzerCallable.java b/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/analyzer/AnalyzerCallable.java index 712e7c6a..38394bb9 100644 --- a/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/analyzer/AnalyzerCallable.java +++ b/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/analyzer/AnalyzerCallable.java @@ -78,9 +78,11 @@ public Boolean call() throws Exception { registry.add(filter); controller.startAnalysis(); fireWaitingEvent(); + long timeoutPoint = System.currentTimeMillis() + (timeoutInSeconds * 1000L); synchronized (filter) { try { - filter.wait(timeoutInSeconds * 1000L); + while (System.currentTimeMillis() < timeoutPoint) + filter.wait(); } catch (InterruptedException e) { LOG.error("Interrupted waiting for request", e); throw e; @@ -105,9 +107,8 @@ private void fireFoundEvent() { } private void fireWaitingEvent() { - proxyListeners.stream(). - forEach(listener -> - listener.waitingForRequest(requestPredicate, closestHarEntryElector) + proxyListeners.stream().forEach(listener -> + listener.waitingForRequest(requestPredicate, closestHarEntryElector) ); } } diff --git a/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/record/AnalyticsWait.java b/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/record/AnalyticsWait.java index 6ceaf1dd..e929c326 100644 --- a/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/record/AnalyticsWait.java +++ b/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/record/AnalyticsWait.java @@ -64,7 +64,10 @@ public AnalyticsWait(RequestFilterRegistry filterRegistry) { */ public synchronized void waitForAnalyticsCall() { try { - this.wait(timeout); + long timeoutPoint = System.currentTimeMillis() + timeout; + while (System.currentTimeMillis() < timeoutPoint) { + this.wait(); + } } catch (InterruptedException e) { LOG.error("Sleep was interrupted", e); Thread.currentThread().interrupt(); @@ -73,7 +76,8 @@ public synchronized void waitForAnalyticsCall() { private class AnalyticsRequestFilter implements RequestFilter { - @Override public io.netty.handler.codec.http.HttpResponse filterRequest(HttpRequest request, + @Override + public io.netty.handler.codec.http.HttpResponse filterRequest(HttpRequest request, HttpMessageContents contents, HttpMessageInfo messageInfo) { String path = request.getUri(); if (path.startsWith(analyticsUriPrefix)) { From 3055e73017012cc39b501fc2fe55f8a7909ff807 Mon Sep 17 00:00:00 2001 From: Mikolaj Manski Date: Mon, 10 Apr 2017 13:33:50 +0200 Subject: [PATCH 7/7] sonar fixes --- .../qa/bb/loadable/hierarchy/ConditionChainRunner.java | 2 +- .../loadable/hierarchy/PageObjectInvocationTracker.java | 4 ++-- .../com/cognifide/qa/bb/webelement/BobcatWebElement.java | 1 - .../cognifide/qa/bb/proxy/analyzer/AnalyzerCallable.java | 8 ++++---- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/ConditionChainRunner.java b/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/ConditionChainRunner.java index 941d58ef..28a6a0f1 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/ConditionChainRunner.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/ConditionChainRunner.java @@ -87,7 +87,7 @@ private void evaluateCondition(LoadableComponentCondition componentCondition, Ob private void manageEvaluationResult(boolean result, Exception exception, ConditionProgressTracker progressTracker) { - if (result == false || exception != null) { + if (!result || exception != null) { progressTracker.provideStepResult(ConditionStatus.FAIL); throw new LoadableConditionException(progressTracker.produceConditionTraceInfo(exception)); } else { diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/PageObjectInvocationTracker.java b/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/PageObjectInvocationTracker.java index 56a67c0c..46b162ba 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/PageObjectInvocationTracker.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/loadable/hierarchy/PageObjectInvocationTracker.java @@ -27,11 +27,11 @@ public class PageObjectInvocationTracker { private final LinkedList subjectStack = new LinkedList<>(); - private final Supplier> supplier = LinkedList::new; + private static final Supplier> SUPPLIER = LinkedList::new; public List getSubjectStack() { return subjectStack.stream().map(RuntimeContext::getSubject).collect(Collectors. - toCollection(supplier)); + toCollection(SUPPLIER)); } public void add(Class clazz, Object subject) { diff --git a/bb-core/src/main/java/com/cognifide/qa/bb/webelement/BobcatWebElement.java b/bb-core/src/main/java/com/cognifide/qa/bb/webelement/BobcatWebElement.java index 9e484bf0..5307e650 100644 --- a/bb-core/src/main/java/com/cognifide/qa/bb/webelement/BobcatWebElement.java +++ b/bb-core/src/main/java/com/cognifide/qa/bb/webelement/BobcatWebElement.java @@ -34,7 +34,6 @@ import org.openqa.selenium.OutputType; import org.openqa.selenium.Point; import org.openqa.selenium.Rectangle; -import org.openqa.selenium.WebDriverException; import org.openqa.selenium.WebElement; import org.openqa.selenium.interactions.internal.Coordinates; import org.openqa.selenium.internal.HasIdentity; diff --git a/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/analyzer/AnalyzerCallable.java b/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/analyzer/AnalyzerCallable.java index 38394bb9..6c87542f 100644 --- a/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/analyzer/AnalyzerCallable.java +++ b/bb-traffic/src/main/java/com/cognifide/qa/bb/proxy/analyzer/AnalyzerCallable.java @@ -81,8 +81,9 @@ public Boolean call() throws Exception { long timeoutPoint = System.currentTimeMillis() + (timeoutInSeconds * 1000L); synchronized (filter) { try { - while (System.currentTimeMillis() < timeoutPoint) + while (System.currentTimeMillis() < timeoutPoint) { filter.wait(); + } } catch (InterruptedException e) { LOG.error("Interrupted waiting for request", e); throw e; @@ -107,8 +108,7 @@ private void fireFoundEvent() { } private void fireWaitingEvent() { - proxyListeners.stream().forEach(listener -> - listener.waitingForRequest(requestPredicate, closestHarEntryElector) - ); + proxyListeners.stream() + .forEach(listener -> listener.waitingForRequest(requestPredicate, closestHarEntryElector)); } }