@Test
  public void testSetIsInFields_first_ok_second_null() {
    OpenStreetMapSimpleImporter openStreetMapSimpleImporter = new OpenStreetMapSimpleImporter();

    final String cityName = "cityName";
    final Integer population = 123;
    final String adm2name = "adm2name";
    final City city = new City();
    city.setPopulation(population);
    city.setAdm2Name(adm2name);
    city.setName(cityName);
    city.setMunicipality(false);
    city.setFeatureId(1L);
    city.setId(123L);
    final Set<ZipCode> zipCodes = new HashSet<ZipCode>();
    zipCodes.add(new ZipCode("zip1"));
    city.addZipCodes(zipCodes);
    Point location = GeolocHelper.createPoint(2F, 3F);

    String countryCode = "FR";

    AlternateName an1 = new AlternateName("an1", AlternateNameSource.OPENSTREETMAP);
    AlternateName an2 = new AlternateName("an2", AlternateNameSource.OPENSTREETMAP);
    city.addAlternateName(an1);
    city.addAlternateName(an2);

    ICityDao cityDao = EasyMock.createMock(ICityDao.class);
    EasyMock.expect(
            cityDao.getByShape(
                EasyMock.anyObject(Point.class),
                EasyMock.anyObject(String.class),
                EasyMock.eq(true)))
        .andReturn(null);
    EasyMock.expect(
            cityDao.getNearest(location, countryCode, true, OpenStreetMapSimpleImporter.DISTANCE))
        .andReturn(city);
    EasyMock.expect(
            cityDao.getNearest(location, countryCode, false, OpenStreetMapSimpleImporter.DISTANCE))
        .andReturn(null);
    EasyMock.replay(cityDao);
    openStreetMapSimpleImporter.setCityDao(cityDao);

    OpenStreetMap street = new OpenStreetMap();
    street.setCountryCode(countryCode);
    street.setLocation(location);
    openStreetMapSimpleImporter.setIsInFields(street);

    Set<String> expectedZip = new HashSet<String>();
    expectedZip.add("ZIP1");
    Assert.assertEquals(expectedZip, street.getIsInZip());
    Assert.assertEquals("adm2name", street.getIsInAdm());
    Assert.assertEquals("cityName", street.getIsIn());
    Assert.assertEquals(123L, street.getCityId());
    Assert.assertEquals(null, street.getIsInPlace());
    Assert.assertTrue(street.getIsInCityAlternateNames().size() == 2);

    EasyMock.verify(cityDao);
  }
  @Test
  public void testSetIsInFields_GetByShape() {
    OpenStreetMapSimpleImporter openStreetMapSimpleImporter = new OpenStreetMapSimpleImporter();

    Point location = GeolocHelper.createPoint(2F, 3F);

    String countryCode = "FR";

    ICityDao cityDao = EasyMock.createMock(ICityDao.class);
    City cityByShape = new City();
    cityByShape.addZipCode(new ZipCode("zip"));
    cityByShape.setName("name");
    cityByShape.setPopulation(1000000);
    Adm adm = new Adm(2);
    adm.setName("admName");
    cityByShape.setAdm(adm);
    cityByShape.setFeatureId(1L);
    cityByShape.setId(123L);
    EasyMock.expect(
            cityDao.getByShape(
                EasyMock.anyObject(Point.class),
                EasyMock.anyObject(String.class),
                EasyMock.eq(true)))
        .andReturn(cityByShape);
    EasyMock.replay(cityDao);
    openStreetMapSimpleImporter.setCityDao(cityDao);

    OpenStreetMap street = new OpenStreetMap();
    street.setCountryCode(countryCode);
    street.setLocation(location);
    openStreetMapSimpleImporter.setIsInFields(street);

    Set<String> expectedZip = new HashSet<String>();
    expectedZip.add("ZIP");
    Assert.assertEquals(expectedZip, street.getIsInZip());
    Assert.assertEquals(true, street.isCityConfident());
    Assert.assertEquals("admName", street.getIsInAdm());
    Assert.assertEquals("name", street.getIsIn());
    Assert.assertEquals(123L, street.getCityId());
    Assert.assertEquals(null, street.getIsInPlace());

    EasyMock.verify(cityDao);
  }
  @Test
  public void testSetIsInFields_both_null() {
    OpenStreetMapSimpleImporter openStreetMapSimpleImporter = new OpenStreetMapSimpleImporter();

    final City city = new City();
    city.setMunicipality(false);
    final List<ZipCode> zipCodes = new ArrayList<ZipCode>();
    zipCodes.add(new ZipCode("zip1"));
    Point location = GeolocHelper.createPoint(2F, 3F);

    String countryCode = "FR";

    ICityDao cityDao = EasyMock.createMock(ICityDao.class);
    EasyMock.expect(
            cityDao.getByShape(
                EasyMock.anyObject(Point.class),
                EasyMock.anyObject(String.class),
                EasyMock.eq(true)))
        .andReturn(null);
    EasyMock.expect(
            cityDao.getNearest(location, countryCode, true, OpenStreetMapSimpleImporter.DISTANCE))
        .andReturn(city);
    EasyMock.expect(
            cityDao.getNearest(location, countryCode, false, OpenStreetMapSimpleImporter.DISTANCE))
        .andReturn(null);
    EasyMock.replay(cityDao);
    openStreetMapSimpleImporter.setCityDao(cityDao);

    OpenStreetMap street = new OpenStreetMap();
    street.setCountryCode(countryCode);
    street.setLocation(location);
    openStreetMapSimpleImporter.setIsInFields(street);

    Assert.assertEquals(null, street.getIsInZip());
    Assert.assertEquals(null, street.getIsInAdm());
    Assert.assertEquals(null, street.getIsIn());
    Assert.assertEquals(null, street.getIsInPlace());

    EasyMock.verify(cityDao);
  }
  @Test
  public void populateAlternateNames_nameWithCommaOrSemiColumn() {
    String RawAlternateNames =
        "Karl-Franzens-Universität Graz___Cheka Jedid,Chekia Atiq:Chekia Jedide;Chekia Jedidé";
    OpenStreetMapSimpleImporter importer = new OpenStreetMapSimpleImporter();
    OpenStreetMap street = new OpenStreetMap();
    street = importer.populateAlternateNames(street, RawAlternateNames);
    Assert.assertEquals(5, street.getAlternateNames().size());
    Assert.assertTrue(
        alternateOsmNameContains(street.getAlternateNames(), "Karl-Franzens-Universität Graz"));
    Assert.assertTrue(alternateOsmNameContains(street.getAlternateNames(), "Cheka Jedid"));
    Assert.assertTrue(alternateOsmNameContains(street.getAlternateNames(), "Chekia Atiq"));
    Assert.assertTrue(alternateOsmNameContains(street.getAlternateNames(), "Chekia Jedide"));
    Assert.assertTrue(alternateOsmNameContains(street.getAlternateNames(), "Chekia Jedidé"));

    Iterator<AlternateOsmName> iterator = street.getAlternateNames().iterator();
    while (iterator.hasNext()) {
      Assert.assertEquals(AlternateNameSource.OPENSTREETMAP, iterator.next().getSource());
    }
  }
  @Test
  public void testImporterShouldImport() throws InterruptedException {
    System.out.println(openStreetMapImporter.getClass());
    openStreetMapImporter.process();
    /*if (openStreetMapImporter.getClass() != OpenStreetMapImporter.class){
        Thread.sleep(10000L);
    }*/
    assertEquals(4L, openStreetMapDao.count());
    openStreetMapDao.getAll();
    Long firstIdAssigned = (idGenerator.getGid() - 4 + 1);
    OpenStreetMap openStreetMap = openStreetMapDao.getByGid(firstIdAssigned);
    assertTrue("The oneWay attribute is not correct", openStreetMap.isOneWay());
    assertEquals("The countryCode is not correct ", "FR", openStreetMap.getCountryCode());
    assertEquals("The is_in is not correct ", "a city", openStreetMap.getIsIn());
    assertEquals(
        "The openstreetmapId is not correct ", new Long(11), openStreetMap.getOpenstreetmapId());
    assertEquals(
        "The streetType is not correct", StreetType.RESIDENTIAL, openStreetMap.getStreetType());
    assertEquals("The name is not correct", "Bachlettenstrasse", openStreetMap.getName());
    assertEquals(
        "The location->X is not correct ",
        ((Point)
                GeolocHelper.convertFromHEXEWKBToGeometry(
                    "010100000006C82291A0521E4054CC39B16BC64740"))
            .getX(),
        openStreetMap.getLocation().getX());
    assertEquals(
        "The location->Y is not correct ",
        ((Point)
                GeolocHelper.convertFromHEXEWKBToGeometry(
                    "010100000006C82291A0521E4054CC39B16BC64740"))
            .getY(),
        openStreetMap.getLocation().getY());
    assertEquals("The length is not correct", 0.00142246604529, openStreetMap.getLength());
    assertEquals(
        "The shape is not correct ",
        GeolocHelper.convertFromHEXEWKBToGeometry(
                "01020000000200000009B254CD6218024038E22428D9EF484075C93846B217024090A8AB96CFEF4840")
            .toString(),
        openStreetMap.getShape().toString());

    // check alternate names when there is 2
    Assert.assertEquals(2, openStreetMap.getAlternateNames().size());
    Assert.assertTrue(
        alternateNamesContain(openStreetMap.getAlternateNames(), "Rue de Bachlettenstrasse"));
    Assert.assertTrue(
        alternateNamesContain(openStreetMap.getAlternateNames(), "Bachletten strasse"));

    // check alternate names when there is no name but alternate
    openStreetMap = openStreetMapDao.getByGid(firstIdAssigned + 1);
    Assert.assertEquals(1, openStreetMap.getAlternateNames().size());
    Assert.assertEquals(
        "When there is no name and some alternatename, the first alternatename is set to name ",
        "noName BUT an alternate",
        openStreetMap.getName());
    Assert.assertTrue(alternateNamesContain(openStreetMap.getAlternateNames(), "other an"));

    // one alternate name
    openStreetMap = openStreetMapDao.getByGid(firstIdAssigned + 2);
    Assert.assertEquals(1, openStreetMap.getAlternateNames().size());
    Assert.assertTrue(alternateNamesContain(openStreetMap.getAlternateNames(), "Friedhof"));

    // no alternate names
    openStreetMap = openStreetMapDao.getByGid(firstIdAssigned + 3);
    Assert.assertEquals(0, openStreetMap.getAlternateNames().size());
  }