@Test
  public void convertsJodaTimeTypesCorrectly() {

    List<Converter<?, ?>> converters = new ArrayList<Converter<?, ?>>();
    converters.add(new LocalDateToDateConverter());
    converters.add(new DateToLocalDateConverter());

    List<Class<?>> customSimpleTypes = new ArrayList<Class<?>>();
    customSimpleTypes.add(LocalDate.class);
    mappingContext.setCustomSimpleTypes(customSimpleTypes);

    converter = new MappingMongoConverter(mappingContext);
    converter.setConverters(converters);
    converter.afterPropertiesSet();

    Person person = new Person();
    person.birthDate = new LocalDate();

    DBObject dbObject = new BasicDBObject();
    converter.write(person, dbObject);

    assertTrue(dbObject.get("birthDate") instanceof Date);

    Person result = converter.read(Person.class, dbObject);
    assertThat(result.birthDate, is(notNullValue()));
  }
  /** @see DATADOC-130 */
  @Test
  public void convertsMapTypeCorrectly() {

    Map<Locale, String> map = Collections.singletonMap(Locale.US, "Foo");

    BasicDBObject dbObject = new BasicDBObject();
    converter.write(map, dbObject);

    assertThat(dbObject.get(Locale.US.toString()).toString(), is("Foo"));
  }
  @Test
  public void writesTypeDiscriminatorIntoRootObject() {

    Person person = new Person();
    person.birthDate = new LocalDate();

    DBObject result = new BasicDBObject();
    converter.write(person, result);

    assertThat(result.containsField(MappingMongoConverter.CUSTOM_TYPE_KEY), is(true));
    assertThat(
        result.get(MappingMongoConverter.CUSTOM_TYPE_KEY).toString(), is(Person.class.getName()));
  }
  @Test
  public void convertsAddressCorrectly() {

    Address address = new Address();
    address.city = "New York";
    address.street = "Broadway";

    DBObject dbObject = new BasicDBObject();

    converter.write(address, dbObject);

    assertThat(dbObject.get("city").toString(), is("New York"));
    assertThat(dbObject.get("street").toString(), is("Broadway"));
  }