Skip to content

Commit

Permalink
fixed sonar comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AEkaterina committed Oct 19, 2023
1 parent 21e2747 commit b2e6e7e
Show file tree
Hide file tree
Showing 46 changed files with 119 additions and 147 deletions.
2 changes: 2 additions & 0 deletions src/test/java/constants/RegEx.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ public class RegEx {
public static final String PAGE_NUMBER_REGEX_FOR_ANDROID = "Page (\\d+) of (\\d+)";
public static final String VALID_PUBLISHER_OR_CATEGORY_NAME = "([a-zA-Z0-9&\\s-,;'./]*)([a-zA-Z,&\\s;:'.]*)([a-zA-Z0-9,\\s-'.]*)";
public static final String DATE_TIME_FORMAT = "y-M-dd HH:m:s";

private RegEx() { }
}
5 changes: 2 additions & 3 deletions src/test/java/constants/appattributes/AndroidAttributes.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package constants.appattributes;

import lombok.experimental.UtilityClass;

@UtilityClass
public class AndroidAttributes {
public static final String CONTENT_DESC = "content-desc";
public static final String TEXT = "text";
public static final String SELECTED = "selected";
public static final String CHECKED = "checked";

private AndroidAttributes() { }
}
5 changes: 2 additions & 3 deletions src/test/java/constants/appattributes/IosAttributes.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package constants.appattributes;

import lombok.experimental.UtilityClass;

