Refactored code to use generic methods and use streams. (#10052)
This commit is contained in:
parent
1cd9875381
commit
f134833952
@ -0,0 +1,19 @@
|
||||
package com.baeldung.reflection.check.staticmethods;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
|
||||
public class StaticUtility {
|
||||
|
||||
public static String getAuthorName() {
|
||||
return "Umang Budhwar";
|
||||
}
|
||||
|
||||
public static LocalDate getLocalDate() {
|
||||
return LocalDate.now();
|
||||
}
|
||||
|
||||
public static LocalTime getLocalTime() {
|
||||
return LocalTime.now();
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.baeldung.reflection.check.staticmethods;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class StaticUtilityUnitTest {
|
||||
|
||||
@Test
|
||||
void whenCheckStaticMethod_ThenSuccess() throws Exception {
|
||||
Method method = StaticUtility.class.getMethod("getAuthorName", null);
|
||||
Assertions.assertTrue(Modifier.isStatic(method.getModifiers()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenCheckAllStaticMethods_thenSuccess() {
|
||||
List<Method> methodList = Arrays.asList(StaticUtility.class.getMethods())
|
||||
.stream()
|
||||
.filter(method -> Modifier.isStatic(method.getModifiers()))
|
||||
.collect(Collectors.toList());
|
||||
Assertions.assertEquals(3, methodList.size());
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user