|
| 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 | +} |
0 commit comments