Skip to content

Commit

Permalink
Merge pull request #42277 from quaff
Browse files Browse the repository at this point in the history
* pr/42277:
  Add tests to ensure private constructor is not used for binding

Closes gh-42277
  • Loading branch information
philwebb committed Sep 13, 2024
2 parents 03e7be3 + ee10425 commit 8686ee8
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -33,6 +33,7 @@
*
* @author Phillip Webb
* @author Madhura Bhave
* @author Yanming Zhou
*/
class DefaultBindConstructorProviderTests {

Expand Down Expand Up @@ -92,6 +93,12 @@ void getBindConstructorWhenHasTwoConstructorsWithBothConstructorBindingThrowsExc
.withMessageContaining("has more than one @ConstructorBinding");
}

@Test
void getBindConstructorWhenIsTypeWithPrivateConstructorReturnsNull() {
Constructor<?> constructor = this.provider.getBindConstructor(TypeWithPrivateConstructor.class, false);
assertThat(constructor).isNull();
}

@Test
void getBindConstructorWhenIsMemberTypeWithPrivateConstructorReturnsNull() {
Constructor<?> constructor = this.provider.getBindConstructor(MemberTypeWithPrivateConstructor.Member.class,
Expand Down Expand Up @@ -224,6 +231,13 @@ static class TwoConstructorsWithBothConstructorBinding {

}

static final class TypeWithPrivateConstructor {

private TypeWithPrivateConstructor(Environment environment) {
}

}

static class MemberTypeWithPrivateConstructor {

static final class Member {
Expand Down

0 comments on commit 8686ee8

Please sign in to comment.