Skip to content

Commit

Permalink
apply spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
rezastallone committed Oct 11, 2023
1 parent d83f19b commit 932ed8a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,17 @@ Stream<File> listFilesRecursively(File directory) {
return Stream.empty();
}
File[] files = directory.listFiles();
if (files == null){
if (files == null) {
return Stream.empty();
}
Stream<File> directories = Stream.of(files).filter(File::isDirectory);
Stream<File> plainFiles = Stream.of(files).filter(File::isFile);
return Stream.concat(plainFiles, directories.flatMap(this::listFilesRecursively));
}

Stream<File> listDirectories(File directory){
Stream<File> listDirectories(File directory) {
File[] files = directory.listFiles();
if (files == null){
if (files == null) {
return Stream.empty();
}
return Stream.of(files).filter(File::isDirectory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public StartTypeAwareSpanStorage(
this.rootDir = rootDir;
this.spanDir = fileUtils.getSpansDirectory(rootDir);
this.uniqueId = UUID.randomUUID().toString();
//if new id then background span directory with old ids can be deleted
// if new id then background span directory with old ids can be deleted
cleanUpUnsentBackgroundSpan();
}

Expand All @@ -67,7 +67,9 @@ public Stream<File> getPendingFiles() {
}

private boolean isAppForeground() {
return (visibleScreenTracker.getCurrentlyVisibleScreen() != null && !visibleScreenTracker.getCurrentlyVisibleScreen().equals("unknown")) || visibleScreenTracker.getPreviouslyVisibleScreen() != null;
return (visibleScreenTracker.getCurrentlyVisibleScreen() != null
&& !visibleScreenTracker.getCurrentlyVisibleScreen().equals("unknown"))
|| visibleScreenTracker.getPreviouslyVisibleScreen() != null;
}

private void moveBackgroundSpanToPendingSpan() {
Expand Down Expand Up @@ -98,14 +100,10 @@ public File provideSpanFile() {

private File getSpanFile() {
if (!isAppForeground()) {
Log.d(
LOG_TAG,
"Creating background span " + uniqueId);
Log.d(LOG_TAG, "Creating background span " + uniqueId);
return getCurrentSessionBackgroundFile();
}
Log.d(
LOG_TAG,
"Creating foreground span " + uniqueId);
Log.d(LOG_TAG, "Creating foreground span " + uniqueId);
return spanDir;
}

Expand All @@ -119,17 +117,20 @@ private File ensureDirExist(File pathToReturn) {
return rootDir;
}

private void cleanUpUnsentBackgroundSpan(){
fileUtils.listDirectories(new File(spanDir, "background/"))
.filter(file -> {
String path = file.getPath();
String pathId = path.substring(path.lastIndexOf("/") + 1);
return !pathId.equals(uniqueId);
})
.forEach(file -> {
Log.d(SplunkRum.LOG_TAG, "Cleaning up " + file.getPath());
fileUtils.listFilesRecursively(file).forEach(fileUtils::safeDelete);
fileUtils.safeDelete(file);
});
private void cleanUpUnsentBackgroundSpan() {
fileUtils
.listDirectories(new File(spanDir, "background/"))
.filter(
file -> {
String path = file.getPath();
String pathId = path.substring(path.lastIndexOf("/") + 1);
return !pathId.equals(uniqueId);
})
.forEach(
file -> {
Log.d(SplunkRum.LOG_TAG, "Cleaning up " + file.getPath());
fileUtils.listFilesRecursively(file).forEach(fileUtils::safeDelete);
fileUtils.safeDelete(file);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand All @@ -31,7 +30,6 @@
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
Expand All @@ -52,7 +50,7 @@ void setup() {
}

@Test
void constructor_onNewId_shouldCleanOldBackgroundFiles(){
void constructor_onNewId_shouldCleanOldBackgroundFiles() {
File file = mock();
when(file.getPath()).thenReturn("files/spans/background/123");
when(fileUtils.listDirectories(any())).thenReturn(Stream.of(file));
Expand All @@ -73,7 +71,8 @@ void getPendingFiles_givenInBackground_shouldReturnForegoundOnlySpan() {
}

@Test
void getPendingFiles_givenPrevouslyInBackground_shouldMoveBackgroundSpanToForegroundSpanForSending() {
void
getPendingFiles_givenPrevouslyInBackground_shouldMoveBackgroundSpanToForegroundSpanForSending() {
when(visibleScreenTracker.getPreviouslyVisibleScreen()).thenReturn("MainActivity");
when(visibleScreenTracker.getCurrentlyVisibleScreen()).thenReturn("MainActivity");

Expand Down

0 comments on commit 932ed8a

Please sign in to comment.