Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
Moved GenericTypeDeterminer to core package, only used there
Moved ConstructorArguments to strategy package, only used there
  • Loading branch information
robert-bor committed Nov 6, 2017
1 parent 7b45833 commit 3787c8f
Show file tree
Hide file tree
Showing 14 changed files with 102 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Beanmapper

[![Build Status](https://travis-ci.org/42BV/beanmapper.svg?branch=master)](https://travis-ci.org/42BV/beanmapper)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/a78e3521eb2e4de48679b21d27a36458)](https://www.codacy.com/app/42bv/beanmapper)
[![codecov](https://codecov.io/gh/42BV/beanmapper/branch/master/graph/badge.svg)](https://codecov.io/gh/42BV/beanmapper)
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/io.beanmapper/beanmapper/badge.svg)](https://maven-badges.herokuapp.com/maven-central/io.beanmapper/beanmapper)
[![Apache 2](http://img.shields.io/badge/license-Apache%202-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0)
[![BCH compliance](https://bettercodehub.com/edge/badge/42BV/beanmapper?branch=master)](https://bettercodehub.com/)

# Beanmapper

Beanmapper is a Java library for mapping dissimilar Java classes with similar names. The use
cases for Beanmapper are the following:
* mapping from forms to entities, because:
Expand Down
4 changes: 0 additions & 4 deletions circle.yml

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/java/io/beanmapper/core/BeanField.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import io.beanmapper.core.inspector.PropertyAccessors;
import io.beanmapper.exceptions.BeanMappingException;
import io.beanmapper.exceptions.BeanNoSuchPropertyException;
import io.beanmapper.utils.ConstructorArguments;
import io.beanmapper.strategy.ConstructorArguments;
import io.beanmapper.utils.DefaultValues;

public class BeanField {
Expand Down
1 change: 0 additions & 1 deletion src/main/java/io/beanmapper/core/BeanMatchStore.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import io.beanmapper.core.unproxy.BeanUnproxy;
import io.beanmapper.exceptions.BeanMissingPathException;
import io.beanmapper.exceptions.BeanNoSuchPropertyException;
import io.beanmapper.utils.GenericTypeDeterminer;

public class BeanMatchStore {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.beanmapper.utils;
package io.beanmapper.core;

import static io.beanmapper.core.converter.collections.CollectionElementType.derived;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
package io.beanmapper.core.constructor;

import io.beanmapper.utils.ConstructorArguments;
import io.beanmapper.strategy.ConstructorArguments;

/**
* Abstraction that initializes beans.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import io.beanmapper.exceptions.BeanConstructException;
import io.beanmapper.exceptions.BeanInstantiationException;
import io.beanmapper.utils.ConstructorArguments;
import io.beanmapper.strategy.ConstructorArguments;

public class DefaultBeanInitializer implements BeanInitializer {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import io.beanmapper.core.converter.BeanConverter;
import io.beanmapper.exceptions.BeanConversionException;
import io.beanmapper.exceptions.BeanFieldNoMatchException;
import io.beanmapper.utils.ConstructorArguments;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.beanmapper.utils;
package io.beanmapper.strategy;

import java.util.ArrayList;
import java.util.List;
Expand Down
37 changes: 37 additions & 0 deletions src/test/java/io/beanmapper/BeanMapperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;

Expand Down Expand Up @@ -129,6 +130,7 @@
import io.beanmapper.testmodel.person.Person;
import io.beanmapper.testmodel.person.PersonAo;
import io.beanmapper.testmodel.person.PersonForm;
import io.beanmapper.testmodel.person.PersonResult;
import io.beanmapper.testmodel.person.PersonView;
import io.beanmapper.testmodel.project.CodeProject;
import io.beanmapper.testmodel.project.CodeProjectResult;
Expand Down Expand Up @@ -410,6 +412,34 @@ public void mapTreeMap() {
assertEquals("Korneel", targetItems.get("korneel").name);
}

@Test
public void direcltyMapSet_comparable() {
Set<Long> source = new TreeSet<Long>() {{
add(13L);
add(29L);
add(43L);
}};
Set<String> target = beanMapper.map(source, String.class);
assertEquals(TreeSet.class, target.getClass());
assertEquals(3, target.size());
assertTrue(target.contains("13"));
assertTrue(target.contains("29"));
assertTrue(target.contains("43"));
}

@Test
public void direcltyMapSet_nonComparable() {
Set<Person> source = new HashSet<Person>() {{
add(new Person() {{
this.setName("Henk");
}});
}};
Set<PersonResult> target = beanMapper.map(source, PersonResult.class);
assertEquals(HashSet.class, target.getClass());
assertEquals(1, target.size());
assertEquals("Henk", target.iterator().next().name);
}

@Test
public void mapToCollectionArraysAsList() {
List<RGB> collection = Arrays.asList(RGB.values());
Expand Down Expand Up @@ -1399,6 +1429,13 @@ public void beanPropertyNestedMismatch() {
beanMapper.map(source, TargetNestedBeanProperty.class);
}

@Test
public void wrap_mustAlwaysWrap() {
assertNotSame(beanMapper.getConfiguration(), beanMapper.wrapConfig().build().getConfiguration());
assertNotSame(beanMapper.getConfiguration(), beanMapper.config().build().getConfiguration());
assertNotSame(beanMapper.getConfiguration(), beanMapper.wrap().build().getConfiguration());
}

public Person createPerson(String name) {
Person person = new Person();
person.setId(1984L);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import io.beanmapper.core.constructor.DefaultBeanInitializer;
import io.beanmapper.core.unproxy.BeanUnproxy;
import io.beanmapper.exceptions.BeanConfigurationOperationNotAllowedException;
import io.beanmapper.utils.ConstructorArguments;
import io.beanmapper.strategy.ConstructorArguments;
import mockit.Deencapsulation;

import org.junit.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import io.beanmapper.BeanMapper;
import io.beanmapper.core.constructor.DefaultBeanInitializer;
import io.beanmapper.utils.ConstructorArguments;
import io.beanmapper.strategy.ConstructorArguments;

import org.junit.Before;
import org.junit.Test;
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/io/beanmapper/utils/CheckTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package io.beanmapper.utils;

import org.junit.Test;

public class CheckTest {

@Test
public void construct() {
// codecov expects a util class to be constructed
new Check();
new Classes();
new DefaultValues();
}

}
41 changes: 41 additions & 0 deletions src/test/java/io/beanmapper/utils/ClassesTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package io.beanmapper.utils;

import static org.junit.Assert.assertEquals;

import java.util.List;

import org.junit.Test;

public class ClassesTest {

@Test(expected = IllegalArgumentException.class)
public void nonExistingClass() {
Classes.forName("a.b.c.DoesNotExist");
}

@Test
public void genericTypeOfClassWithGenericType() {
ClassWithGeneric source = new ClassWithGeneric();
assertEquals(String.class, source.getType());
}

@Test
public void genericTypeOfClassWithoutGenericType() {
ClassWithNestedGeneric source = new ClassWithNestedGeneric();
assertEquals(List.class, source.getType());
}

public static class AbstractClassWithGeneric<C> {
private final Class<C> type;
public AbstractClassWithGeneric() {
this.type = (Class<C>)Classes.getParameteredTypes(getClass())[0];
}
public Class<C> getType() { return type; }
}

public static class ClassWithGeneric extends AbstractClassWithGeneric<String> {
}

public static class ClassWithNestedGeneric extends AbstractClassWithGeneric<List<String>> {
}
}

0 comments on commit 3787c8f

Please sign in to comment.