@UtilityClass
public class IosAttributes {
public static final String NAME = "name";
public static final String VALUE = "value";
public static final String VISIBLE = "visible";

private IosAttributes() {}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package constants.keysForContext;
package constants.keysforcontext;

public class ScenarioContextKey {
public static final String SCENARIO_KEY = "SCENARIO";
public static final String LIST_OF_CREDENTIALS_KEY = "CREDENTIALS";

private ScenarioContextKey() { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
public class BookActionButtonNames {
public static final String GET_BUTTON_NAME = "Get";
public static final String DOWNLOAD_BUTTON_NAME = "Download";

private BookActionButtonNames() { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public abstract class AbstractILocalizationProvider implements ILocalizationProv
*/
private final String filename;

public AbstractILocalizationProvider(@NonNull String filename) {
protected AbstractILocalizationProvider(@NonNull String filename) {
localizationController = new LocalizationController(StandardCharsets.UTF_8);
this.filename = filename;
bundles.put(DEFAULT_LOCALE, ResourceBundle
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package constants.localization.providers;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
Expand All @@ -18,6 +19,7 @@ public LocalizationController(Charset charset) {
this.charset = charset;
}

@Override
public ResourceBundle newBundle(String baseName, Locale locale, String format,
ClassLoader loader, boolean reload) throws IOException {
String bundleName = toBundleName(baseName, locale);
Expand All @@ -37,8 +39,9 @@ public ResourceBundle newBundle(String baseName, Locale locale, String format,
stream = loader.getResourceAsStream(resourceName);
}
if (stream != null) {
try {
bundle = new PropertyResourceBundle(new InputStreamReader(stream, charset));
try(InputStreamReader inputStreamReader = new InputStreamReader(stream, charset);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader)) {
bundle = new PropertyResourceBundle(bufferedReader);
} finally {
stream.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
public class LocalizationProviderFactory {
private static Map<String, AbstractILocalizationProvider> providers = new ConcurrentHashMap<>();

private LocalizationProviderFactory () { }

public static AbstractILocalizationProvider getProvider(String fileName) {
return providers.computeIfAbsent(fileName, v -> new AbstractILocalizationProvider(v) {
// default
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/constants/util/UtilConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ public class UtilConstants {
public static final String PALACE_MARKETPLACE = "palace marketplace";
public static final String PALACE_MARKETPLACE_CATEGORY = "Palace Marketplace Test";
public static final String PALACE_BOOKSHELF = "Palace Bookshelf";

private UtilConstants() { }
}
4 changes: 2 additions & 2 deletions src/test/java/enums/BookType.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ public enum BookType {
AUDIOBOOK("audiobook"),
PDF("pdf");

private String bookType;
private String currentBookType;

public String getBookType() {
return bookType;
return currentBookType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
public class ConfigurationStorage {
private static Map<Long, String> map = new ConcurrentHashMap<>();

private ConfigurationStorage() {}

public static synchronized void lockCredentials(String barcode) {
AqualityServices.getLogger().info("Locking credential with barcode " + barcode);
map.put(Thread.currentThread().getId(), barcode);
Expand Down
1 change: 1 addition & 0 deletions src/test/java/framework/configuration/Credentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

@Data
public class Credentials {

private String barcode;
private String pin;

Expand Down
2 changes: 2 additions & 0 deletions src/test/java/framework/utilities/ActionProcessorUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public class ActionProcessorUtils {

private static final PlatformName PLATFORM_NAME = AqualityServices.getApplication().getPlatformName();

private ActionProcessorUtils() {}

private static void doForPlatform(PlatformName platformName, Runnable action) {
if(PLATFORM_NAME.equals(platformName)) {
action.run();
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/framework/utilities/DateUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import java.util.List;

public class DateUtils {

private DateUtils() {}
public static Duration getDuration(String date) {
String formattedString = "";
List<String> parts = Arrays.asList(date.split(":"));
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/framework/utilities/LocatorUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public class LocatorUtils {

private static final PlatformName PLATFORM_NAME = AqualityServices.getApplication().getPlatformName();

private LocatorUtils() {}

public static By getLocator(AndroidLocator androidLocator, IosLocator iosLocator) {
switch (PLATFORM_NAME) {
case ANDROID:
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/framework/utilities/PlatformUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

public class PlatformUtils {

private PlatformUtils() {}

public static PlatformName getPlatformName() {
return AqualityServices.getApplication().getPlatformName();
}
Expand Down
6 changes: 4 additions & 2 deletions src/test/java/framework/utilities/RegExUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

public class RegExUtil {

private RegExUtil() {}

public static String deleteBracketsFromText(String text) {
text = text.replaceAll("\\(", "");
text = text.replaceAll("\\)", "");
text = text.replace("\\(", "");
text = text.replace("\\)", "");
return text;
}

Expand Down
2 changes: 2 additions & 0 deletions src/test/java/framework/utilities/ScreenshotUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.openqa.selenium.OutputType;

public class ScreenshotUtils {

private ScreenshotUtils() {}
public static byte[] getScreenshot() {
AqualityServices.getApplication().getDriver().getPageSource();
return AqualityServices.getApplication().getDriver().getScreenshotAs(OutputType.BYTES);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package framework.utilities.feedXMLUtil;
package framework.utilities.feedxmlutil;

import java.util.Objects;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package framework.utilities.feedXMLUtil;
package framework.utilities.feedxmlutil;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
Expand Down Expand Up @@ -180,7 +180,7 @@ public void setCountAvailableCopies(int countAvailableCopies) {

class IndirectAcquisition{
private String type;
private InternalIndirectAcquisition indirectAcquisition;
private InternalIndirectAcquisition internalIndirectAcquisition;

public String getType() {
return type;
Expand All @@ -192,12 +192,12 @@ public void setType(String type) {
}

public InternalIndirectAcquisition getInternalIndirectAcquisition() {
return indirectAcquisition;
return internalIndirectAcquisition;
}

@XmlElement(name = "indirectAcquisition", namespace = "http://opds-spec.org/2010/catalog")
public void setInternalIndirectAcquisition(InternalIndirectAcquisition indirectAcquisition) {
this.indirectAcquisition = indirectAcquisition;
this.internalIndirectAcquisition = indirectAcquisition;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package framework.utilities.feedXMLUtil;
package framework.utilities.feedxmlutil;

public class GettingBookUtil {
private static XMLUtil xmlUtil;

private GettingBookUtil() {}

public static synchronized void setXmlUtil(XMLUtil xml){
xmlUtil = xml;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package framework.utilities.feedXMLUtil;
package framework.utilities.feedxmlutil;

import retrofit2.Call;
import retrofit2.http.GET;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package framework.utilities.feedXMLUtil;
package framework.utilities.feedxmlutil;

import aquality.appium.mobile.application.AqualityServices;
import constants.util.UtilConstants;
Expand All @@ -15,42 +15,43 @@
import java.util.stream.Collectors;

public class XMLUtil {
private static final String SEPARATOR_LINE = "//////////////////////////////////////////////////////////////////////////////////////";
private static final String BASE_URL = "https://gorgon.tpp-qa.lyrasistechnology.org";
private static final String partOfURL = "lyrasis-reads/crawlable";
private static final String PART_OF_URL = "lyrasis-reads/crawlable";
private HashMap<String, List<BookModel>> hashMapAvailableEbooks;
private HashMap<String, List<BookModel>> hashMapAvailableAudiobooks;
private HashMap<String, List<BookModel>> hashMapUnavailableEbooks;
private HashMap<String, List<BookModel>> hashMapUnavailableAudiobooks;
private ArrayList<BookModel> availableBooksAnyType;
private ArrayList<BookModel> unavailableBooksAnyType;
private ArrayList<BookModel> availablePdf;
private final int CONNECT_TIMEOUT = 120;
private final int READ_TIMEOUT = 120;
private final int WRITE_TIMEOUT = 120;
private final int THREAD_SLEEP_TIME = 3000;
private static final int CONNECT_TIMEOUT = 120;
private static final int READ_TIMEOUT = 120;
private static final int WRITE_TIMEOUT = 120;
private static final int THREAD_SLEEP_TIME = 3000;

public XMLUtil() {
setHashMapsForEBooksAndAudioBooks();
}

public void getDistributorsInfo(){
AqualityServices.getLogger().info("//////////////////////////////////////////////////////////////////////////////////////");
AqualityServices.getLogger().info(SEPARATOR_LINE);
for (String distributor : hashMapAvailableAudiobooks.keySet()) {
printDistributorInfo("hashMapAvailableAudiobooks", distributor, hashMapAvailableAudiobooks.get(distributor));
}
AqualityServices.getLogger().info("//////////////////////////////////////////////////////////////////////////////////////");
AqualityServices.getLogger().info(SEPARATOR_LINE);
for (String distributor : hashMapAvailableEbooks.keySet()) {
printDistributorInfo("hashMapAvailableEbooks", distributor, hashMapAvailableEbooks.get(distributor));
}
AqualityServices.getLogger().info("//////////////////////////////////////////////////////////////////////////////////////");
AqualityServices.getLogger().info(SEPARATOR_LINE);
for (String distributor : hashMapUnavailableAudiobooks.keySet()) {
printDistributorInfo("hashMapUnavailableAudiobooks", distributor, hashMapUnavailableAudiobooks.get(distributor));
}
AqualityServices.getLogger().info("//////////////////////////////////////////////////////////////////////////////////////");
AqualityServices.getLogger().info(SEPARATOR_LINE);
for (String distributor : hashMapUnavailableEbooks.keySet()) {
printDistributorInfo("hashMapUnavailableEbooks", distributor, hashMapUnavailableEbooks.get(distributor));
}
AqualityServices.getLogger().info("//////////////////////////////////////////////////////////////////////////////////////");
AqualityServices.getLogger().info(SEPARATOR_LINE);
}

private void printDistributorInfo(String text, String distributor, List<BookModel> list){
Expand All @@ -62,15 +63,14 @@ private void printDistributorInfo(String text, String distributor, List<BookMode
}

private void setListAvailableAndUnavailableBooksAnyTypeMayBeWithRepeat() {
String url = partOfURL;
String url = PART_OF_URL;
ArrayList<BookModel> listAvailableBooksAnyType = new ArrayList<>();
ArrayList<BookModel> listUnavailableBooksAnyType = new ArrayList<>();
ArrayList<BookModel> listAvailablePdf = new ArrayList<>();

while (true) {
FeedModel feedModel = supportMethod(url);
boolean isNextXMLPresent = feedModel.getLinksFromFeed().stream().anyMatch(link -> link.getConditionForNextXML().equals(UtilConstants.NEXT.toLowerCase()));
if (!isNextXMLPresent) {
if (!hasNextXML(feedModel)) {
break;
}

Expand Down Expand Up @@ -156,6 +156,11 @@ private void setListAvailableAndUnavailableBooksAnyTypeMayBeWithRepeat() {
availablePdf = getListAvailablePdfWithoutRepetitions(listAvailablePdf);
}

private boolean hasNextXML(FeedModel feedModel) {
return feedModel.getLinksFromFeed().stream()
.anyMatch(link -> link.getConditionForNextXML().equals(UtilConstants.NEXT.toLowerCase()));
}

private ArrayList<BookModel> getListAvailablePdfWithoutRepetitions(ArrayList<BookModel> arrayList) {
Set<BookModel> setAvailablePdf = new HashSet<>(arrayList);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package framework.utilities.returningBooksUtil;
package framework.utilities.returningbooksutil;


import javax.xml.bind.annotation.XmlAttribute;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package framework.utilities.returningBooksUtil;
package framework.utilities.returningbooksutil;

import aquality.appium.mobile.application.AqualityServices;
import framework.configuration.Credentials;
Expand All @@ -15,6 +15,9 @@

public class APIUtil {
private static final PropertyUtils propertyUtils = new PropertyUtils("src/test/resources/apiConfig.properties");
private static final String PROPERTY_BASE_URL = "base_url";

private APIUtil() { }

public static void returnBooks(Credentials credentials) {
String authHeader = getAuthHeader(credentials);
Expand Down Expand Up @@ -43,14 +46,14 @@ private static void sendRequestsForReturningBooks(String authHeader, ArrayList<S
OkHttpClient client = makeHttpClient();
ReturnBooksAPIMethods getBooksAPIMethods = new Retrofit
.Builder()
.baseUrl(propertyUtils.getProperty("base_url"))
.baseUrl(propertyUtils.getProperty(PROPERTY_BASE_URL))
.client(client)
.build()
.create(ReturnBooksAPIMethods.class);

if (booksForReturning.size() != 0) {
if (!booksForReturning.isEmpty()) {
for (String bookUrl : booksForReturning) {
String path = bookUrl.replace(propertyUtils.getProperty("base_url"), "");
String path = bookUrl.replace(propertyUtils.getProperty(PROPERTY_BASE_URL), "");
try {
getBooksAPIMethods.returnBooks(authHeader, path).execute();
} catch (IOException e) {
Expand All @@ -72,7 +75,7 @@ private static ArrayList<String> getListOfBooksInAccount(String authHeader) {
OkHttpClient client = makeHttpClient();
GetBooksAPIMethods getBooksAPIMethods = new Retrofit
.Builder()
.baseUrl(propertyUtils.getProperty("base_url"))
.baseUrl(propertyUtils.getProperty(PROPERTY_BASE_URL))
.addConverterFactory(JaxbConverterFactory.create())
.client(client)
.build()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package framework.utilities.returningBooksUtil;
package framework.utilities.returningbooksutil;

import retrofit2.Call;
import retrofit2.http.GET;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package framework.utilities.returningBooksUtil;
package framework.utilities.returningbooksutil;

import okhttp3.ResponseBody;
import retrofit2.Call;
Expand Down
Loading

0 comments on commit b2e6e7e

Please sign in to comment.