Created
February 18, 2015 14:50
-
-
Save freekman/15771f4c7932dba6c21d to your computer and use it in GitHub Desktop.
Sax Parser Test Happy Path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package xml.sax; | |
import org.junit.Test; | |
import java.util.List; | |
import static org.hamcrest.MatcherAssert.assertThat; | |
import static org.hamcrest.core.Is.is; | |
public class ParseJavaObjectsWithSaxTest { | |
SaxParser saxParser = new SaxParser(); | |
@Test | |
public void happyPath() throws Exception { | |
List<Employee> employees = saxParser.parse(SaxParser.class.getResourceAsStream("Employees.xml"), Employee.class); | |
Employee firstEmployee = employees.get(0); | |
assertThat(employees.size(), is(1)); | |
assertEmployee(firstEmployee); | |
assertEmployer(firstEmployee.getEmployer()); | |
assertAddress(firstEmployee.getAddress()); | |
} | |
private void assertAddress(Address address) { | |
assertThat(address.getStreet(), is("Boris Bogdanov")); | |
assertThat(address.getStreetNo(), is("7")); | |
assertThat(address.getSection(), is("center")); | |
assertThat(address.getCity(), is("Veliko tarnovo")); | |
} | |
private void assertEmployer(Employer employer) { | |
assertThat(employer.getName(), is("Boss")); | |
assertThat(employer.getStartDate(), is("2014-08-08")); | |
assertThat(employer.getEndDate(), is("2015-01-02")); | |
} | |
private void assertEmployee(Employee firstEmployee) { | |
assertThat(firstEmployee.getFirstName(), is("Ivan")); | |
assertThat(firstEmployee.getLastName(), is("Ivanov")); | |
assertThat(firstEmployee.getAge(), is("25")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment