Newer
Older
adjustgpx-core / test / osm / jp / gpx / ElementMapTRKSEGTest.java
@haya4 haya4 on 18 Aug 2019 2 KB Java11 - AdjustTime2
  1. package osm.jp.gpx;
  2.  
  3. import static org.hamcrest.CoreMatchers.is;
  4. import static org.hamcrest.CoreMatchers.notNullValue;
  5. import static org.junit.Assert.assertThat;
  6. import static org.junit.Assert.fail;
  7. import java.io.File;
  8. import java.io.IOException;
  9. import java.text.ParseException;
  10. import java.util.Date;
  11. import javax.xml.parsers.ParserConfigurationException;
  12. import org.junit.experimental.theories.DataPoints;
  13. import org.junit.experimental.theories.Theories;
  14. import org.junit.experimental.theories.Theory;
  15. import org.junit.runner.RunWith;
  16. import org.w3c.dom.DOMException;
  17. import org.xml.sax.SAXException;
  18.  
  19. public class ElementMapTRKSEGTest {
  20.  
  21. @RunWith(Theories.class)
  22. public static class 各種GPXファイルを食わせる {
  23. static class Fixture {
  24. String gpxSourcePath; // GPXファイル(オリジナル)
  25. int segCount; // GPXファイルに含まれるTRKSEGノードの数
  26.  
  27. public Fixture(String gpxSourcePath, int segCount) {
  28. this.gpxSourcePath = gpxSourcePath;
  29. this.segCount = segCount;
  30. }
  31.  
  32. @Override
  33. public String toString() {
  34. String msg = "テストパターン : \n";
  35. msg += "\tgpxSourcePath = "+ gpxSourcePath +"\n";
  36. msg += "\tsegCount = "+ segCount;
  37. return msg;
  38. }
  39. }
  40.  
  41. @DataPoints
  42. public static Fixture[] datas = {
  43. new Fixture("testdata/20170517.gpx", 1),
  44. new Fixture("testdata/20170518.gpx", 1),
  45. new Fixture("testdata/muiltiTRK.GarminColorado.gpx.xml", 3),
  46. new Fixture("testdata/muiltiTRKSEG.GarminColorado.gpx.xml", 3),
  47. new Fixture("testdata/muiltiTRKSEG.noNameSpace.gpx.xml", 3),
  48. new Fixture("testdata/multiTRKSEG.eTrex_20J.gpx.xml", 3),
  49. new Fixture("testdata/multiTRKSEGreverse.eTrex_20J.gpx.xml", 3),
  50. };
  51.  
  52. @Theory
  53. public void TRKSEGを読み込む(Fixture dataset) {
  54. try {
  55. ElementMapTRKSEG mapTRKSEG = new ElementMapTRKSEG();
  56. mapTRKSEG.parse(new File(dataset.gpxSourcePath));
  57. mapTRKSEG.printinfo();
  58. System.out.println("GPX file: "+ dataset.gpxSourcePath);
  59. assertThat(mapTRKSEG.size(), is(dataset.segCount));
  60. for (Date key : mapTRKSEG.keySet()) {
  61. assertThat(key, is(notNullValue()));
  62. }
  63. }
  64. catch (IOException | ParseException | ParserConfigurationException | DOMException | SAXException e) {
  65. fail();
  66. }
  67. }
  68. }
  69. }