@@ -67,10 +67,12 @@ void usesCustomNullAwayVersion() {
6767 @ Test
6868 void configuresErrorProneOnCompileJava () {
6969 BuildResult result = this .gradleBuild .build ("checkCompileJava" );
70- assertThat (result .getOutput ())
71- .contains ("-XepDisableAllChecks -Xep:NullAway:ERROR -XepOpt:NullAway:OnlyNullMarked=true "
72- + "-XepOpt:NullAway:CustomContractAnnotations=org.springframework.lang.Contract "
73- + "-XepOpt:NullAway:JSpecifyMode=true" );
70+ assertThat (result .getOutput ()).contains ("-XepDisableAllChecks" )
71+ .contains ("-Xep:NullAway:ERROR" )
72+ .contains ("-Xep:RequireExplicitNullMarking:ERROR" )
73+ .contains ("-XepOpt:NullAway:OnlyNullMarked=true" )
74+ .contains ("-XepOpt:NullAway:CustomContractAnnotations=org.springframework.lang.Contract" )
75+ .contains ("-XepOpt:NullAway:JSpecifyMode=true" );
7476 }
7577
7678 @ Test
@@ -82,10 +84,15 @@ void disablesErrorProneOnCompileTestJavaByDefault() {
8284 @ Test
8385 void configuresErrorProneOnCompileTestJavaWhenEnabled () {
8486 BuildResult result = this .gradleBuild .build ("checkCompileTestJava" );
85- assertThat (result .getOutput ()).contains (
86- "-XepDisableAllChecks -XepCompilingTestOnlyCode -Xep:NullAway:ERROR -XepOpt:NullAway:OnlyNullMarked=true "
87- + "-XepOpt:NullAway:CustomContractAnnotations=org.springframework.lang.Contract,org.assertj.core.internal.annotation.Contract "
88- + "-XepOpt:NullAway:JSpecifyMode=true -XepOpt:NullAway:HandleTestAssertionLibraries=true" );
87+ assertThat (result .getOutput ()).contains ("-XepDisableAllChecks" )
88+ .contains ("-XepCompilingTestOnlyCode" )
89+ .contains ("-Xep:NullAway:ERROR" )
90+ .contains ("-Xep:RequireExplicitNullMarking:ERROR" )
91+ .contains ("-XepOpt:NullAway:OnlyNullMarked=true" )
92+ .contains (
93+ "-XepOpt:NullAway:CustomContractAnnotations=org.springframework.lang.Contract,org.assertj.core.internal.annotation.Contract" )
94+ .contains ("-XepOpt:NullAway:JSpecifyMode=true" )
95+ .contains ("-XepOpt:NullAway:HandleTestAssertionLibraries=true" );
8996 }
9097
9198 @ Test
@@ -109,17 +116,48 @@ void compileFailsForNullabilityViolationInTestCodeWhenCheckingIsEnabled() throws
109116 assertThat (result .getOutput ()).contains ("[NullAway] assigning @Nullable expression to @NonNull field" );
110117 }
111118
112- private void writeSource (String sourceSetName ) {
119+ @ Test
120+ void compileFailsForCodeThatIsNotNullMarked () throws IOException {
121+ Path pkg = createSrcDirectories ("main" );
122+ writeExampleClass (pkg );
123+ BuildResult result = this .gradleBuild .prepareRunner ("compileJava" ).buildAndFail ();
124+ assertThat (result .getOutput ()).contains ("[RequireExplicitNullMarking]" );
125+ }
126+
127+ private Path createSrcDirectories (String sourceSetName ) {
113128 Path projectDir = this .gradleBuild .getProjectDir ().toPath ();
114129 Path pkg = projectDir .resolve ("src/%s/java/com/example" .formatted (sourceSetName ));
115130 try {
116131 Files .createDirectories (pkg );
132+ }
133+ catch (IOException ex ) {
134+ throw new UncheckedIOException (ex );
135+ }
136+ return pkg ;
137+ }
138+
139+ private void writeSource (String sourceSetName ) {
140+ Path pkg = createSrcDirectories (sourceSetName );
141+ writePackageInfo (pkg );
142+ writeExampleClass (pkg );
143+ }
144+
145+ private void writePackageInfo (Path pkg ) {
146+ try {
117147 Files .writeString (pkg .resolve ("package-info.java" ), """
118148 @NullMarked
119149 package com.example;
120150
121151 import org.jspecify.annotations.NullMarked;
122152 """ );
153+ }
154+ catch (IOException ex ) {
155+ throw new UncheckedIOException (ex );
156+ }
157+ }
158+
159+ private void writeExampleClass (Path pkg ) {
160+ try {
123161 Files .writeString (pkg .resolve ("Example.java" ), """
124162 package com.example;
125163
0 commit comments