forked from micronaut-projects/micronaut-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:micronaut-projects/micronaut-core
- Loading branch information
Showing
10 changed files
with
217 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
inject-java/src/test/groovy/io/micronaut/inject/field/nullableinjection/A.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright 2017-2018 original authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.micronaut.inject.field.nullableinjection; | ||
|
||
public interface A { | ||
} |
28 changes: 28 additions & 0 deletions
28
inject-java/src/test/groovy/io/micronaut/inject/field/nullableinjection/B.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2017-2018 original authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.micronaut.inject.field.nullableinjection; | ||
|
||
import javax.annotation.Nullable; | ||
import javax.inject.Inject; | ||
|
||
public class B { | ||
|
||
@Inject @Nullable protected A a; | ||
|
||
public A getA() { | ||
return this.a; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
inject-java/src/test/groovy/io/micronaut/inject/field/nullableinjection/C.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright 2017-2018 original authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.micronaut.inject.field.nullableinjection; | ||
|
||
import javax.inject.Inject; | ||
|
||
public class C { | ||
|
||
@Inject protected A a; | ||
|
||
public A getA() { | ||
return this.a; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...test/groovy/io/micronaut/inject/field/nullableinjection/FieldNullableInjectionSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2017-2018 original authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.micronaut.inject.field.nullableinjection | ||
|
||
import io.micronaut.context.BeanContext | ||
import io.micronaut.context.DefaultBeanContext | ||
import io.micronaut.context.exceptions.DependencyInjectionException | ||
import spock.lang.Specification | ||
|
||
class FieldNullableInjectionSpec extends Specification { | ||
|
||
void "test nullable injection with field"() { | ||
given: | ||
BeanContext context = new DefaultBeanContext() | ||
context.start() | ||
|
||
when:"A bean is obtained that has a constructor with @Inject" | ||
B b = context.getBean(B) | ||
|
||
then:"The implementation is not injected, but null is" | ||
b.a == null | ||
} | ||
|
||
void "test normal injection still fails"() { | ||
given: | ||
BeanContext context = new DefaultBeanContext() | ||
context.start() | ||
|
||
when:"A bean is obtained that has a constructor with @Inject" | ||
context.getBean(C) | ||
|
||
then:"The bean is not found" | ||
thrown(DependencyInjectionException) | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
inject-java/src/test/groovy/io/micronaut/inject/value/nullablevalue/A.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package io.micronaut.inject.value.nullablevalue; | ||
|
||
import io.micronaut.context.annotation.Value; | ||
|
||
import javax.annotation.Nullable; | ||
import javax.inject.Inject; | ||
import javax.inject.Singleton; | ||
|
||
@Singleton | ||
public class A { | ||
|
||
public final String nullConstructorArg; | ||
public final String nonNullConstructorArg; | ||
public String nullMethodArg; | ||
public String nonNullMethodArg; | ||
public @Value("${doesnt.exist}") @Nullable String nullField; | ||
public @Value("${exists.x}") String nonNullField; | ||
|
||
|
||
public A(@Value("${doesnt.exist}") @Nullable String nullConstructorArg, | ||
@Value("${exists.x}") String nonNullConstructorArg) { | ||
this.nullConstructorArg = nullConstructorArg; | ||
this.nonNullConstructorArg = nonNullConstructorArg; | ||
} | ||
|
||
@Inject | ||
void injectedMethod(@Value("${doesnt.exist}") @Nullable String nullMethodArg, | ||
@Value("${exists.x}") String nonNullMethodArg) { | ||
this.nullMethodArg = nullMethodArg; | ||
this.nonNullMethodArg = nonNullMethodArg; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
inject-java/src/test/groovy/io/micronaut/inject/value/nullablevalue/NullableValueSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.micronaut.inject.value.nullablevalue | ||
|
||
import io.micronaut.context.ApplicationContext | ||
import spock.lang.Specification | ||
|
||
class NullableValueSpec extends Specification { | ||
|
||
void "test value with nullable"() { | ||
given: | ||
ApplicationContext context = ApplicationContext.run( | ||
["exists.x":"fromConfig"], "test" | ||
) | ||
|
||
when: | ||
A a = context.getBean(A) | ||
|
||
then: | ||
a.nullField == null | ||
a.nonNullField == "fromConfig" | ||
a.nullConstructorArg == null | ||
a.nonNullConstructorArg == "fromConfig" | ||
a.nullMethodArg == null | ||
a.nonNullMethodArg == "fromConfig" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters