title: Attempting to parse XML using SAX, but none of my JUnit tests work?
body: <p>So I'm attempting to run various tests to check that my XML parsing is correct. Unfortunately none of them pass which I assume is due to the fact my XML file isn't being stored correctly to the ArrayList. I'd appreciate any help!</p>
  
  <p>VideoFile.java:</p>
  
  <pre><code>package server;
  
  public class VideoFile {
      private int id;
      private String title;
      private String filename;
  
      public int getId() {
          return id;
      }
      public void setId(int id) {
          this.id = id;
      }
      public String getTitle() {
          return title;
      }
      public void setTitle(String title) {
          this.title = title;
      }
      public String getFilename() {
          return filename;
      }
      public void setFilename(String filename) {
          this.filename = filename;
      }  
  }
  </code></pre>
  
  <p>XMLReader.java:</p>
  
  <pre><code>package server;
  
  
  import java.io.File;
  import java.io.IOException;
  
  import java.util.ArrayList;
  import java.util.List;
  
  import javax.xml.parsers.ParserConfigurationException;
  import javax.xml.parsers.SAXParser;
  import javax.xml.parsers.SAXParserFactory;
  
  import org.xml.sax.Attributes;
  import org.xml.sax.SAXException;
  import org.xml.sax.helpers.DefaultHandler;
  
  
  
  public class XMLReader extends DefaultHandler {
  
      //List to hold VideoFiles object
      private List&lt;VideoFile&gt; videoList = null;
      private VideoFile emp = null;
  
  
      //getter method for employee list
      public List&lt;VideoFile&gt; getList() {
          return videoList;
      }
  
  
      boolean bTitle = false;
      boolean bFilename = false;
  
  
      @Override
      public void startElement(String uri, String localName, String qName, Attributes attributes)
              throws SAXException {
  
          if (qName.equalsIgnoreCase("video")) {
              //create a new VideoFile and put it in Map
              String id = attributes.getValue("id");
              //initialize VideoFile object and set id attribute
              emp = new VideoFile();
              emp.setId(Integer.parseInt(id));
              //initialize list
              if (videoList == null)
                  videoList = new ArrayList&lt;&gt;();
          } else if (qName.equalsIgnoreCase("title")) {
              //set boolean values for fields, will be used in setting VideoFile variables
              bTitle = true;
          } else if (qName.equalsIgnoreCase("filename")) {
              bFilename = true;
          }    
      }
  
  
      @Override
      public void endElement(String uri, String localName, String qName) throws SAXException {
          if (qName.equalsIgnoreCase("video")) {
              //add VideoFile object to list
              videoList.add(emp);
          }
      }
  
  
      @Override
      public void characters(char ch[], int start, int length) throws SAXException {
  
          if (bTitle) {
              emp.setTitle(new String(ch, start, length));
              bTitle = false;
          } else if (bFilename) {
              emp.setFilename(new String(ch, start, length));
              bFilename = false;
          }
      }
  
      public static void main(String[] args) {
      SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
      try {
          SAXParser saxParser = saxParserFactory.newSAXParser();
          XMLReader handler = new XMLReader();
          saxParser.parse(new File("videoList.xml"), handler);
          //Get VideoFiles list
          List&lt;VideoFile&gt; videoList = handler.getList();
          //print employee information
          for(VideoFile emp : videoList)
              System.out.println(emp);
      } catch (ParserConfigurationException | SAXException | IOException e) {
          e.printStackTrace();
      }
      }
  }
  </code></pre>
  
  <p>XMLReaderTest.java:</p>
  
  <pre><code>package server;
  
  import static org.junit.Assert.*;
  import java.util.List;
  import org.junit.Before;
  import org.junit.Test;
  
  public class XMLReaderTest {
      private XMLReader reader;
      private List&lt;VideoFile&gt; videoList;
  
      @Before
      public void setUp() throws Exception {
          reader = new XMLReader();
          videoList = reader.getList();
      }
  
      @Test
      public void createListOfVideos() {
          assertTrue(videoList instanceof List);
      }
  
      @Test
      public void listContainsVideoFiles() {
          assertTrue(videoList.get(0) instanceof VideoFile);
      }
  
      @Test
      public void videoFileReturnsCorrectFields() {
          VideoFile videoFile = videoList.get(0);
          assertNotNull(videoFile.getId());
          assertNotNull(videoFile.getTitle());
          assertNotNull(videoFile.getFilename());
      }
  
      @Test
      public void videoFileReturnsCorrectData() {
          VideoFile videoFile = videoList.get(0);
          assertEquals("201202132", videoFile.getId());
          assertEquals("Monsters Inc.", videoFile.getTitle());
          assertEquals("monstersinc_high.mpg", videoFile.getFilename());
      }
  }
  </code></pre>
  
  <p>videoList.xml:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;videoList version="sample"&gt;
      &lt;video id="4352524242"&gt;
          &lt;title&gt;Video 1&lt;/title&gt;
          &lt;filename&gt;vid1_high.mpg&lt;/filename&gt;
      &lt;/video&gt;
      &lt;video id="20120102b7"&gt;
          &lt;title&gt;Video 2&lt;/title&gt;
          &lt;filename&gt;vid2-featurehp.mp4&lt;/filename&gt;
      &lt;/video&gt;
      &lt;video id="1242102b7"&gt;
          &lt;title&gt;Vid3&lt;/title&gt;
          &lt;filename&gt;vid3-featureukFhp.mp4&lt;/filename&gt;
      &lt;/video&gt;
  &lt;/videoList&gt;
  </code></pre>