/** Just test if no exceptions are thrown when writing to file. */
  @Test
  public void testWriteGraphOrderToFile() {

    DigicoreNetworkWriter dnw = new DigicoreNetworkWriter(buildSmallNetwork());
    try {
      dnw.writeGraphOrderToFile(utils.getOutputDirectory() + "testOrder.csv");
    } catch (IOException e1) {
      Assert.fail("Should not throw an exception.");
    }
  }
  @Test
  public void testWriteNetwork() {
    DigicoreNetwork dn = buildSmallNetwork();
    DigicoreNetworkWriter dnw = new DigicoreNetworkWriter(dn);

    /* Check that writing and overwriting of output is correct. */
    try {
      dnw.writeNetwork(utils.getOutputDirectory() + "network.txt.gz");
    } catch (IOException e) {
      Assert.fail("Should be able to write the first file without IOException.");
    }
    try {
      dnw.writeNetwork(utils.getOutputDirectory() + "network.txt.gz");
      Assert.fail("Should not be able to overwrite the file.");
    } catch (IOException e) {
      /* Pass. */
    }
    try {
      dnw.writeNetwork(utils.getOutputDirectory() + "network.txt.gz", false);
      Assert.fail("Should not be able to overwrite the file.");
    } catch (IOException e) {
      /* Pass. */
    }
    try {
      dnw.writeNetwork(utils.getOutputDirectory() + "network.txt.gz", true);
    } catch (IOException e) {
      Assert.fail("Should overwrite the file without IOException.");
    }

    /* Now check the content of the file. */
    BufferedReader br = IOUtils.getBufferedReader(utils.getOutputDirectory() + "network.txt.gz");
    try {
      String line = br.readLine();
      Assert.assertTrue("Wrong line.", line.equalsIgnoreCase("NODES"));
      line = br.readLine();
      Assert.assertTrue("Wrong line.", line.equalsIgnoreCase("NodeId,Long,Lat"));
      line = br.readLine();
      Assert.assertTrue("Wrong line.", line.equalsIgnoreCase("3,1.0000,1.0000"));
      line = br.readLine();
      Assert.assertTrue("Wrong line.", line.equalsIgnoreCase("2,0.0000,1.0000"));
      line = br.readLine();
      Assert.assertTrue("Wrong line.", line.equalsIgnoreCase("1,0.0000,0.0000"));
      line = br.readLine();
      Assert.assertTrue("Wrong line.", line.equalsIgnoreCase("4,1.0000,0.0000"));
      line = br.readLine();
      Assert.assertTrue("Wrong line.", line.equalsIgnoreCase("ARCS"));
      line = br.readLine();
      Assert.assertTrue(
          "Wrong line.", line.equalsIgnoreCase("From_Id,To_Id,From_Type,To_Type,Weight"));
      line = br.readLine();
      Assert.assertTrue("Wrong line.", line.equalsIgnoreCase("1,2,test,test,1"));
      line = br.readLine();
      Assert.assertTrue("Wrong line.", line.equalsIgnoreCase("3,1,test,test,1"));
      line = br.readLine();
      Assert.assertTrue("Wrong line.", line.equalsIgnoreCase("1,3,test,test,2"));
      line = br.readLine();
      Assert.assertTrue("Wrong line.", line.equalsIgnoreCase("4,1,test,test,3"));
    } catch (IOException e) {
      Assert.fail("Should not fail reading the file.");
    }
  }