From 9fefb00503b3950a721aaf3909d9991b258abd74 Mon Sep 17 00:00:00 2001 From: Ashley Scopes <73482956+ascopes@users.noreply.github.com> Date: Sun, 12 Feb 2023 12:34:30 +0000 Subject: [PATCH] Add location helpers in JctFileManager Add methods such as .getClassOutputGroup() for all StandardLocation members. --- .../acceptance-tests-avaje-inject/pom.xml | 2 +- .../acceptance-tests-avaje-jsonb/pom.xml | 2 +- .../acceptance-tests-checkerframework/pom.xml | 2 +- .../acceptance-tests-dagger/pom.xml | 2 +- .../acceptance-tests-dogfood/pom.xml | 2 +- .../acceptance-tests-error-prone/pom.xml | 2 +- .../pom.xml | 2 +- .../pom.xml | 2 +- .../pom.xml | 2 +- .../acceptance-tests-immutables/pom.xml | 2 +- .../acceptance-tests-lombok/pom.xml | 2 +- .../acceptance-tests-mapstruct/pom.xml | 2 +- .../acceptance-tests-micronaut/pom.xml | 2 +- .../pom.xml | 2 +- .../acceptance-tests-serviceloader/pom.xml | 2 +- .../acceptance-tests-spring/pom.xml | 2 +- acceptance-tests/pom.xml | 2 +- java-compiler-testing/pom.xml | 2 +- .../jct/filemanagers/JctFileManager.java | 153 +++++++++ .../ascopes/jct/junit/JavacCompilerTest.java | 2 +- .../unit/filemanagers/JctFileManagerTest.java | 292 ++++++++++++++++++ pom.xml | 2 +- 22 files changed, 465 insertions(+), 20 deletions(-) create mode 100644 java-compiler-testing/src/test/java/io/github/ascopes/jct/tests/unit/filemanagers/JctFileManagerTest.java diff --git a/acceptance-tests/acceptance-tests-avaje-inject/pom.xml b/acceptance-tests/acceptance-tests-avaje-inject/pom.xml index 43b656c42..5a39ebdef 100644 --- a/acceptance-tests/acceptance-tests-avaje-inject/pom.xml +++ b/acceptance-tests/acceptance-tests-avaje-inject/pom.xml @@ -22,7 +22,7 @@ io.github.ascopes.jct acceptance-tests - 0.0.2-SNAPSHOT + 0.1.0-SNAPSHOT ../pom.xml diff --git a/acceptance-tests/acceptance-tests-avaje-jsonb/pom.xml b/acceptance-tests/acceptance-tests-avaje-jsonb/pom.xml index cc0a55b9f..bf17f95f5 100644 --- a/acceptance-tests/acceptance-tests-avaje-jsonb/pom.xml +++ b/acceptance-tests/acceptance-tests-avaje-jsonb/pom.xml @@ -22,7 +22,7 @@ io.github.ascopes.jct acceptance-tests - 0.0.2-SNAPSHOT + 0.1.0-SNAPSHOT ../pom.xml diff --git a/acceptance-tests/acceptance-tests-checkerframework/pom.xml b/acceptance-tests/acceptance-tests-checkerframework/pom.xml index c95e5af91..f3ea9ede3 100644 --- a/acceptance-tests/acceptance-tests-checkerframework/pom.xml +++ b/acceptance-tests/acceptance-tests-checkerframework/pom.xml @@ -22,7 +22,7 @@ io.github.ascopes.jct acceptance-tests - 0.0.2-SNAPSHOT + 0.1.0-SNAPSHOT ../pom.xml diff --git a/acceptance-tests/acceptance-tests-dagger/pom.xml b/acceptance-tests/acceptance-tests-dagger/pom.xml index a0ac9f26c..479fa8b85 100644 --- a/acceptance-tests/acceptance-tests-dagger/pom.xml +++ b/acceptance-tests/acceptance-tests-dagger/pom.xml @@ -22,7 +22,7 @@ io.github.ascopes.jct acceptance-tests - 0.0.2-SNAPSHOT + 0.1.0-SNAPSHOT ../pom.xml diff --git a/acceptance-tests/acceptance-tests-dogfood/pom.xml b/acceptance-tests/acceptance-tests-dogfood/pom.xml index feccb336d..dc96e39cd 100644 --- a/acceptance-tests/acceptance-tests-dogfood/pom.xml +++ b/acceptance-tests/acceptance-tests-dogfood/pom.xml @@ -22,7 +22,7 @@ io.github.ascopes.jct acceptance-tests - 0.0.2-SNAPSHOT + 0.1.0-SNAPSHOT ../pom.xml diff --git a/acceptance-tests/acceptance-tests-error-prone/pom.xml b/acceptance-tests/acceptance-tests-error-prone/pom.xml index 0f2ff0a02..5b23165e4 100644 --- a/acceptance-tests/acceptance-tests-error-prone/pom.xml +++ b/acceptance-tests/acceptance-tests-error-prone/pom.xml @@ -22,7 +22,7 @@ io.github.ascopes.jct acceptance-tests - 0.0.2-SNAPSHOT + 0.1.0-SNAPSHOT ../pom.xml diff --git a/acceptance-tests/acceptance-tests-google-auto-factory/pom.xml b/acceptance-tests/acceptance-tests-google-auto-factory/pom.xml index c0bc9ef65..1112512b0 100644 --- a/acceptance-tests/acceptance-tests-google-auto-factory/pom.xml +++ b/acceptance-tests/acceptance-tests-google-auto-factory/pom.xml @@ -22,7 +22,7 @@ io.github.ascopes.jct acceptance-tests - 0.0.2-SNAPSHOT + 0.1.0-SNAPSHOT ../pom.xml diff --git a/acceptance-tests/acceptance-tests-google-auto-service/pom.xml b/acceptance-tests/acceptance-tests-google-auto-service/pom.xml index bd9e1e619..f88873cd8 100644 --- a/acceptance-tests/acceptance-tests-google-auto-service/pom.xml +++ b/acceptance-tests/acceptance-tests-google-auto-service/pom.xml @@ -22,7 +22,7 @@ io.github.ascopes.jct acceptance-tests - 0.0.2-SNAPSHOT + 0.1.0-SNAPSHOT ../pom.xml diff --git a/acceptance-tests/acceptance-tests-google-auto-value/pom.xml b/acceptance-tests/acceptance-tests-google-auto-value/pom.xml index 22eb87c48..019d450f8 100644 --- a/acceptance-tests/acceptance-tests-google-auto-value/pom.xml +++ b/acceptance-tests/acceptance-tests-google-auto-value/pom.xml @@ -22,7 +22,7 @@ io.github.ascopes.jct acceptance-tests - 0.0.2-SNAPSHOT + 0.1.0-SNAPSHOT ../pom.xml diff --git a/acceptance-tests/acceptance-tests-immutables/pom.xml b/acceptance-tests/acceptance-tests-immutables/pom.xml index fc5fa817b..947261230 100644 --- a/acceptance-tests/acceptance-tests-immutables/pom.xml +++ b/acceptance-tests/acceptance-tests-immutables/pom.xml @@ -22,7 +22,7 @@ io.github.ascopes.jct acceptance-tests - 0.0.2-SNAPSHOT + 0.1.0-SNAPSHOT ../pom.xml diff --git a/acceptance-tests/acceptance-tests-lombok/pom.xml b/acceptance-tests/acceptance-tests-lombok/pom.xml index 98c30d7ed..96c9ece94 100644 --- a/acceptance-tests/acceptance-tests-lombok/pom.xml +++ b/acceptance-tests/acceptance-tests-lombok/pom.xml @@ -22,7 +22,7 @@ io.github.ascopes.jct acceptance-tests - 0.0.2-SNAPSHOT + 0.1.0-SNAPSHOT ../pom.xml diff --git a/acceptance-tests/acceptance-tests-mapstruct/pom.xml b/acceptance-tests/acceptance-tests-mapstruct/pom.xml index d2897fc07..78656d755 100644 --- a/acceptance-tests/acceptance-tests-mapstruct/pom.xml +++ b/acceptance-tests/acceptance-tests-mapstruct/pom.xml @@ -22,7 +22,7 @@ io.github.ascopes.jct acceptance-tests - 0.0.2-SNAPSHOT + 0.1.0-SNAPSHOT ../pom.xml diff --git a/acceptance-tests/acceptance-tests-micronaut/pom.xml b/acceptance-tests/acceptance-tests-micronaut/pom.xml index 193c521a7..af7f86ddc 100644 --- a/acceptance-tests/acceptance-tests-micronaut/pom.xml +++ b/acceptance-tests/acceptance-tests-micronaut/pom.xml @@ -22,7 +22,7 @@ io.github.ascopes.jct acceptance-tests - 0.0.2-SNAPSHOT + 0.1.0-SNAPSHOT ../pom.xml diff --git a/acceptance-tests/acceptance-tests-serviceloader-jpms/pom.xml b/acceptance-tests/acceptance-tests-serviceloader-jpms/pom.xml index 7500702bd..89127a6dc 100644 --- a/acceptance-tests/acceptance-tests-serviceloader-jpms/pom.xml +++ b/acceptance-tests/acceptance-tests-serviceloader-jpms/pom.xml @@ -22,7 +22,7 @@ io.github.ascopes.jct acceptance-tests - 0.0.2-SNAPSHOT + 0.1.0-SNAPSHOT ../pom.xml diff --git a/acceptance-tests/acceptance-tests-serviceloader/pom.xml b/acceptance-tests/acceptance-tests-serviceloader/pom.xml index a2ebd13b3..47acdd8c0 100644 --- a/acceptance-tests/acceptance-tests-serviceloader/pom.xml +++ b/acceptance-tests/acceptance-tests-serviceloader/pom.xml @@ -22,7 +22,7 @@ io.github.ascopes.jct acceptance-tests - 0.0.2-SNAPSHOT + 0.1.0-SNAPSHOT ../pom.xml diff --git a/acceptance-tests/acceptance-tests-spring/pom.xml b/acceptance-tests/acceptance-tests-spring/pom.xml index a6d81f9a6..34d520cc0 100644 --- a/acceptance-tests/acceptance-tests-spring/pom.xml +++ b/acceptance-tests/acceptance-tests-spring/pom.xml @@ -22,7 +22,7 @@ io.github.ascopes.jct acceptance-tests - 0.0.2-SNAPSHOT + 0.1.0-SNAPSHOT ../pom.xml diff --git a/acceptance-tests/pom.xml b/acceptance-tests/pom.xml index 184966089..e59e8a75e 100644 --- a/acceptance-tests/pom.xml +++ b/acceptance-tests/pom.xml @@ -22,7 +22,7 @@ io.github.ascopes.jct java-compiler-testing-parent - 0.0.2-SNAPSHOT + 0.1.0-SNAPSHOT ../pom.xml diff --git a/java-compiler-testing/pom.xml b/java-compiler-testing/pom.xml index 2831e7688..6568fd401 100644 --- a/java-compiler-testing/pom.xml +++ b/java-compiler-testing/pom.xml @@ -22,7 +22,7 @@ io.github.ascopes.jct java-compiler-testing-parent - 0.0.2-SNAPSHOT + 0.1.0-SNAPSHOT ../pom.xml diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/JctFileManager.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/JctFileManager.java index ceda81d18..e929b0cd8 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/JctFileManager.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/filemanagers/JctFileManager.java @@ -25,8 +25,10 @@ import javax.tools.JavaFileManager; import javax.tools.JavaFileObject; import javax.tools.JavaFileObject.Kind; +import javax.tools.StandardLocation; import org.apiguardian.api.API; import org.apiguardian.api.API.Status; +import org.jspecify.annotations.Nullable; /** * Extension around a {@link JavaFileManager} that allows adding of {@link PathRoot} objects to the @@ -163,4 +165,155 @@ Set list( Set kinds, boolean recurse ) throws IOException; + + /// + /// Default helper overrides + /// + + /** + * Get the location holding the {@link StandardLocation#CLASS_OUTPUT class outputs}. + * + * @return the location, or {@code null} if the location is not present in the file manager. + * @since 0.1.0 + */ + @Nullable + default OutputContainerGroup getClassOutputGroup() { + return getOutputContainerGroup(StandardLocation.CLASS_OUTPUT); + } + + /** + * Get the location holding the {@link StandardLocation#SOURCE_OUTPUT source outputs}. + * + * @return the location, or {@code null} if the location is not present in the file manager. + * @since 0.1.0 + */ + @Nullable + default OutputContainerGroup getSourceOutputGroup() { + return getOutputContainerGroup(StandardLocation.SOURCE_OUTPUT); + } + + /** + * Get the location holding the {@link StandardLocation#CLASS_PATH class path}. + * + * @return the location, or {@code null} if the location is not present in the file manager. + * @since 0.1.0 + */ + @Nullable + default PackageContainerGroup getClassPathGroup() { + return getPackageContainerGroup(StandardLocation.CLASS_PATH); + } + + /** + * Get the location holding the {@link StandardLocation#SOURCE_PATH source path}. + * + * @return the location, or {@code null} if the location is not present in the file manager. + * @since 0.1.0 + */ + @Nullable + default PackageContainerGroup getSourcePathGroup() { + return getPackageContainerGroup(StandardLocation.SOURCE_PATH); + } + + /** + * Get the location holding the + * {@link StandardLocation#ANNOTATION_PROCESSOR_PATH annotation processor path}. + * + * @return the location, or {@code null} if the location is not present in the file manager. + * @since 0.1.0 + */ + @Nullable + default PackageContainerGroup getAnnotationProcessorPathGroup() { + return getPackageContainerGroup(StandardLocation.ANNOTATION_PROCESSOR_PATH); + } + + /** + * Get the location holding the + * {@link StandardLocation#ANNOTATION_PROCESSOR_MODULE_PATH annotation processor module path}. + * + * @return the location, or {@code null} if the location is not present in the file manager. + * @since 0.1.0 + */ + @Nullable + default ModuleContainerGroup getAnnotationProcessorModulePathGroup() { + return getModuleContainerGroup(StandardLocation.ANNOTATION_PROCESSOR_MODULE_PATH); + } + + /** + * Get the location holding the {@link StandardLocation#PLATFORM_CLASS_PATH platform class path} + * (also known as the boot class path). + * + * @return the location, or {@code null} if the location is not present in the file manager. + * @since 0.1.0 + */ + @Nullable + default PackageContainerGroup getPlatformClassPathGroup() { + return getPackageContainerGroup(StandardLocation.PLATFORM_CLASS_PATH); + } + + /** + * Get the location holding the + * {@link StandardLocation#NATIVE_HEADER_OUTPUT native header outputs}. + * + * @return the location, or {@code null} if the location is not present in the file manager. + * @since 0.1.0 + */ + @Nullable + default OutputContainerGroup getNativeHeaderOutputGroup() { + return getOutputContainerGroup(StandardLocation.NATIVE_HEADER_OUTPUT); + } + + /** + * Get the location holding the {@link StandardLocation#MODULE_SOURCE_PATH module source path}. + * + * @return the location, or {@code null} if the location is not present in the file manager. + * @since 0.1.0 + */ + @Nullable + default ModuleContainerGroup getModuleSourcePathGroup() { + return getModuleContainerGroup(StandardLocation.MODULE_SOURCE_PATH); + } + + /** + * Get the location holding the {@link StandardLocation#UPGRADE_MODULE_PATH upgrade module path}. + * + * @return the location, or {@code null} if the location is not present in the file manager. + * @since 0.1.0 + */ + @Nullable + default ModuleContainerGroup getUpgradeModulePathGroup() { + return getModuleContainerGroup(StandardLocation.UPGRADE_MODULE_PATH); + } + + /** + * Get the location holding the {@link StandardLocation#SYSTEM_MODULES system modules}. + * + * @return the location, or {@code null} if the location is not present in the file manager. + * @since 0.1.0 + */ + @Nullable + default ModuleContainerGroup getSystemModulesGroup() { + return getModuleContainerGroup(StandardLocation.SYSTEM_MODULES); + } + + /** + * Get the location holding the {@link StandardLocation#MODULE_PATH module path}. + * + * @return the location, or {@code null} if the location is not present in the file manager. + * @since 0.1.0 + */ + @Nullable + default ModuleContainerGroup getModulePathGroup() { + return getModuleContainerGroup(StandardLocation.MODULE_PATH); + } + + /** + * Get the location holding the {@link StandardLocation#PATCH_MODULE_PATH patch module path}. + * + * @return the location, or {@code null} if the location is not present in the file manager. + * @since 0.1.0 + */ + @Nullable + default ModuleContainerGroup getPatchModulePathGroup() { + return getModuleContainerGroup(StandardLocation.PATCH_MODULE_PATH); + } } diff --git a/java-compiler-testing/src/main/java/io/github/ascopes/jct/junit/JavacCompilerTest.java b/java-compiler-testing/src/main/java/io/github/ascopes/jct/junit/JavacCompilerTest.java index e3032ec97..52e822f9b 100644 --- a/java-compiler-testing/src/main/java/io/github/ascopes/jct/junit/JavacCompilerTest.java +++ b/java-compiler-testing/src/main/java/io/github/ascopes/jct/junit/JavacCompilerTest.java @@ -169,7 +169,7 @@ * @return {@code true} if we need to support modules, or {@code false} if we do not. * @deprecated this will be removed in a future release, since Java 8 is reaching end-of-life. */ - @Deprecated(forRemoval = true, since = "0.0.2") + @Deprecated(forRemoval = true, since = "0.1.0") boolean modules() default false; /** diff --git a/java-compiler-testing/src/test/java/io/github/ascopes/jct/tests/unit/filemanagers/JctFileManagerTest.java b/java-compiler-testing/src/test/java/io/github/ascopes/jct/tests/unit/filemanagers/JctFileManagerTest.java new file mode 100644 index 000000000..7ecc864a2 --- /dev/null +++ b/java-compiler-testing/src/test/java/io/github/ascopes/jct/tests/unit/filemanagers/JctFileManagerTest.java @@ -0,0 +1,292 @@ +/* + * Copyright (C) 2022 - 2023, the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.github.ascopes.jct.tests.unit.filemanagers; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; + +import io.github.ascopes.jct.containers.ModuleContainerGroup; +import io.github.ascopes.jct.containers.OutputContainerGroup; +import io.github.ascopes.jct.containers.PackageContainerGroup; +import io.github.ascopes.jct.filemanagers.JctFileManager; +import java.util.stream.Stream; +import javax.tools.StandardLocation; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +/** + * {@link JctFileManager tests}. + * + * @author Ashley Scopes + */ +@DisplayName("JctFileManager tests") +@ExtendWith(MockitoExtension.class) +class JctFileManagerTest { + + @Mock + JctFileManager fileManager; + + @DisplayName(".getClassOutputGroup() makes the expected call") + @MethodSource("outputContainerGroupResults") + @ParameterizedTest(name = "when internal getter returns {0}") + void getClassOutputGroupMakesTheExpectedCall(OutputContainerGroup expected) { + // Given + when(fileManager.getClassOutputGroup()).thenCallRealMethod(); + when(fileManager.getOutputContainerGroup(any())).thenReturn(expected); + + // When + var actual = fileManager.getClassOutputGroup(); + + // Then + verify(fileManager).getOutputContainerGroup(StandardLocation.CLASS_OUTPUT); + verifyNoMoreInteractions(fileManager); + assertThat(actual).isSameAs(expected); + } + + @DisplayName(".getSourceOutputGroup() makes the expected call") + @MethodSource("outputContainerGroupResults") + @ParameterizedTest(name = "when internal getter returns {0}") + void getSourceOutputGroupMakesTheExpectedCall(OutputContainerGroup expected) { + // Given + when(fileManager.getSourceOutputGroup()).thenCallRealMethod(); + when(fileManager.getOutputContainerGroup(any())).thenReturn(expected); + + // When + var actual = fileManager.getSourceOutputGroup(); + + // Then + verify(fileManager).getOutputContainerGroup(StandardLocation.SOURCE_OUTPUT); + verifyNoMoreInteractions(fileManager); + assertThat(actual).isSameAs(expected); + } + + @DisplayName(".getClassPathGroup() makes the expected call") + @MethodSource("outputContainerGroupResults") + @ParameterizedTest(name = "when internal getter returns {0}") + void getClassPathGroupMakesTheExpectedCall(PackageContainerGroup expected) { + // Given + when(fileManager.getClassPathGroup()).thenCallRealMethod(); + when(fileManager.getPackageContainerGroup(any())).thenReturn(expected); + + // When + var actual = fileManager.getClassPathGroup(); + + // Then + verify(fileManager).getPackageContainerGroup(StandardLocation.CLASS_PATH); + verifyNoMoreInteractions(fileManager); + assertThat(actual).isSameAs(expected); + } + + @DisplayName(".getSourcePathGroup() makes the expected call") + @MethodSource("outputContainerGroupResults") + @ParameterizedTest(name = "when internal getter returns {0}") + void getSourcePathGroupMakesTheExpectedCall(PackageContainerGroup expected) { + // Given + when(fileManager.getSourcePathGroup()).thenCallRealMethod(); + when(fileManager.getPackageContainerGroup(any())).thenReturn(expected); + + // When + var actual = fileManager.getSourcePathGroup(); + + // Then + verify(fileManager).getPackageContainerGroup(StandardLocation.SOURCE_PATH); + verifyNoMoreInteractions(fileManager); + assertThat(actual).isSameAs(expected); + } + + @DisplayName(".getAnnotationProcessorPathGroup() makes the expected call") + @MethodSource("outputContainerGroupResults") + @ParameterizedTest(name = "when internal getter returns {0}") + void getAnnotationProcessorPathGroupMakesTheExpectedCall(PackageContainerGroup expected) { + // Given + when(fileManager.getAnnotationProcessorPathGroup()).thenCallRealMethod(); + when(fileManager.getPackageContainerGroup(any())).thenReturn(expected); + + // When + var actual = fileManager.getAnnotationProcessorPathGroup(); + + // Then + verify(fileManager).getPackageContainerGroup(StandardLocation.ANNOTATION_PROCESSOR_PATH); + verifyNoMoreInteractions(fileManager); + assertThat(actual).isSameAs(expected); + } + + @DisplayName(".getAnnotationProcessorModulePathGroup() makes the expected call") + @MethodSource("moduleContainerGroupResults") + @ParameterizedTest(name = "when internal getter returns {0}") + void getAnnotationProcessorModulePathGroupMakesTheExpectedCall(ModuleContainerGroup expected) { + // Given + when(fileManager.getAnnotationProcessorModulePathGroup()).thenCallRealMethod(); + when(fileManager.getModuleContainerGroup(any())).thenReturn(expected); + + // When + var actual = fileManager.getAnnotationProcessorModulePathGroup(); + + // Then + verify(fileManager).getModuleContainerGroup(StandardLocation.ANNOTATION_PROCESSOR_MODULE_PATH); + verifyNoMoreInteractions(fileManager); + assertThat(actual).isSameAs(expected); + } + + @DisplayName(".getPlatformClassPathGroup() makes the expected call") + @MethodSource("outputContainerGroupResults") + @ParameterizedTest(name = "when internal getter returns {0}") + void getPlatformClassPathGroupMakesTheExpectedCall(PackageContainerGroup expected) { + // Given + when(fileManager.getPlatformClassPathGroup()).thenCallRealMethod(); + when(fileManager.getPackageContainerGroup(any())).thenReturn(expected); + + // When + var actual = fileManager.getPlatformClassPathGroup(); + + // Then + verify(fileManager).getPackageContainerGroup(StandardLocation.PLATFORM_CLASS_PATH); + verifyNoMoreInteractions(fileManager); + assertThat(actual).isSameAs(expected); + } + + @DisplayName(".getNativeHeaderOutputGroup() makes the expected call") + @MethodSource("outputContainerGroupResults") + @ParameterizedTest(name = "when internal getter returns {0}") + void getNativeHeaderOutputGroupMakesTheExpectedCall(OutputContainerGroup expected) { + // Given + when(fileManager.getNativeHeaderOutputGroup()).thenCallRealMethod(); + when(fileManager.getOutputContainerGroup(any())).thenReturn(expected); + + // When + var actual = fileManager.getNativeHeaderOutputGroup(); + + // Then + verify(fileManager).getOutputContainerGroup(StandardLocation.NATIVE_HEADER_OUTPUT); + verifyNoMoreInteractions(fileManager); + assertThat(actual).isSameAs(expected); + } + + @DisplayName(".getModuleSourcePathGroup() makes the expected call") + @MethodSource("moduleContainerGroupResults") + @ParameterizedTest(name = "when internal getter returns {0}") + void getModuleSourcePathGroupMakesTheExpectedCall(ModuleContainerGroup expected) { + // Given + when(fileManager.getModuleSourcePathGroup()).thenCallRealMethod(); + when(fileManager.getModuleContainerGroup(any())).thenReturn(expected); + + // When + var actual = fileManager.getModuleSourcePathGroup(); + + // Then + verify(fileManager).getModuleContainerGroup(StandardLocation.MODULE_SOURCE_PATH); + verifyNoMoreInteractions(fileManager); + assertThat(actual).isSameAs(expected); + } + + @DisplayName(".getUpgradeModulePathGroup() makes the expected call") + @MethodSource("moduleContainerGroupResults") + @ParameterizedTest(name = "when internal getter returns {0}") + void getUpgradeModulePathGroupMakesTheExpectedCall(ModuleContainerGroup expected) { + // Given + when(fileManager.getUpgradeModulePathGroup()).thenCallRealMethod(); + when(fileManager.getModuleContainerGroup(any())).thenReturn(expected); + + // When + var actual = fileManager.getUpgradeModulePathGroup(); + + // Then + verify(fileManager).getModuleContainerGroup(StandardLocation.UPGRADE_MODULE_PATH); + verifyNoMoreInteractions(fileManager); + assertThat(actual).isSameAs(expected); + } + + @DisplayName(".getSystemModulesGroup() makes the expected call") + @MethodSource("moduleContainerGroupResults") + @ParameterizedTest(name = "when internal getter returns {0}") + void getSystemModulesGroupMakesTheExpectedCall(ModuleContainerGroup expected) { + // Given + when(fileManager.getSystemModulesGroup()).thenCallRealMethod(); + when(fileManager.getModuleContainerGroup(any())).thenReturn(expected); + + // When + var actual = fileManager.getSystemModulesGroup(); + + // Then + verify(fileManager).getModuleContainerGroup(StandardLocation.SYSTEM_MODULES); + verifyNoMoreInteractions(fileManager); + assertThat(actual).isSameAs(expected); + } + + @DisplayName(".getModulePathGroup() makes the expected call") + @MethodSource("moduleContainerGroupResults") + @ParameterizedTest(name = "when internal getter returns {0}") + void getModulePathGroupMakesTheExpectedCall(ModuleContainerGroup expected) { + // Given + when(fileManager.getModulePathGroup()).thenCallRealMethod(); + when(fileManager.getModuleContainerGroup(any())).thenReturn(expected); + + // When + var actual = fileManager.getModulePathGroup(); + + // Then + verify(fileManager).getModuleContainerGroup(StandardLocation.MODULE_PATH); + verifyNoMoreInteractions(fileManager); + assertThat(actual).isSameAs(expected); + } + + @DisplayName(".getPatchModulePathGroup() makes the expected call") + @MethodSource("moduleContainerGroupResults") + @ParameterizedTest(name = "when internal getter returns {0}") + void getPatchModulePathGroupMakesTheExpectedCall(ModuleContainerGroup expected) { + // Given + when(fileManager.getPatchModulePathGroup()).thenCallRealMethod(); + when(fileManager.getModuleContainerGroup(any())).thenReturn(expected); + + // When + var actual = fileManager.getPatchModulePathGroup(); + + // Then + verify(fileManager).getModuleContainerGroup(StandardLocation.PATCH_MODULE_PATH); + verifyNoMoreInteractions(fileManager); + assertThat(actual).isSameAs(expected); + } + + + static Stream moduleContainerGroupResults() { + return Stream.of( + mock(ModuleContainerGroup.class, "a module container group"), + null + ); + } + + static Stream outputContainerGroupResults() { + return Stream.of( + mock(OutputContainerGroup.class, "an output container group"), + null + ); + } + + static Stream packageContainerGroupResults() { + return Stream.of( + mock(PackageContainerGroup.class, "a package container group"), + null + ); + } +} diff --git a/pom.xml b/pom.xml index 3e6e2cec8..ca548e19b 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ io.github.ascopes.jct java-compiler-testing-parent - 0.0.2-SNAPSHOT + 0.1.0-SNAPSHOT pom Java Compiler Testing parent project