Skip to content
This repository has been archived by the owner on Apr 30, 2022. It is now read-only.

Commit

Permalink
Merge pull request #311 from Magenic/bug/JMAQS-309
Browse files Browse the repository at this point in the history
JMAQS #309 - Checkstyle and Sonarlint Cleanup
  • Loading branch information
jason-edstrom authored May 15, 2020
2 parents 6ae9153 + d78890a commit 5f95dee
Show file tree
Hide file tree
Showing 35 changed files with 2,087 additions and 2,045 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/checkstyle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven

name: Checkstyle Validation

on:
pull_request:
branches: [ master ]

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Run Checkstyle
run: mvn -B validate --file pom.xml -e -fae
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package com.magenic.jmaqs.appium;

import com.magenic.jmaqs.appium.constants.PlatformType;
import com.magenic.jmaqs.appium.exceptions.AppiumConfigException;
import com.magenic.jmaqs.utilities.helper.Config;
import com.magenic.jmaqs.utilities.helper.ConfigSection;
import com.magenic.jmaqs.utilities.helper.StringProcessor;
Expand All @@ -22,12 +23,12 @@ public class AppiumConfig {
/**
* The appium configuration section.
*/
private static final ConfigSection APPIUM_SECTION = ConfigSection.AppiumMaqs;
private static final ConfigSection APPIUM_SECTION = ConfigSection.APPIUM_MAQS;

/**
* The appium capabilities configuration section.
*/
private static final ConfigSection APPIUM_CAPS_SECTION = ConfigSection.AppiumCapsMaqs;
private static final ConfigSection APPIUM_CAPS_SECTION = ConfigSection.APPIUM_CAPS_MAQS;

private AppiumConfig() {

Expand Down Expand Up @@ -66,8 +67,7 @@ public static String getDeviceName() {
* @return the save page source on fail
*/
public static boolean getSavePageSourceOnFail() {
return Config.getValueForSection(APPIUM_SECTION, "SavePageSourceOnFail")
.equalsIgnoreCase("Yes");
return Config.getValueForSection(APPIUM_SECTION, "SavePageSourceOnFail").equalsIgnoreCase("Yes");
}

/**
Expand All @@ -76,8 +76,7 @@ public static boolean getSavePageSourceOnFail() {
* @return the soft assert screen shot
*/
public static boolean getSoftAssertScreenShot() {
return Config.getValueForSection(APPIUM_SECTION, "SoftAssertScreenShot")
.equalsIgnoreCase("Yes");
return Config.getValueForSection(APPIUM_SECTION, "SoftAssertScreenShot").equalsIgnoreCase("Yes");
}

/**
Expand All @@ -99,7 +98,7 @@ public static URL getMobileHubUrl() {
try {
url = new URL(getMobileHubUrlString());
} catch (MalformedURLException e) {
e.printStackTrace();
throw new AppiumConfigException(e);
}
return url;
}
Expand All @@ -115,8 +114,8 @@ public static Duration getCommandTimeout() {
try {
timeoutValue = Integer.parseInt(value);
} catch (NumberFormatException ex) {
throw new NumberFormatException("MobileCommandTimeout in " + APPIUM_SECTION
+ " should be a number, but the current value is: " + value);
throw new NumberFormatException(
"MobileCommandTimeout in " + APPIUM_SECTION + " should be a number, but the current value is: " + value);
}

return Duration.ofMillis((long) timeoutValue);
Expand All @@ -128,11 +127,9 @@ public static Duration getCommandTimeout() {
* @return the mobile timeout
*/
public static Duration getMobileTimeout() {
return Duration.ofMillis(
Integer.parseInt(Config.getValueForSection(APPIUM_SECTION, "MobileTimeout", "0")));
return Duration.ofMillis(Integer.parseInt(Config.getValueForSection(APPIUM_SECTION, "MobileTimeout", "0")));
}


/**
* Gets capabilities as strings.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright 2020 (C) Magenic, All rights Reserved
*/

package com.magenic.jmaqs.appium.exceptions;

public class AppiumConfigException extends RuntimeException {
public AppiumConfigException(Exception e) {
super(e);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public void testGetCommandTimeout() {
public void testGetCommandTimeoutError() {
HashMap<String, String> configValues = new HashMap<>();
configValues.put("MobileCommandTimeout", "sixty thousand");
Config.addTestSettingValues(configValues, ConfigSection.AppiumMaqs, true);
Config.addTestSettingValues(configValues, ConfigSection.APPIUM_MAQS, true);
AppiumConfig.getCommandTimeout();
}

Expand Down
17 changes: 6 additions & 11 deletions jmaqs-base/src/main/java/com/magenic/jmaqs/base/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;


/**
* Base test class.
*/
Expand Down Expand Up @@ -154,8 +153,7 @@ public List<String> getLoggedExceptions() {
* @param loggedExceptionList ArrayList of logged exceptions to use.
*/
public void setLoggedExceptions(List<String> loggedExceptionList) {
this.loggedExceptions
.put(this.fullyQualifiedTestClassName.get(), (ArrayList<String>) loggedExceptionList);
this.loggedExceptions.put(this.fullyQualifiedTestClassName.get(), (ArrayList<String>) loggedExceptionList);
}

/**
Expand Down Expand Up @@ -238,8 +236,7 @@ public void teardown() {
try {
this.beforeLoggingTeardown(testResult);
} catch (Exception e) {
this.tryToLog(MessageType.WARNING, "Failed before logging teardown because: %s",
e.getMessage());
this.tryToLog(MessageType.WARNING, "Failed before logging teardown because: %s", e.getMessage());
}

// Log the test result
Expand Down Expand Up @@ -309,10 +306,9 @@ protected Logger createLogger() {
this.setLoggedExceptions(new ArrayList<String>());

if (this.loggingEnabledSetting != LoggingEnabled.NO) {
log = LoggingConfig.getLogger(StringProcessor
.safeFormatter("%s - %s", this.fullyQualifiedTestClassName.get(),
DateTimeFormatter.ofPattern("uuuu-MM-dd-HH-mm-ss-SSSS", Locale.getDefault())
.format(LocalDateTime.now(Clock.systemUTC()))));
log = LoggingConfig.getLogger(StringProcessor.safeFormatter("%s - %s", this.fullyQualifiedTestClassName.get(),
DateTimeFormatter.ofPattern("uuuu-MM-dd-HH-mm-ss-SSSS", Locale.getDefault())
.format(LocalDateTime.now(Clock.systemUTC()))));
} else {
log = new ConsoleLogger();
}
Expand Down Expand Up @@ -405,8 +401,7 @@ protected void logVerbose(String message, Object... args) {

for (StackTraceElement element : Thread.currentThread().getStackTrace()) {
// If the stack trace element is from the com.magenic package (excluding this method) append the stack trace line
if (element.toString().startsWith("com.magenic") && !element.toString()
.contains("BaseTest.logVerbose")) {
if (element.toString().startsWith("com.magenic") && !element.toString().contains("BaseTest.logVerbose")) {
messages.append(element.toString() + System.lineSeparator());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package com.magenic.jmaqs.base;

import com.magenic.jmaqs.base.exceptions.DriverDisposalException;
import com.magenic.jmaqs.utilities.helper.StringProcessor;
import com.magenic.jmaqs.utilities.logging.Logger;
import com.magenic.jmaqs.utilities.logging.MessageType;
import com.magenic.jmaqs.utilities.performance.PerfTimerCollection;
Expand Down Expand Up @@ -315,7 +317,7 @@ public void close() {
try {
singleDriver.close();
} catch (final Exception e) {
e.printStackTrace();
throw new DriverDisposalException(StringProcessor.safeFormatter("Unable to properly dispose of driver"), e);
}
}
this.managerStore = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

/**
* The type Driver manager.
* @param <T> Manager of type T
*/
public abstract class DriverManager<T> implements AutoCloseable {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package com.magenic.jmaqs.base;

import com.magenic.jmaqs.base.exceptions.ManagerDisposalException;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -23,7 +24,7 @@ public void clear() {
try {
entry.getValue().close();
} catch (Exception e) {
e.printStackTrace();
throw new ManagerDisposalException(e);
}
}
super.clear();
Expand Down Expand Up @@ -81,7 +82,7 @@ public boolean remove(String key) {
try {
this.get(key).close();
} catch (Exception e) {
e.printStackTrace();
throw new ManagerDisposalException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright 2020 (C) Magenic, All rights Reserved
*/

package com.magenic.jmaqs.base.exceptions;

public class DriverDisposalException extends RuntimeException {
public DriverDisposalException(String message, Exception exception) {
super(message, exception);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright 2020 (C) Magenic, All rights Reserved
*/

package com.magenic.jmaqs.base.exceptions;

public class ManagerDisposalException extends RuntimeException {
public ManagerDisposalException(Exception e) {
super(e);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ private DatabaseConfig() {
/**
* The Database section.
*/
private static final ConfigSection DATABASE_SECTION = ConfigSection.DatabaseMaqs;
private static final ConfigSection DATABASE_SECTION = ConfigSection.DATABASE_MAQS;

/**
* Field DATABASE_CAPS_SECTION.
*/
private static final ConfigSection DATABASE_CAPS_SECTION = ConfigSection.DatabaseCapsMaqs;
private static final ConfigSection DATABASE_CAPS_SECTION = ConfigSection.DATABASE_CAPS_MAQS;

/**
* Gets connection string.
Expand Down
Loading

0 comments on commit 5f95dee

Please sign in to comment.