Merging BAEL-968: Apache Commons BeanUtils (#2149)

This commit is contained in:
Syed Ali Raza
2017-06-25 19:12:51 +05:00
committed by Grzegorz Piwowarek
parent 526fd057ce
commit ed7c1694a7
5 changed files with 127 additions and 1 deletions

View File

@@ -0,0 +1,38 @@
package com.baeldung.commons.beanutils;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
public class CourseServiceTest {
@Test
public void givenCourse_whenSetValuesUsingPropertyUtil_thenReturnSetValues()
throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {
Course course = new Course();
String name = "Computer Science";
List<String> codes = Arrays.asList("CS", "CS01");
CourseService.setValues(course, name, codes);
Assert.assertEquals(name, course.getName());
Assert.assertEquals(2, course.getCodes().size());
Assert.assertEquals("CS", course.getCodes().get(0));
CourseService.setIndexedValue(course, 1, "CS02");
Assert.assertEquals("CS02", course.getCodes().get(1));
Student student = new Student();
String studentName = "Joe";
student.setName(studentName);
CourseService.setMappedValue(course, "ST-1", student);
Assert.assertEquals(student, course.getEnrolledStudent("ST-1"));
String accessedStudentName = CourseService.getNestedValue(course, "ST-1", "name");
Assert.assertEquals(studentName, accessedStudentName);
}
}