Skip to content

Commit

Permalink
Tweak errors thrown and test for them
Browse files Browse the repository at this point in the history
  • Loading branch information
Vankka committed Dec 13, 2024
1 parent 906c43a commit d976727
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,9 @@ public CompletableFuture<Void>[] load(@Nullable Executor executor, @NotNull Clas
// If step is 1 (download), 2 (relocate) change to 3 (load), otherwise keep current
int currentStep = step.getAndUpdate(current -> current == 0 || current == 3 ? current : 3);
if (currentStep == 0) {
throw new IllegalArgumentException("Download hasn't been executed");
throw new IllegalStateException("Download hasn't been executed");
} else if (currentStep == 3) {
throw new IllegalArgumentException("Already loaded");
throw new IllegalStateException("Already loaded");
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,21 @@ public void test() {
assertEquals(Collections.singletonList(REAL_DEPENDENCY), dependencyManager.getDependencies(), "dependencies match");
assertEquals(Collections.singletonList(REAL_RELOCATION), dependencyManager.getRelocations(), "relocations match");

assertThrows(IllegalArgumentException.class, () -> dependencyManager.downloadAll(null, Collections.emptyList()));
assertThrows(IllegalStateException.class, () -> dependencyManager.relocateAll(null));
assertThrows(IllegalStateException.class, () -> dependencyManager.loadAll(null, url -> fail("Load classpath appender called")));

CompletableFuture<Void> download = dependencyManager.downloadAll(null, Collections.singletonList(REAL_REPOSITORY));
assertNotNull(download, "download future is not null");
assertTrue(download.isDone(), "download future is done");
assertFalse(download.isCompletedExceptionally(), "download did not fail");
assertThrows(IllegalStateException.class, () -> dependencyManager.downloadAll(null, Collections.singletonList(REAL_REPOSITORY)));

CompletableFuture<Void> relocate = dependencyManager.relocateAll(null);
assertNotNull(relocate, "relocate future is not null");
assertTrue(relocate.isDone(), "relocate future is done");
assertFalse(relocate.isCompletedExceptionally(), "relocate did not fail");
assertThrows(IllegalStateException.class, () -> dependencyManager.relocateAll(null));

AtomicInteger calledTimes = new AtomicInteger(0);
CompletableFuture<Void> load = dependencyManager.loadAll(null, url -> calledTimes.incrementAndGet());
Expand All @@ -98,6 +104,7 @@ public void test() {
assertFalse(load.isCompletedExceptionally(), "load did not fail");
assertEquals(1, calledTimes.get(), "ClasspathAppender called only once");
assertTrue(dependencyManager.isLoaded(), "DependencyManager.isLoaded");
assertThrows(IllegalStateException.class, () -> dependencyManager.loadAll(null, url -> fail("Load classpath appender called")));
}

@Test
Expand Down

0 comments on commit d976727

Please sign in to comment.