minor fix
This commit is contained in:
parent
622da702d0
commit
7fb6cc7900
2
core-java/.gitignore
vendored
2
core-java/.gitignore
vendored
@ -13,4 +13,4 @@
|
|||||||
*.ear
|
*.ear
|
||||||
|
|
||||||
# Files generated by integration tests
|
# Files generated by integration tests
|
||||||
#*.txt
|
*.txt
|
@ -1,32 +1,35 @@
|
|||||||
package com.baeldung.java.reflection;
|
package com.baeldung.java.reflection;
|
||||||
|
|
||||||
import org.junit.Test;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.lang.reflect.Modifier;
|
import java.lang.reflect.Modifier;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ArrayList;
|
|
||||||
import static org.junit.Assert.*;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class ReflectionUnitTest {
|
public class ReflectionUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenObject_whenGetsFieldNamesAtRuntime_thenCorrect() {
|
public void givenObject_whenGetsFieldNamesAtRuntime_thenCorrect() {
|
||||||
Object person = new Person();
|
final Object person = new Person();
|
||||||
Field[] fields = person.getClass().getDeclaredFields();
|
final Field[] fields = person.getClass().getDeclaredFields();
|
||||||
|
|
||||||
List<String> actualFieldNames = getFieldNames(fields);
|
final List<String> actualFieldNames = getFieldNames(fields);
|
||||||
|
|
||||||
assertTrue(Arrays.asList("name", "age").containsAll(actualFieldNames));
|
assertTrue(Arrays.asList("name", "age").containsAll(actualFieldNames));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenObject_whenGetsClassName_thenCorrect() {
|
public void givenObject_whenGetsClassName_thenCorrect() {
|
||||||
Object goat = new Goat("goat");
|
final Object goat = new Goat("goat");
|
||||||
Class<?> clazz = goat.getClass();
|
final Class<?> clazz = goat.getClass();
|
||||||
|
|
||||||
assertEquals("Goat", clazz.getSimpleName());
|
assertEquals("Goat", clazz.getSimpleName());
|
||||||
assertEquals("com.baeldung.java.reflection.Goat", clazz.getName());
|
assertEquals("com.baeldung.java.reflection.Goat", clazz.getName());
|
||||||
@ -35,7 +38,7 @@ public class ReflectionUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenClassName_whenCreatesObject_thenCorrect() throws ClassNotFoundException {
|
public void givenClassName_whenCreatesObject_thenCorrect() throws ClassNotFoundException {
|
||||||
Class<?> clazz = Class.forName("com.baeldung.java.reflection.Goat");
|
final Class<?> clazz = Class.forName("com.baeldung.java.reflection.Goat");
|
||||||
|
|
||||||
assertEquals("Goat", clazz.getSimpleName());
|
assertEquals("Goat", clazz.getSimpleName());
|
||||||
assertEquals("com.baeldung.java.reflection.Goat", clazz.getName());
|
assertEquals("com.baeldung.java.reflection.Goat", clazz.getName());
|
||||||
@ -44,10 +47,10 @@ public class ReflectionUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenClass_whenRecognisesModifiers_thenCorrect() throws ClassNotFoundException {
|
public void givenClass_whenRecognisesModifiers_thenCorrect() throws ClassNotFoundException {
|
||||||
Class<?> goatClass = Class.forName("com.baeldung.java.reflection.Goat");
|
final Class<?> goatClass = Class.forName("com.baeldung.java.reflection.Goat");
|
||||||
Class<?> animalClass = Class.forName("com.baeldung.java.reflection.Animal");
|
final Class<?> animalClass = Class.forName("com.baeldung.java.reflection.Animal");
|
||||||
int goatMods = goatClass.getModifiers();
|
final int goatMods = goatClass.getModifiers();
|
||||||
int animalMods = animalClass.getModifiers();
|
final int animalMods = animalClass.getModifiers();
|
||||||
|
|
||||||
assertTrue(Modifier.isPublic(goatMods));
|
assertTrue(Modifier.isPublic(goatMods));
|
||||||
assertTrue(Modifier.isAbstract(animalMods));
|
assertTrue(Modifier.isAbstract(animalMods));
|
||||||
@ -56,20 +59,20 @@ public class ReflectionUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenClass_whenGetsPackageInfo_thenCorrect() {
|
public void givenClass_whenGetsPackageInfo_thenCorrect() {
|
||||||
Goat goat = new Goat("goat");
|
final Goat goat = new Goat("goat");
|
||||||
Class<?> goatClass = goat.getClass();
|
final Class<?> goatClass = goat.getClass();
|
||||||
Package pkg = goatClass.getPackage();
|
final Package pkg = goatClass.getPackage();
|
||||||
|
|
||||||
assertEquals("com.baeldung.java.reflection", pkg.getName());
|
assertEquals("com.baeldung.java.reflection", pkg.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenClass_whenGetsSuperClass_thenCorrect() {
|
public void givenClass_whenGetsSuperClass_thenCorrect() {
|
||||||
Goat goat = new Goat("goat");
|
final Goat goat = new Goat("goat");
|
||||||
String str = "any string";
|
final String str = "any string";
|
||||||
|
|
||||||
Class<?> goatClass = goat.getClass();
|
final Class<?> goatClass = goat.getClass();
|
||||||
Class<?> goatSuperClass = goatClass.getSuperclass();
|
final Class<?> goatSuperClass = goatClass.getSuperclass();
|
||||||
|
|
||||||
assertEquals("Animal", goatSuperClass.getSimpleName());
|
assertEquals("Animal", goatSuperClass.getSimpleName());
|
||||||
assertEquals("Object", str.getClass().getSuperclass().getSimpleName());
|
assertEquals("Object", str.getClass().getSuperclass().getSimpleName());
|
||||||
@ -78,10 +81,10 @@ public class ReflectionUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenClass_whenGetsImplementedInterfaces_thenCorrect() throws ClassNotFoundException {
|
public void givenClass_whenGetsImplementedInterfaces_thenCorrect() throws ClassNotFoundException {
|
||||||
Class<?> goatClass = Class.forName("com.baeldung.java.reflection.Goat");
|
final Class<?> goatClass = Class.forName("com.baeldung.java.reflection.Goat");
|
||||||
Class<?> animalClass = Class.forName("com.baeldung.java.reflection.Animal");
|
final Class<?> animalClass = Class.forName("com.baeldung.java.reflection.Animal");
|
||||||
Class<?>[] goatInterfaces = goatClass.getInterfaces();
|
final Class<?>[] goatInterfaces = goatClass.getInterfaces();
|
||||||
Class<?>[] animalInterfaces = animalClass.getInterfaces();
|
final Class<?>[] animalInterfaces = animalClass.getInterfaces();
|
||||||
|
|
||||||
assertEquals(1, goatInterfaces.length);
|
assertEquals(1, goatInterfaces.length);
|
||||||
assertEquals(1, animalInterfaces.length);
|
assertEquals(1, animalInterfaces.length);
|
||||||
@ -91,8 +94,8 @@ public class ReflectionUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenClass_whenGetsConstructor_thenCorrect() throws ClassNotFoundException {
|
public void givenClass_whenGetsConstructor_thenCorrect() throws ClassNotFoundException {
|
||||||
Class<?> goatClass = Class.forName("com.baeldung.java.reflection.Goat");
|
final Class<?> goatClass = Class.forName("com.baeldung.java.reflection.Goat");
|
||||||
Constructor<?>[] constructors = goatClass.getConstructors();
|
final Constructor<?>[] constructors = goatClass.getConstructors();
|
||||||
|
|
||||||
assertEquals(1, constructors.length);
|
assertEquals(1, constructors.length);
|
||||||
assertEquals("com.baeldung.java.reflection.Goat", constructors[0].getName());
|
assertEquals("com.baeldung.java.reflection.Goat", constructors[0].getName());
|
||||||
@ -100,10 +103,10 @@ public class ReflectionUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenClass_whenGetsFields_thenCorrect() throws ClassNotFoundException {
|
public void givenClass_whenGetsFields_thenCorrect() throws ClassNotFoundException {
|
||||||
Class<?> animalClass = Class.forName("com.baeldung.java.reflection.Animal");
|
final Class<?> animalClass = Class.forName("com.baeldung.java.reflection.Animal");
|
||||||
Field[] fields = animalClass.getDeclaredFields();
|
final Field[] fields = animalClass.getDeclaredFields();
|
||||||
|
|
||||||
List<String> actualFields = getFieldNames(fields);
|
final List<String> actualFields = getFieldNames(fields);
|
||||||
|
|
||||||
assertEquals(2, actualFields.size());
|
assertEquals(2, actualFields.size());
|
||||||
assertTrue(actualFields.containsAll(Arrays.asList("name", "CATEGORY")));
|
assertTrue(actualFields.containsAll(Arrays.asList("name", "CATEGORY")));
|
||||||
@ -111,41 +114,41 @@ public class ReflectionUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenClass_whenGetsMethods_thenCorrect() throws ClassNotFoundException {
|
public void givenClass_whenGetsMethods_thenCorrect() throws ClassNotFoundException {
|
||||||
Class<?> animalClass = Class.forName("com.baeldung.java.reflection.Animal");
|
final Class<?> animalClass = Class.forName("com.baeldung.java.reflection.Animal");
|
||||||
Method[] methods = animalClass.getDeclaredMethods();
|
final Method[] methods = animalClass.getDeclaredMethods();
|
||||||
List<String> actualMethods = getMethodNames(methods);
|
final List<String> actualMethods = getMethodNames(methods);
|
||||||
|
|
||||||
assertEquals(4, actualMethods.size());
|
assertEquals(3, actualMethods.size());
|
||||||
assertTrue(actualMethods.containsAll(Arrays.asList("getName", "setName", "getSound")));
|
assertTrue(actualMethods.containsAll(Arrays.asList("getName", "setName", "getSound")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenClass_whenGetsAllConstructors_thenCorrect() throws ClassNotFoundException {
|
public void givenClass_whenGetsAllConstructors_thenCorrect() throws ClassNotFoundException {
|
||||||
Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
|
final Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
|
||||||
Constructor<?>[] constructors = birdClass.getConstructors();
|
final Constructor<?>[] constructors = birdClass.getConstructors();
|
||||||
|
|
||||||
assertEquals(3, constructors.length);
|
assertEquals(3, constructors.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenClass_whenGetsEachConstructorByParamTypes_thenCorrect() throws Exception {
|
public void givenClass_whenGetsEachConstructorByParamTypes_thenCorrect() throws Exception {
|
||||||
Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
|
final Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
|
||||||
Constructor<?> cons1 = birdClass.getConstructor();
|
birdClass.getConstructor();
|
||||||
Constructor<?> cons2 = birdClass.getConstructor(String.class);
|
birdClass.getConstructor(String.class);
|
||||||
Constructor<?> cons3 = birdClass.getConstructor(String.class, boolean.class);
|
birdClass.getConstructor(String.class, boolean.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenClass_whenInstantiatesObjectsAtRuntime_thenCorrect() throws Exception {
|
public void givenClass_whenInstantiatesObjectsAtRuntime_thenCorrect() throws Exception {
|
||||||
Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
|
final Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
|
||||||
|
|
||||||
Constructor<?> cons1 = birdClass.getConstructor();
|
final Constructor<?> cons1 = birdClass.getConstructor();
|
||||||
Constructor<?> cons2 = birdClass.getConstructor(String.class);
|
final Constructor<?> cons2 = birdClass.getConstructor(String.class);
|
||||||
Constructor<?> cons3 = birdClass.getConstructor(String.class, boolean.class);
|
final Constructor<?> cons3 = birdClass.getConstructor(String.class, boolean.class);
|
||||||
|
|
||||||
Bird bird1 = (Bird) cons1.newInstance();
|
final Bird bird1 = (Bird) cons1.newInstance();
|
||||||
Bird bird2 = (Bird) cons2.newInstance("Weaver bird");
|
final Bird bird2 = (Bird) cons2.newInstance("Weaver bird");
|
||||||
Bird bird3 = (Bird) cons3.newInstance("dove", true);
|
final Bird bird3 = (Bird) cons3.newInstance("dove", true);
|
||||||
|
|
||||||
assertEquals("bird", bird1.getName());
|
assertEquals("bird", bird1.getName());
|
||||||
assertEquals("Weaver bird", bird2.getName());
|
assertEquals("Weaver bird", bird2.getName());
|
||||||
@ -156,8 +159,8 @@ public class ReflectionUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenClass_whenGetsPublicFields_thenCorrect() throws ClassNotFoundException {
|
public void givenClass_whenGetsPublicFields_thenCorrect() throws ClassNotFoundException {
|
||||||
Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
|
final Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
|
||||||
Field[] fields = birdClass.getFields();
|
final Field[] fields = birdClass.getFields();
|
||||||
assertEquals(1, fields.length);
|
assertEquals(1, fields.length);
|
||||||
assertEquals("CATEGORY", fields[0].getName());
|
assertEquals("CATEGORY", fields[0].getName());
|
||||||
|
|
||||||
@ -165,40 +168,40 @@ public class ReflectionUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenClass_whenGetsPublicFieldByName_thenCorrect() throws Exception {
|
public void givenClass_whenGetsPublicFieldByName_thenCorrect() throws Exception {
|
||||||
Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
|
final Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
|
||||||
Field field = birdClass.getField("CATEGORY");
|
final Field field = birdClass.getField("CATEGORY");
|
||||||
assertEquals("CATEGORY", field.getName());
|
assertEquals("CATEGORY", field.getName());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenClass_whenGetsDeclaredFields_thenCorrect() throws ClassNotFoundException {
|
public void givenClass_whenGetsDeclaredFields_thenCorrect() throws ClassNotFoundException {
|
||||||
Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
|
final Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
|
||||||
Field[] fields = birdClass.getDeclaredFields();
|
final Field[] fields = birdClass.getDeclaredFields();
|
||||||
assertEquals(1, fields.length);
|
assertEquals(1, fields.length);
|
||||||
assertEquals("walks", fields[0].getName());
|
assertEquals("walks", fields[0].getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenClass_whenGetsFieldsByName_thenCorrect() throws Exception {
|
public void givenClass_whenGetsFieldsByName_thenCorrect() throws Exception {
|
||||||
Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
|
final Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
|
||||||
Field field = birdClass.getDeclaredField("walks");
|
final Field field = birdClass.getDeclaredField("walks");
|
||||||
assertEquals("walks", field.getName());
|
assertEquals("walks", field.getName());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenClassField_whenGetsType_thenCorrect() throws Exception {
|
public void givenClassField_whenGetsType_thenCorrect() throws Exception {
|
||||||
Field field = Class.forName("com.baeldung.java.reflection.Bird").getDeclaredField("walks");
|
final Field field = Class.forName("com.baeldung.java.reflection.Bird").getDeclaredField("walks");
|
||||||
Class<?> fieldClass = field.getType();
|
final Class<?> fieldClass = field.getType();
|
||||||
assertEquals("boolean", fieldClass.getSimpleName());
|
assertEquals("boolean", fieldClass.getSimpleName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenClassField_whenSetsAndGetsValue_thenCorrect() throws Exception {
|
public void givenClassField_whenSetsAndGetsValue_thenCorrect() throws Exception {
|
||||||
Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
|
final Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
|
||||||
Bird bird = (Bird) birdClass.newInstance();
|
final Bird bird = (Bird) birdClass.newInstance();
|
||||||
Field field = birdClass.getDeclaredField("walks");
|
final Field field = birdClass.getDeclaredField("walks");
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
|
|
||||||
assertFalse(field.getBoolean(bird));
|
assertFalse(field.getBoolean(bird));
|
||||||
@ -213,8 +216,8 @@ public class ReflectionUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenClassField_whenGetsAndSetsWithNull_thenCorrect() throws Exception {
|
public void givenClassField_whenGetsAndSetsWithNull_thenCorrect() throws Exception {
|
||||||
Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
|
final Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
|
||||||
Field field = birdClass.getField("CATEGORY");
|
final Field field = birdClass.getField("CATEGORY");
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
|
|
||||||
assertEquals("domestic", field.get(null));
|
assertEquals("domestic", field.get(null));
|
||||||
@ -222,9 +225,9 @@ public class ReflectionUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenClass_whenGetsAllPublicMethods_thenCorrect() throws ClassNotFoundException {
|
public void givenClass_whenGetsAllPublicMethods_thenCorrect() throws ClassNotFoundException {
|
||||||
Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
|
final Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
|
||||||
Method[] methods = birdClass.getMethods();
|
final Method[] methods = birdClass.getMethods();
|
||||||
List<String> methodNames = getMethodNames(methods);
|
final List<String> methodNames = getMethodNames(methods);
|
||||||
|
|
||||||
assertTrue(methodNames.containsAll(Arrays.asList("equals", "notifyAll", "hashCode", "walks", "eats", "toString")));
|
assertTrue(methodNames.containsAll(Arrays.asList("equals", "notifyAll", "hashCode", "walks", "eats", "toString")));
|
||||||
|
|
||||||
@ -232,10 +235,10 @@ public class ReflectionUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenClass_whenGetsOnlyDeclaredMethods_thenCorrect() throws ClassNotFoundException {
|
public void givenClass_whenGetsOnlyDeclaredMethods_thenCorrect() throws ClassNotFoundException {
|
||||||
Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
|
final Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
|
||||||
List<String> actualMethodNames = getMethodNames(birdClass.getDeclaredMethods());
|
final List<String> actualMethodNames = getMethodNames(birdClass.getDeclaredMethods());
|
||||||
|
|
||||||
List<String> expectedMethodNames = Arrays.asList("setWalks", "walks", "getSound", "eats");
|
final List<String> expectedMethodNames = Arrays.asList("setWalks", "walks", "getSound", "eats");
|
||||||
|
|
||||||
assertEquals(expectedMethodNames.size(), actualMethodNames.size());
|
assertEquals(expectedMethodNames.size(), actualMethodNames.size());
|
||||||
assertTrue(expectedMethodNames.containsAll(actualMethodNames));
|
assertTrue(expectedMethodNames.containsAll(actualMethodNames));
|
||||||
@ -245,9 +248,9 @@ public class ReflectionUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenMethodName_whenGetsMethod_thenCorrect() throws Exception {
|
public void givenMethodName_whenGetsMethod_thenCorrect() throws Exception {
|
||||||
Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
|
final Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
|
||||||
Method walksMethod = birdClass.getDeclaredMethod("walks");
|
final Method walksMethod = birdClass.getDeclaredMethod("walks");
|
||||||
Method setWalksMethod = birdClass.getDeclaredMethod("setWalks", boolean.class);
|
final Method setWalksMethod = birdClass.getDeclaredMethod("setWalks", boolean.class);
|
||||||
|
|
||||||
assertFalse(walksMethod.isAccessible());
|
assertFalse(walksMethod.isAccessible());
|
||||||
assertFalse(setWalksMethod.isAccessible());
|
assertFalse(setWalksMethod.isAccessible());
|
||||||
@ -262,17 +265,17 @@ public class ReflectionUnitTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenMethod_whenInvokes_thenCorrect() throws Exception {
|
public void givenMethod_whenInvokes_thenCorrect() throws Exception {
|
||||||
Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
|
final Class<?> birdClass = Class.forName("com.baeldung.java.reflection.Bird");
|
||||||
Bird bird = (Bird) birdClass.newInstance();
|
final Bird bird = (Bird) birdClass.newInstance();
|
||||||
Method setWalksMethod = birdClass.getDeclaredMethod("setWalks", boolean.class);
|
final Method setWalksMethod = birdClass.getDeclaredMethod("setWalks", boolean.class);
|
||||||
Method walksMethod = birdClass.getDeclaredMethod("walks");
|
final Method walksMethod = birdClass.getDeclaredMethod("walks");
|
||||||
boolean walks = (boolean) walksMethod.invoke(bird);
|
final boolean walks = (boolean) walksMethod.invoke(bird);
|
||||||
|
|
||||||
assertFalse(walks);
|
assertFalse(walks);
|
||||||
assertFalse(bird.walks());
|
assertFalse(bird.walks());
|
||||||
|
|
||||||
setWalksMethod.invoke(bird, true);
|
setWalksMethod.invoke(bird, true);
|
||||||
boolean walks2 = (boolean) walksMethod.invoke(bird);
|
final boolean walks2 = (boolean) walksMethod.invoke(bird);
|
||||||
|
|
||||||
assertTrue(walks2);
|
assertTrue(walks2);
|
||||||
assertTrue(bird.walks());
|
assertTrue(bird.walks());
|
||||||
@ -280,17 +283,19 @@ public class ReflectionUnitTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static List<String> getFieldNames(Field[] fields) {
|
private static List<String> getFieldNames(Field[] fields) {
|
||||||
List<String> fieldNames = new ArrayList<>();
|
final List<String> fieldNames = new ArrayList<>();
|
||||||
for (Field field : fields)
|
for (final Field field : fields) {
|
||||||
fieldNames.add(field.getName());
|
fieldNames.add(field.getName());
|
||||||
|
}
|
||||||
return fieldNames;
|
return fieldNames;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<String> getMethodNames(Method[] methods) {
|
private static List<String> getMethodNames(Method[] methods) {
|
||||||
List<String> methodNames = new ArrayList<>();
|
final List<String> methodNames = new ArrayList<>();
|
||||||
for (Method method : methods)
|
for (final Method method : methods) {
|
||||||
methodNames.add(method.getName());
|
methodNames.add(method.getName());
|
||||||
|
}
|
||||||
return methodNames;
|
return methodNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ import java.util.Scanner;
|
|||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
import org.apache.commons.io.LineIterator;
|
import org.apache.commons.io.LineIterator;
|
||||||
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -14,6 +15,7 @@ import org.slf4j.LoggerFactory;
|
|||||||
import com.google.common.base.Charsets;
|
import com.google.common.base.Charsets;
|
||||||
import com.google.common.io.Files;
|
import com.google.common.io.Files;
|
||||||
|
|
||||||
|
@Ignore("need large file for testing")
|
||||||
public class JavaIoUnitTest {
|
public class JavaIoUnitTest {
|
||||||
protected final Logger logger = LoggerFactory.getLogger(getClass());
|
protected final Logger logger = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user