Skip to content

Commit

Permalink
add a unit test that checks packages when endpoint is used
Browse files Browse the repository at this point in the history
  • Loading branch information
mshabarov committed Dec 19, 2024
1 parent c9b5c97 commit 9a1c149
Showing 1 changed file with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,37 @@ public void getDefaultDependencies_hillaIsNotUsed_doesntAddHillaComponents() {
defaultDevDeps.containsKey("lit-dev-dependency"));
}

@Test
public void getDefaultDependencies_endpointsAreUsed_addsHillaPackages() {
try (MockedStatic<FrontendUtils> utilsMock = Mockito
.mockStatic(FrontendUtils.class)) {
utilsMock.when(
() -> FrontendUtils.isHillaUsed(Mockito.any(File.class),
Mockito.any(ClassFinder.class)))
.thenReturn(false);

utilsMock
.when(() -> FrontendUtils
.areEndpointsUsed(Mockito.any(Options.class)))
.thenReturn(false);
Map<String, String> defaultDeps = nodeUpdater
.getDefaultDependencies();
Assert.assertFalse(
"Hilla dev dependency added unexpectedly when no endpoints are used",
defaultDeps.containsKey("react-dev-dependency"));

utilsMock
.when(() -> FrontendUtils
.areEndpointsUsed(Mockito.any(Options.class)))
.thenReturn(true);
Map<String, String> defaultDevDeps = nodeUpdater
.getDefaultDevDependencies();
Assert.assertTrue(
"Hilla dev dependency is expected when endpoints are used",
defaultDevDeps.containsKey("react-dev-dependency"));
}
}

@Test
public void readPackageJson_nonExistingFile_doesNotThrow()
throws IOException {
Expand Down

0 comments on commit 9a1c149

Please sign in to comment.