<commit_before>package org.dozer.functional_tests.annotation;

import org.dozer.Mapping;
import org.dozer.functional_tests.AbstractFunctionalTest;
import org.junit.Before;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;

/**
 * @author dmitry.buzdin
 */
public class AnnotationMappingTest extends AbstractFunctionalTest {

  private User source;
  private SubUser subSource;
  private UserDto destination;

  @Before
  public void setUp() throws Exception {
    super.setUp();
    source = new User();
    subSource = new SubUser();
    destination = new UserDto();
  }

  @Test
  public void shouldMapProperies() {
    source.setId(1L);

    UserDto result = mapper.map(source, UserDto.class);
    
    assertThat(result.getPk(), equalTo("1"));
    assertThat(result.getId(), nullValue());
  }

  @Test
  public void shouldMapProperies_Backwards() {
    source.setAge(new Short("1"));

    UserDto result = mapper.map(source, UserDto.class);
                                         
    assertThat(result.getYears(), equalTo("1"));
  }

  @Test
  public void shouldMapFields() {
    source.setName("name");

    UserDto result = mapper.map(source, UserDto.class);

    assertThat(result.username, equalTo("name"));
    assertThat(result.name, nullValue());
  }

  @Test
  public void shouldMapFields_Backwards() {
    source.freeText = "text";

    UserDto result = mapper.map(source, UserDto.class);

    assertThat(result.comment, equalTo("text"));
  }

  @Test
  public void shouldMapFields_Inherited() {
    subSource.setName("name");

    UserDto result = mapper.map(subSource, UserDto.class);

    assertThat(result.username, equalTo("name"));
    assertThat(result.name, nullValue());
  }

  @Test
  public void shouldMapFields_Backwards_Inherited() {
    subSource.freeText = "text";

    UserDto result = mapper.map(subSource, UserDto.class);

    assertThat(result.comment, equalTo("text"));
  }

  public static class User {
    Long id;
    Short age;

    @Mapping("username")
    private String name;

    String freeText;

    @Mapping("pk")
    public Long getId() {
      return id;
    }

    public void setId(Long id) {
      this.id = id;
    }

    public Short getAge() {
      return age;
    }

    public void setAge(Short age) {
      this.age = age;
    }

    public void setName(String name) {
      this.name = name;
    }
  }

  public static class SubUser extends User {}

  public static class UserDto {
    String id;
    String years;
    String pk;
    String name;
    String username;
    @Mapping("freeText")
    String comment;

    public String getPk() {
      return pk;
    }

    public void setPk(String pk) {
      this.pk = pk;
    }

    public String getId() {
      return id;
    }

    public void setId(String id) {
      this.id = id;
    }

    @Mapping("age")
    public String getYears() {
      return years;
    }

    public void setYears(String years) {
      this.years = years;
    }
  }

}<commit_msg>Unit-Tests for #100<commit_after>package org.dozer.functional_tests.annotation;

import org.dozer.Mapping;
import org.dozer.functional_tests.AbstractFunctionalTest;
import org.junit.Before;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;

/**
 * @author dmitry.buzdin
 */
public class AnnotationMappingTest extends AbstractFunctionalTest {

  private User source;
  private SubUser subSource;
  private UserDto destination;

  @Before
  public void setUp() throws Exception {
    super.setUp();
    source = new User();
    subSource = new SubUser();
    destination = new UserDto();
  }

  @Test
  public void shouldMapProperties() {
    source.setId(1L);

    UserDto result = mapper.map(source, UserDto.class);
    
    assertThat(result.getPk(), equalTo("1"));
    assertThat(result.getId(), nullValue());
  }

  @Test
  public void shouldMapProperties_Backwards() {
    source.setAge(new Short("1"));

    UserDto result = mapper.map(source, UserDto.class);
                                         
    assertThat(result.getYears(), equalTo("1"));
  }

  @Test
  public void shouldMapFields_Custom() {
    source.setName("name");

    UserDto result = mapper.map(source, UserDto.class);

    assertThat(result.username, equalTo("name"));
    assertThat(result.name, nullValue());
  }

  @Test
  public void shouldMapFields_Custom_Backwards() {
    source.freeText = "text";

    UserDto result = mapper.map(source, UserDto.class);

    assertThat(result.comment, equalTo("text"));
  }

  @Test
  public void shouldMapFields_Default() {
    source.setRole("role");

    UserDto result = mapper.map(source, UserDto.class);

    assertThat(result.role, equalTo("role"));
  }

  @Test
  public void shouldMapFields_Default_Backwards() {
    source.setZip("12345");

    UserDto result = mapper.map(source, UserDto.class);

    assertThat(result.zip, equalTo("12345"));
  }

  @Test
  public void shouldMapFields_Inherited() {
    subSource.setName("name");
    subSource.setRole("role");

    UserDto result = mapper.map(subSource, UserDto.class);

    assertThat(result.username, equalTo("name"));
    assertThat(result.role, equalTo("role"));
    assertThat(result.name, nullValue());
  }

  @Test
  public void shouldMapFields_Backwards_Inherited() {
    subSource.freeText = "text";
    subSource.setZip("12345");

    UserDto result = mapper.map(subSource, UserDto.class);

    assertThat(result.comment, equalTo("text"));
    assertThat(result.zip, equalTo("12345"));
  }

  public static class User {

    Long id;

    Short age;

    private String zip;

    @Mapping
    private String role;

    @Mapping("username")
    private String name;

    String freeText;

    @Mapping("pk")
    public Long getId() {
      return id;
    }

    public void setId(Long id) {
      this.id = id;
    }

    public Short getAge() {
      return age;
    }

    public void setAge(Short age) {
      this.age = age;
    }

    public void setName(String name) {
      this.name = name;
    }

    public void setRole(String role) {
      this.role = role;
    }

    public void setZip(String zip) {
      this.zip = zip;
    }
  }

  public static class SubUser extends User {}

  public static class UserDto {

    String id;

    String years;

    String pk;

    @Mapping
    String zip;

    String role;

    String name;

    String username;

    @Mapping("freeText")
    String comment;

    public String getPk() {
      return pk;
    }

    public void setPk(String pk) {
      this.pk = pk;
    }

    public String getId() {
      return id;
    }

    public void setId(String id) {
      this.id = id;
    }

    @Mapping("age")
    public String getYears() {
      return years;
    }

    public void setYears(String years) {
      this.years = years;
    }
  }
}
{'fraction_non_alphanumeric': 0.11700758117579746, 'fraction_numerical': 0.004434272636246603, 'mean_word_length': 2.8693967902600996, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4157756', 'n_tokens_mistral': 2263, 'n_tokens_neox': 2192, 'n_words': 506}