Skip to content

Commit

Permalink
Merge pull request eugenp#4367 from chrisoberle/master
Browse files Browse the repository at this point in the history
BAEL-1786
  • Loading branch information
thombergs authored Jun 3, 2018
2 parents dc60351 + d683b37 commit fb8224d
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
10 changes: 10 additions & 0 deletions core-java-8/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
18 changes: 18 additions & 0 deletions core-java-8/src/main/java/com/baeldung/reflect/Person.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.baeldung.reflect;

public class Person {

private String fullName;

public Person(String fullName) {
this.fullName = fullName;
}

public void setFullName(String fullName) {
this.fullName = fullName;
}

public String getFullName() {
return fullName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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 java.util.Optional;

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).getParameters());
Optional<Parameter> parameter
= parameters.stream().filter(Parameter::isNamePresent).findFirst();
assertThat(parameter.get().getName()).isEqualTo("fullName");
}

@Test
public void whenGetMethodParams_thenOk()
throws NoSuchMethodException, SecurityException {
List<Parameter> parameters
= Arrays.asList(
Person.class.getMethod("setFullName", String.class).getParameters());
Optional<Parameter> parameter
= parameters.stream().filter(Parameter::isNamePresent).findFirst();
assertThat(parameter.get().getName()).isEqualTo("fullName");
}
}

0 comments on commit fb8224d

Please sign in to comment.