Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #110 : Error when field's name ends with the name of the containing class. #149

Merged
merged 1 commit into from
Apr 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);

}