Skip to content

Commit

Permalink
Fix #110 : Selma get confused when field's name ends with the name of
Browse files Browse the repository at this point in the history
the containing class.
  • Loading branch information
FaniloRandria committed Apr 22, 2017
1 parent 31a6eb3 commit 934aa18
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void removeSourcePrefix(String simpleName, String fqcn) {

private String removePrefixes(String key, String simpleName, String fqcn) {
key = key.replace(simpleName + ".", "");
return key.replace(fqcn + ".", "");
return key.replaceFirst("^" + fqcn + "\\.", "");
}

public boolean hasEmbedded() {
Expand Down
22 changes: 22 additions & 0 deletions processor/src/test/java/fr/xebia/extras/selma/beans/Home.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package fr.xebia.extras.selma.beans;

/**
* @author FaniloRandria
*/
public class Home {

private Phone phoneHome;

public Home (Phone phoneHome) {
this.phoneHome = phoneHome;
}

public Phone getPhoneHome() {
return phoneHome;
}

public void setPhoneHome(Phone phoneHome) {
this.phoneHome = phoneHome;
}

}
18 changes: 18 additions & 0 deletions processor/src/test/java/fr/xebia/extras/selma/beans/HomeDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package fr.xebia.extras.selma.beans;

/**
* @author FaniloRandria
*/
public class HomeDto {

public String phone;

public String getPhone() {
return phone;
}

public void setPhone(String phone) {
this.phone = phone;
}

}
22 changes: 22 additions & 0 deletions processor/src/test/java/fr/xebia/extras/selma/beans/Phone.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package fr.xebia.extras.selma.beans;

/**
* @author FaniloRandria
*/
public class Phone {

private String phoneNumber;

public Phone (String phoneNumber) {
this.phoneNumber = phoneNumber;
}

public String getPhoneNumber() {
return phoneNumber;
}

public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}

}
32 changes: 32 additions & 0 deletions processor/src/test/java/fr/xebia/extras/selma/it/HomeMapperIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package fr.xebia.extras.selma.it;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.Test;

import fr.xebia.extras.selma.Selma;
import fr.xebia.extras.selma.beans.Home;
import fr.xebia.extras.selma.beans.HomeDto;
import fr.xebia.extras.selma.beans.Phone;
import fr.xebia.extras.selma.it.mappers.HomeMapper;
import fr.xebia.extras.selma.it.utils.Compile;
import fr.xebia.extras.selma.it.utils.IntegrationTestBase;

/**
* @author FaniloRandria
*/
@Compile(withClasses = HomeMapper.class)
public class HomeMapperIT extends IntegrationTestBase {

public static final String NUMBER_PHONE = "06-11-22-33-44";

@Test
public void beanMapperTest() throws Exception {
HomeMapper mapper = Selma.getMapper(HomeMapper.class);
Phone phone = new Phone(NUMBER_PHONE);
Home home = new Home(phone);
HomeDto homeDto = mapper.toDto(home);
assertThat(homeDto.getPhone()).isEqualTo(NUMBER_PHONE);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package fr.xebia.extras.selma.it.mappers;

import fr.xebia.extras.selma.Field;
import fr.xebia.extras.selma.Mapper;
import fr.xebia.extras.selma.Maps;
import fr.xebia.extras.selma.beans.Home;
import fr.xebia.extras.selma.beans.HomeDto;

/**
* @author FaniloRandria
*/
@Mapper
public interface HomeMapper {

@Maps(withCustomFields = {
@Field(value = {"phone", "phoneHome.phoneNumber"})
}) HomeDto toDto (Home in);

}

0 comments on commit 934aa18

Please sign in to comment.