initial import of source for BAEL-1786

This commit is contained in:
Chris Oberle 2018-05-29 09:35:09 -04:00
parent 523fbf433c
commit 543c87fa70
3 changed files with 85 additions and 0 deletions

View File

@ -195,6 +195,16 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArgument>-parameters</compilerArgument>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>

View File

@ -0,0 +1,42 @@
package com.baeldung.reflect;
public class Person {
private String firstName;
private String lastName;
private Integer age;
public Person(String firstName, String lastName, Integer age) {
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
}
public Person() {}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
}

View File

@ -0,0 +1,33 @@
package com.baeldung.reflect;
import static org.assertj.core.api.Assertions.assertThat;
import java.lang.reflect.Parameter;
import java.util.Arrays;
import java.util.List;
import static java.util.stream.Collectors.toList;
import org.junit.Test;
public class MethodParamNameTest {
@Test
public void whenGetConstructorParams_thenOk() throws NoSuchMethodException, SecurityException {
List<Parameter> parameters
= Arrays.asList(
Person.class.getConstructor(String.class, String.class, Integer.class)
.getParameters());
List<String> parameterNames
= parameters.stream().map(Parameter::getName).collect(toList());
assertThat(parameterNames)
.containsExactlyInAnyOrder("lastName", "firstName", "age");
}
@Test
public void whenGetMethodParams_thenOk() throws NoSuchMethodException, SecurityException {
List<Parameter> parameters
= Arrays.asList(
Person.class.getMethod("setLastName", String.class).getParameters());
assertThat(parameters.get(0).getName()).isEqualTo("lastName");
}
}