2929import static org .mockito .Mockito .doThrow ;
3030import static org .mockito .Mockito .mock ;
3131import static org .mockito .Mockito .mockConstruction ;
32+ import static org .mockito .Mockito .mockStatic ;
3233import static org .mockito .Mockito .spy ;
3334import static org .mockito .Mockito .verify ;
3435import static org .mockito .Mockito .verifyNoMoreInteractions ;
4748import io .github .ascopes .jct .filemanagers .AnnotationProcessorDiscovery ;
4849import io .github .ascopes .jct .filemanagers .JctFileManager ;
4950import io .github .ascopes .jct .filemanagers .JctFileManagerFactory ;
51+ import io .github .ascopes .jct .filemanagers .JctFileManagers ;
5052import io .github .ascopes .jct .filemanagers .LoggingMode ;
5153import io .github .ascopes .jct .workspaces .Workspace ;
5254import java .io .IOException ;
8587import org .mockito .Mock ;
8688import org .mockito .MockedConstruction ;
8789import org .mockito .MockedConstruction .Context ;
90+ import org .mockito .MockedStatic ;
8891import org .mockito .junit .jupiter .MockitoExtension ;
8992
9093/**
@@ -103,9 +106,6 @@ class AbstractJctCompilerTest {
103106 @ Mock (answer = Answers .RETURNS_MOCKS )
104107 Jsr199CompilerFactory jsr199CompilerFactory ;
105108
106- @ Mock (answer = Answers .RETURNS_MOCKS )
107- JctFileManagerFactory fileManagerFactory ;
108-
109109 String name ;
110110 String defaultRelease ;
111111 CompilerImpl compiler ;
@@ -309,14 +309,20 @@ void constructorInitialisesAnnotationProcessorDiscoveryToDefaultValue() {
309309 }
310310
311311 @ ExtendWith (MockitoExtension .class )
312- @ SuppressWarnings ("unused" )
312+ @ SuppressWarnings ({ "unused" , "JUnitMalformedDeclaration" /* IDEA-326883 */ } )
313313 abstract class AbstractCompileTestTemplate {
314314
315315 @ Mock
316316 Workspace workspace ;
317317
318318 List <String > flags ;
319319
320+ @ Mock
321+ MockedStatic <JctFileManagers > fileManagers ;
322+
323+ @ Mock
324+ JctFileManagerFactory fileManagerFactory ;
325+
320326 @ Mock
321327 JctFileManager fileManager ;
322328
@@ -345,6 +351,8 @@ void setUp() {
345351
346352 when (flagBuilderFactory .createFlagBuilder ()).thenReturn (flagBuilder );
347353 when (jsr199CompilerFactory .createCompiler ()).thenReturn (jsr199Compiler );
354+ fileManagers .when (() -> JctFileManagers .newJctFileManagerFactory (any ()))
355+ .thenReturn (fileManagerFactory );
348356 when (fileManagerFactory .createFileManager (any ())).thenReturn (fileManager );
349357
350358 // Default implementation. We can override this to make it throw exceptions, etc.
@@ -1558,6 +1566,24 @@ void toStringShouldReturnTheName() {
15581566 assertThat (compiler ).hasToString (name );
15591567 }
15601568
1569+ @ DisplayName (".getFileManagerFactory() should build a new file manager factory impl" )
1570+ @ Test
1571+ void getFileManagerFactoryShouldBuildNewFileManagerFactoryImpl () {
1572+ // Given
1573+ try (var fileManagersCls = mockStatic (JctFileManagers .class )) {
1574+ var expectedFactory = mock (JctFileManagerFactory .class );
1575+ fileManagersCls .when (() -> JctFileManagers .newJctFileManagerFactory (any ()))
1576+ .thenReturn (expectedFactory );
1577+
1578+ // When
1579+ var actualFactory = compiler .getFileManagerFactory ();
1580+
1581+ // Then
1582+ fileManagersCls .verify (() -> JctFileManagers .newJctFileManagerFactory (compiler ));
1583+ assertThat (actualFactory ).isSameAs (expectedFactory );
1584+ }
1585+ }
1586+
15611587 @ DisplayName (".getCompilationFactory() should build a new compilation factory impl" )
15621588 @ Test
15631589 void getCompilationFactoryBuildsCompilationFactoryImpl () {
@@ -1668,11 +1694,6 @@ public Jsr199CompilerFactory getCompilerFactory() {
16681694 return jsr199CompilerFactory ;
16691695 }
16701696
1671- @ Override
1672- public JctFileManagerFactory getFileManagerFactory () {
1673- return fileManagerFactory ;
1674- }
1675-
16761697 @ Override
16771698 public List <String > buildFlags (JctFlagBuilder flagBuilder ) {
16781699 // Promote this method to be public for testing.
0 commit comments