Skip to content

Commit

Permalink
Merge branch 'staging' into remake_events_module
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtursKadikis authored Sep 22, 2023
2 parents 9dc9fe3 + b35a08f commit 2624930
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 14 deletions.
21 changes: 17 additions & 4 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
name: Java Gradle Build and Test

permissions:
checks: write
pull-requests: write

on:
push:
branches:
Expand All @@ -16,15 +20,24 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Checkout code
uses: actions/checkout@v4

- name: Set up JDK 8
uses: actions/setup-java@v3
with:
java-version: '8'
distribution: 'corretto'

- name: Build with Gradle
uses: gradle/gradle-build-action@749f47bda3e44aa060e82d7b3ef7e40d953bd629
- name: Build and Test with Gradle
run: ./gradlew build

- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
arguments: build
check_name: "Unit Test Results :rocket:"
comment_title: "Unit Test Results :rocket:"
files: |
sdk-java/build/test-results/**/*.xml
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ protected String readEventQueue() {
String eventQueue = "";

try {
eventQueue = Utils.readFileContent(file);
eventQueue = Utils.readFileContent(file, L);
} catch (IOException e) {
// Handle the error if reading fails
L.e("[SDKStorage] Failed to read EQ from json file: " + e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,8 @@ public Boolean call() throws Exception {
}

public static void stop() {
tasks.shutdown();
if (tasks != null) {
tasks.shutdown();
}
}
}
9 changes: 8 additions & 1 deletion sdk-java/src/main/java/ly/count/sdk/java/internal/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,20 @@ public static boolean isValidDataType(Object value) {
* If file doesn't exist, return empty string
*
* @param file to read
* @param logger to log errors
* @return file contents or empty string
* @throws IOException if file exists but couldn't be read
*/
public static String readFileContent(File file) throws IOException {
public static String readFileContent(File file, Log logger) throws IOException {
StringBuilder fileContent = new StringBuilder();

if (!file.exists()) {
logger.v("[Utils] readFileContent : File doesn't exist: " + file.getAbsolutePath() + ". returning empty string");
return fileContent.toString();
}

if (!file.canRead()) {
logger.v("[Utils] readFileContent : File exists but can't be read: " + file.getAbsolutePath() + ". returning empty string");
return fileContent.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

public class TestUtils {

private static String DELIMETER = ":::";

private TestUtils() {
}

Expand Down Expand Up @@ -73,7 +75,7 @@ protected static List<EventImpl> getCurrentEventQueue(File targetFolder, Log log
File file = new File(targetFolder, FILE_NAME_PREFIX + FILE_NAME_SEPARATOR + EVENT_QUEUE_FILE_NAME);
String fileContent = "";
try {
fileContent = Utils.readFileContent(file);
fileContent = Utils.readFileContent(file, logger);
} catch (IOException e) {
//do nothing
}
Expand Down Expand Up @@ -148,4 +150,4 @@ private static Map<String, String> parseRequestParams(File file) throws IOExcept
return paramMap;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public void readFileContent() throws IOException {
writer.write(fileContent);
writer.close();

String result = Utils.readFileContent(file);
String result = Utils.readFileContent(file, logger);
//delete file
file.delete();
Assert.assertEquals(fileContent, result);
Expand All @@ -272,17 +272,17 @@ public void readFileContent_fileNotExist() throws IOException {

File file = new File(fileName);

String result = Utils.readFileContent(file);
String result = Utils.readFileContent(file, logger);

Assert.assertNotEquals(fileContent, result);
Assert.assertEquals("", result);
}

/**
* If the file is not readable for some reason,
* the method should throw exception.
* the method should return empty string.
*/
@Test(expected = IOException.class)
@Test
public void readFileContent_fileNotReadable() throws IOException {
try {
String fileContent = "testContent";
Expand All @@ -294,7 +294,8 @@ public void readFileContent_fileNotReadable() throws IOException {
writer.close();
file.setReadable(false);

Utils.readFileContent(file);
String content = Utils.readFileContent(file, logger);
Assert.assertEquals("", content);
} finally {
File file = new File(TEST_FILE_NAME);
if (file.exists()) {
Expand Down

0 comments on commit 2624930

Please sign in to comment.