|
20 | 20 | import static io.github.ascopes.jct.tests.helpers.Fixtures.someBinaryName; |
21 | 21 | import static io.github.ascopes.jct.tests.helpers.Fixtures.someFlags; |
22 | 22 | import static io.github.ascopes.jct.tests.helpers.Fixtures.someLinesOfText; |
| 23 | +import static io.github.ascopes.jct.tests.helpers.Fixtures.someText; |
23 | 24 | import static io.github.ascopes.jct.tests.helpers.Fixtures.someTraceDiagnostic; |
24 | 25 | import static io.github.ascopes.jct.utils.IterableUtils.flatten; |
25 | 26 | import static java.util.stream.Collectors.toList; |
@@ -655,6 +656,35 @@ void exceptionsDuringCompilationGetWrappedAndRethrown() throws IOException { |
655 | 656 | .hasCause(cause); |
656 | 657 | } |
657 | 658 |
|
| 659 | + @DisplayName("Compilers returning null outcomes will be raised as an exception") |
| 660 | + @Test |
| 661 | + void compilersReturningNullOutcomesWillBeRaisedAsAnException() throws IOException { |
| 662 | + // Given |
| 663 | + var task = mock(CompilationTask.class); |
| 664 | + var name = someText(); |
| 665 | + |
| 666 | + when(jctCompiler.getName()) |
| 667 | + .thenReturn(name); |
| 668 | + |
| 669 | + when(javaCompiler.getTask(any(), any(), any(), any(), any(), any())) |
| 670 | + .thenReturn(task); |
| 671 | + when(task.call()) |
| 672 | + .thenReturn(null); |
| 673 | + |
| 674 | + // Do not inline this, it will break in Mockito's stubber backend. |
| 675 | + var fileObjects = Set.of(somePathFileObject(someBinaryName())); |
| 676 | + when(fileManager.list(any(), any(), any(), anyBoolean())) |
| 677 | + .thenReturn(fileObjects); |
| 678 | + |
| 679 | + // Then |
| 680 | + assertThatThrownBy(() -> doCompile(null)) |
| 681 | + .isInstanceOf(JctCompilerException.class) |
| 682 | + .hasMessage("Failed to perform compilation, an unexpected exception was raised") |
| 683 | + .cause() |
| 684 | + .hasMessage("Compiler %s task .call() method returned null unexpectedly!", name) |
| 685 | + .isInstanceOf(NullPointerException.class); |
| 686 | + } |
| 687 | + |
658 | 688 | @DisplayName("The compilation result holds the failOnWarnings flag from the compiler") |
659 | 689 | @ValueSource(booleans = {true, false}) |
660 | 690 | @ParameterizedTest(name = "for compiler.isFailOnWarnings() = {0}") |
|
0 commit comments