Skip to content

Commit

Permalink
Add tests for Fix ClassCastException of BeanReadPropertyImpl to BeanP…
Browse files Browse the repository at this point in the history
…roperty
  • Loading branch information
erkieh committed Nov 30, 2024
1 parent 528c27f commit bf1a326
Showing 1 changed file with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,59 @@ class Test {
introspection.getProperty("foo").get().type == String.class
}

void "test read property by type is defined by its reader field"() {
given:
def introspection = buildBeanIntrospection('test.Test', '''
package test;
import io.micronaut.core.annotation.Introspected;
import io.micronaut.context.annotation.Executable;
import io.micronaut.core.annotation.Nullable;
import java.util.Optional;
@Introspected(accessKind = {Introspected.AccessKind.METHOD, Introspected.AccessKind.FIELD})
class Test {
@Nullable
String foo;
public Optional<String> getFoo() {
return Optional.ofNullable(foo);
}
}
''')
expect:
introspection.getReadProperty("foo", String.class).isEmpty()
introspection.getReadProperty("foo", Optional.class).get().type == Optional.class

}

void "test read property type is defined by its field"() {
given:
def introspection = buildBeanIntrospection('test.Test', '''
package test;
import io.micronaut.core.annotation.Introspected;
import io.micronaut.context.annotation.Executable;
import io.micronaut.core.annotation.Nullable;
import java.util.Optional;
@Introspected(accessKind = {Introspected.AccessKind.METHOD, Introspected.AccessKind.FIELD})
class Test {
@Nullable
String foo;
public void setFoo(Optional<String> foo) {
this.foo = foo.orElse(null);
}
}
''')
expect:
introspection.getReadProperty("foo", String.class).get().type == String.class
introspection.getReadProperty("foo", Optional.class).isEmpty()
}

void "test optional property type is defined by its setter"() {
given:
def introspection = buildBeanIntrospection('test.Test', '''
Expand Down

0 comments on commit bf1a326

Please sign in to comment.