Skip to content

Commit 06e81c3

Browse files
authored
Add JSpecify annotations in default annotation list (#1235)
1 parent 8aecb9c commit 06e81c3

File tree

5 files changed

+139
-3
lines changed

5 files changed

+139
-3
lines changed

buildSrc/src/main/kotlin/Dependencies.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
object Versions {
2020
const val FIND_BUGS_JSR305 = "3.0.2"
2121
const val FIND_BUGS_ANNOTATIONS = "3.0.1"
22+
const val JSPECIFY = "1.0.0"
23+
const val CHECKER_QUAL = "3.50.0"
2224
const val SLF4J = "1.7.25"
2325
const val LOGBACK = "1.2.9"
2426
const val JUNIT_ENGINE = "1.9.1"

fixture-monkey-api/src/main/java/com/navercorp/fixturemonkey/api/generator/DefaultNullInjectGenerator.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ public final class DefaultNullInjectGenerator implements NullInjectGenerator {
4343
"org.springframework.lang.Nullable",
4444
"org.checkerframework.checker.nullness.qual.Nullable",
4545
"org.eclipse.jgit.annotations.Nullable",
46-
"org.jmlspecs.annotation.Nullable"
46+
"org.jmlspecs.annotation.Nullable",
47+
"org.jspecify.annotations.Nullable"
4748
)
4849
);
4950

@@ -55,7 +56,8 @@ public final class DefaultNullInjectGenerator implements NullInjectGenerator {
5556
"jakarta.validation.constraints.NotNull",
5657
"org.springframework.lang.NonNull",
5758
"org.checkerframework.checker.nullness.qual.NonNull",
58-
"org.jmlspecs.annotation.NonNull"
59+
"org.jmlspecs.annotation.NonNull",
60+
"org.jspecify.annotations.NonNull"
5961
)
6062
);
6163

fixture-monkey-tests/java-tests/build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ plugins {
55
dependencies {
66
testImplementation(project(":fixture-monkey-javax-validation"))
77
testImplementation(project(":fixture-monkey-datafaker"))
8-
testImplementation("org.projectlombok:lombok:${Versions.LOMBOK}")
98
testImplementation(project(":fixture-monkey-jackson"))
9+
testImplementation("org.jspecify:jspecify:${Versions.JSPECIFY}")
10+
testImplementation("org.checkerframework:checker-qual:${Versions.CHECKER_QUAL}")
11+
testImplementation("org.projectlombok:lombok:${Versions.LOMBOK}")
1012
testAnnotationProcessor("org.projectlombok:lombok:${Versions.LOMBOK}")
1113
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* Fixture Monkey
3+
*
4+
* Copyright (c) 2021-present NAVER Corp.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package com.navercorp.fixturemonkey.tests.java;
20+
21+
import static com.navercorp.fixturemonkey.api.generator.DefaultNullInjectGenerator.ALWAYS_NULL_INJECT;
22+
import static com.navercorp.fixturemonkey.api.generator.DefaultNullInjectGenerator.DEFAULT_NOTNULL_ANNOTATION_TYPES;
23+
import static com.navercorp.fixturemonkey.api.generator.DefaultNullInjectGenerator.DEFAULT_NULLABLE_ANNOTATION_TYPES;
24+
import static com.navercorp.fixturemonkey.tests.TestEnvironment.TEST_COUNT;
25+
import static org.assertj.core.api.BDDAssertions.then;
26+
27+
import java.util.HashSet;
28+
29+
import org.junit.jupiter.api.RepeatedTest;
30+
31+
import com.navercorp.fixturemonkey.FixtureMonkey;
32+
import com.navercorp.fixturemonkey.api.generator.DefaultNullInjectGenerator;
33+
import com.navercorp.fixturemonkey.api.introspector.ConstructorPropertiesArbitraryIntrospector;
34+
import com.navercorp.fixturemonkey.tests.java.specs.DefaultNullInjectGeneratorSpecs.NonNullAnnotationObject;
35+
import com.navercorp.fixturemonkey.tests.java.specs.DefaultNullInjectGeneratorSpecs.NullableAnnotationObject;
36+
37+
class DefaultNullInjectGeneratorTest {
38+
@RepeatedTest(TEST_COUNT)
39+
void nonNullAnnotations() {
40+
FixtureMonkey sut = FixtureMonkey.builder()
41+
.objectIntrospector(ConstructorPropertiesArbitraryIntrospector.INSTANCE)
42+
.defaultNullInjectGenerator(
43+
new DefaultNullInjectGenerator(
44+
ALWAYS_NULL_INJECT,
45+
false,
46+
false,
47+
false,
48+
new HashSet<>(DEFAULT_NULLABLE_ANNOTATION_TYPES),
49+
new HashSet<>(DEFAULT_NOTNULL_ANNOTATION_TYPES)
50+
)
51+
)
52+
.build();
53+
54+
NonNullAnnotationObject actual = sut.giveMeOne(NonNullAnnotationObject.class);
55+
56+
then(actual.getJavaxNonNullField()).isNotNull();
57+
then(actual.getJspecifyNonNullField()).isNotNull();
58+
then(actual.getCheckerNonNullField()).isNotNull();
59+
}
60+
61+
@RepeatedTest(TEST_COUNT)
62+
void nullableAnnotations() {
63+
FixtureMonkey sut = FixtureMonkey.builder()
64+
.objectIntrospector(ConstructorPropertiesArbitraryIntrospector.INSTANCE)
65+
.defaultNullInjectGenerator(
66+
new DefaultNullInjectGenerator(
67+
ALWAYS_NULL_INJECT,
68+
false,
69+
true,
70+
false,
71+
new HashSet<>(DEFAULT_NULLABLE_ANNOTATION_TYPES),
72+
new HashSet<>(DEFAULT_NOTNULL_ANNOTATION_TYPES)
73+
)
74+
)
75+
.build();
76+
77+
NullableAnnotationObject actual = sut.giveMeOne(NullableAnnotationObject.class);
78+
79+
then(actual.getJavaxNullableField()).isNull();
80+
then(actual.getJspecifyNullableField()).isNull();
81+
then(actual.getCheckerNullableField()).isNull();
82+
}
83+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Fixture Monkey
3+
*
4+
* Copyright (c) 2021-present NAVER Corp.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
package com.navercorp.fixturemonkey.tests.java.specs;
20+
21+
import lombok.Value;
22+
23+
public class DefaultNullInjectGeneratorSpecs {
24+
@Value
25+
public static class NonNullAnnotationObject {
26+
@javax.validation.constraints.NotNull
27+
String javaxNonNullField;
28+
29+
@org.jspecify.annotations.NonNull
30+
String jspecifyNonNullField;
31+
32+
@org.checkerframework.checker.nullness.qual.NonNull
33+
String checkerNonNullField;
34+
}
35+
36+
@Value
37+
public static class NullableAnnotationObject {
38+
@javax.annotation.Nullable
39+
String javaxNullableField;
40+
41+
@org.jspecify.annotations.Nullable
42+
String jspecifyNullableField;
43+
44+
@org.checkerframework.checker.nullness.qual.Nullable
45+
String checkerNullableField;
46+
}
47+
}

0 commit comments

Comments
 (0)