|
|
@ -1,5 +1,5 @@
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Copyright 2012-2019 the original author or authors.
|
|
|
|
* Copyright 2012-2021 the original author or authors.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
@ -16,8 +16,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.actuate.endpoint.invoke.reflect;
|
|
|
|
package org.springframework.boot.actuate.endpoint.invoke.reflect;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.lang.annotation.Retention;
|
|
|
|
|
|
|
|
import java.lang.annotation.RetentionPolicy;
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
import java.lang.reflect.Method;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
|
|
|
|
import javax.annotation.meta.TypeQualifier;
|
|
|
|
|
|
|
|
import javax.annotation.meta.When;
|
|
|
|
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.lang.Nullable;
|
|
|
|
import org.springframework.lang.Nullable;
|
|
|
@ -32,29 +38,48 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
class OperationMethodParameterTests {
|
|
|
|
class OperationMethodParameterTests {
|
|
|
|
|
|
|
|
|
|
|
|
private Method method = ReflectionUtils.findMethod(getClass(), "example", String.class, String.class);
|
|
|
|
private Method example = ReflectionUtils.findMethod(getClass(), "example", String.class, String.class);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Method exampleJsr305 = ReflectionUtils.findMethod(getClass(), "exampleJsr305", String.class, String.class);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Method exampleMetaJsr305 = ReflectionUtils.findMethod(getClass(), "exampleMetaJsr305", String.class,
|
|
|
|
|
|
|
|
String.class);
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void getNameShouldReturnName() {
|
|
|
|
void getNameShouldReturnName() {
|
|
|
|
OperationMethodParameter parameter = new OperationMethodParameter("name", this.method.getParameters()[0]);
|
|
|
|
OperationMethodParameter parameter = new OperationMethodParameter("name", this.example.getParameters()[0]);
|
|
|
|
assertThat(parameter.getName()).isEqualTo("name");
|
|
|
|
assertThat(parameter.getName()).isEqualTo("name");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void getTypeShouldReturnType() {
|
|
|
|
void getTypeShouldReturnType() {
|
|
|
|
OperationMethodParameter parameter = new OperationMethodParameter("name", this.method.getParameters()[0]);
|
|
|
|
OperationMethodParameter parameter = new OperationMethodParameter("name", this.example.getParameters()[0]);
|
|
|
|
assertThat(parameter.getType()).isEqualTo(String.class);
|
|
|
|
assertThat(parameter.getType()).isEqualTo(String.class);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void isMandatoryWhenNoAnnotationShouldReturnTrue() {
|
|
|
|
void isMandatoryWhenNoAnnotationShouldReturnTrue() {
|
|
|
|
OperationMethodParameter parameter = new OperationMethodParameter("name", this.method.getParameters()[0]);
|
|
|
|
OperationMethodParameter parameter = new OperationMethodParameter("name", this.example.getParameters()[0]);
|
|
|
|
assertThat(parameter.isMandatory()).isTrue();
|
|
|
|
assertThat(parameter.isMandatory()).isTrue();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void isMandatoryWhenNullableAnnotationShouldReturnFalse() {
|
|
|
|
void isMandatoryWhenNullableAnnotationShouldReturnFalse() {
|
|
|
|
OperationMethodParameter parameter = new OperationMethodParameter("name", this.method.getParameters()[1]);
|
|
|
|
OperationMethodParameter parameter = new OperationMethodParameter("name", this.example.getParameters()[1]);
|
|
|
|
|
|
|
|
assertThat(parameter.isMandatory()).isFalse();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
void isMandatoryWhenJsrNullableAnnotationShouldReturnFalse() {
|
|
|
|
|
|
|
|
OperationMethodParameter parameter = new OperationMethodParameter("name",
|
|
|
|
|
|
|
|
this.exampleJsr305.getParameters()[1]);
|
|
|
|
|
|
|
|
assertThat(parameter.isMandatory()).isFalse();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
void isMandatoryWhenJsrMetaNullableAnnotationShouldReturnFalse() {
|
|
|
|
|
|
|
|
OperationMethodParameter parameter = new OperationMethodParameter("name",
|
|
|
|
|
|
|
|
this.exampleMetaJsr305.getParameters()[1]);
|
|
|
|
assertThat(parameter.isMandatory()).isFalse();
|
|
|
|
assertThat(parameter.isMandatory()).isFalse();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -62,4 +87,19 @@ class OperationMethodParameterTests {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void exampleJsr305(String one, @javax.annotation.Nullable String two) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void exampleMetaJsr305(String one, @MetaNullable String two) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@TypeQualifier
|
|
|
|
|
|
|
|
@Retention(RetentionPolicy.RUNTIME)
|
|
|
|
|
|
|
|
@Nonnull(when = When.MAYBE)
|
|
|
|
|
|
|
|
@interface MetaNullable {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|