Skip to content

Commit

Permalink
Added tests, Configuration uses Boolean instead of boolean. OverrideF…
Browse files Browse the repository at this point in the history
…ield reset() renamed to block(). StrictMappingProperties.getBeanUnproxy() removed.
  • Loading branch information
robert-bor committed Nov 4, 2017
1 parent fa3c6f1 commit 7b45833
Show file tree
Hide file tree
Showing 39 changed files with 364 additions and 92 deletions.
7 changes: 3 additions & 4 deletions docs/src/test/java/io/beanmapper/BeanAliasExample.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package io.beanmapper;

import static junit.framework.Assert.assertEquals;

import io.beanmapper.annotations.BeanAlias;
import io.beanmapper.annotations.BeanConstruct;
import io.beanmapper.annotations.BeanUnwrap;
import io.beanmapper.config.BeanMapperBuilder;
import org.junit.Test;

import static junit.framework.Assert.assertEquals;
import org.junit.Test;

public class BeanAliasExample {

Expand Down
11 changes: 6 additions & 5 deletions docs/src/test/java/io/beanmapper/BeanCollectionExample.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package io.beanmapper;

import io.beanmapper.annotations.BeanCollection;
import io.beanmapper.annotations.BeanCollectionUsage;
import io.beanmapper.config.BeanMapperBuilder;
import org.junit.Test;
import static junit.framework.Assert.assertEquals;

import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import static junit.framework.Assert.assertEquals;
import io.beanmapper.annotations.BeanCollection;
import io.beanmapper.annotations.BeanCollectionUsage;
import io.beanmapper.config.BeanMapperBuilder;

import org.junit.Test;

public class BeanCollectionExample {

Expand Down
11 changes: 3 additions & 8 deletions docs/src/test/java/io/beanmapper/BeanConstructExample.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
package io.beanmapper;

import io.beanmapper.annotations.BeanCollection;
import io.beanmapper.annotations.BeanCollectionUsage;
import static junit.framework.Assert.assertEquals;

import io.beanmapper.annotations.BeanConstruct;
import io.beanmapper.config.BeanMapperBuilder;
import org.junit.Test;

import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import static junit.framework.Assert.assertEquals;
import org.junit.Test;

public class BeanConstructExample {

Expand Down
7 changes: 3 additions & 4 deletions docs/src/test/java/io/beanmapper/BeanDefaultExample.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package io.beanmapper;

import static junit.framework.Assert.assertEquals;

import io.beanmapper.annotations.BeanDefault;
import io.beanmapper.annotations.BeanIgnore;
import io.beanmapper.config.BeanMapperBuilder;
import org.junit.Test;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNull;
import org.junit.Test;

public class BeanDefaultExample {

Expand Down
7 changes: 3 additions & 4 deletions docs/src/test/java/io/beanmapper/BeanIgnoreExample.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package io.beanmapper;

import static junit.framework.Assert.assertNull;

import io.beanmapper.annotations.BeanIgnore;
import io.beanmapper.annotations.BeanProperty;
import io.beanmapper.config.BeanMapperBuilder;
import org.junit.Test;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNull;
import org.junit.Test;

public class BeanIgnoreExample {

Expand Down
5 changes: 3 additions & 2 deletions docs/src/test/java/io/beanmapper/BeanPropertyExample.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package io.beanmapper;

import static junit.framework.Assert.assertEquals;

import io.beanmapper.annotations.BeanProperty;
import io.beanmapper.config.BeanMapperBuilder;
import org.junit.Test;

import static junit.framework.Assert.assertEquals;
import org.junit.Test;

public class BeanPropertyExample {

Expand Down
9 changes: 5 additions & 4 deletions docs/src/test/java/io/beanmapper/NestedToNestedExample.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package io.beanmapper;

import io.beanmapper.annotations.BeanProperty;
import io.beanmapper.config.BeanMapperBuilder;
import org.junit.Test;
import static org.junit.Assert.assertEquals;

import java.time.LocalDate;

import static org.junit.Assert.assertEquals;
import io.beanmapper.annotations.BeanProperty;
import io.beanmapper.config.BeanMapperBuilder;

import org.junit.Test;

public class NestedToNestedExample {

Expand Down
12 changes: 7 additions & 5 deletions docs/src/test/java/io/beanmapper/StrategiesExample.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package io.beanmapper;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.beanmapper.config.BeanMapperBuilder;
import org.junit.Test;
import static junit.framework.Assert.assertEquals;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static junit.framework.Assert.assertEquals;
import io.beanmapper.config.BeanMapperBuilder;

import org.junit.Test;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class StrategiesExample {

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/beanmapper/config/BeanMapperBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
import io.beanmapper.core.constructor.BeanInitializer;
import io.beanmapper.core.converter.BeanConverter;
import io.beanmapper.core.converter.collections.CollectionConverter;
import io.beanmapper.core.converter.impl.AnyToEnumConverter;
import io.beanmapper.core.converter.impl.NumberToNumberConverter;
import io.beanmapper.core.converter.impl.ObjectToStringConverter;
import io.beanmapper.core.converter.impl.PrimitiveConverter;
import io.beanmapper.core.converter.impl.StringToBigDecimalConverter;
import io.beanmapper.core.converter.impl.StringToBooleanConverter;
import io.beanmapper.core.converter.impl.AnyToEnumConverter;
import io.beanmapper.core.converter.impl.StringToIntegerConverter;
import io.beanmapper.core.converter.impl.StringToLongConverter;
import io.beanmapper.core.unproxy.BeanUnproxy;
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/io/beanmapper/config/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public interface Configuration {
* collection has taken place.
* @return true if the flush-chain must be called after a clear
*/
boolean isFlushAfterClear();
Boolean isFlushAfterClear();

/**
* Determines if flushing has been enabled. Flushing is the calling of flush() on a collection
Expand All @@ -178,14 +178,14 @@ public interface Configuration {
* case, the flush will throw an exception.
* @return whether flushing has been enabled
*/
boolean isFlushEnabled();
Boolean isFlushEnabled();

/**
* Works on the combination of the global flush setting (flushEnabled) and the specific flush
* setting (flushAfterClear). If both are true, the flush will trigger.
* @return true if a flush after clear must take place
*/
boolean mustFlush();
Boolean mustFlush();

/**
* Add a converter class (must inherit from abstract BeanConverter class) to the beanMapper.
Expand Down Expand Up @@ -356,7 +356,7 @@ public interface Configuration {
* Determines whether the flush-chain must be called after a clear has taken place.
* @param flushAfterClear true if the flush-chain must be called
*/
void setFlushAfterClear(boolean flushAfterClear);
void setFlushAfterClear(Boolean flushAfterClear);

/**
* Set whether flushing must be enabled. Flushing is the calling of flush() on a collection
Expand All @@ -365,6 +365,6 @@ public interface Configuration {
* case, the flush will throw an exception.
* @param flushEnabled whether flushing has been enabled
*/
void setFlushEnabled(boolean flushEnabled);
void setFlushEnabled(Boolean flushEnabled);

}
12 changes: 6 additions & 6 deletions src/main/java/io/beanmapper/config/CoreConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public class CoreConfiguration implements Configuration {

private CollectionFlusher collectionFlusher = new CollectionFlusher();

private boolean flushEnabled = false;
private Boolean flushEnabled = false;

@Override
public List<String> getDownsizeTarget() { return null; }
Expand Down Expand Up @@ -194,17 +194,17 @@ public CollectionFlusher getCollectionFlusher() {
}

@Override
public boolean isFlushAfterClear() {
public Boolean isFlushAfterClear() {
return false;
}

@Override
public boolean isFlushEnabled() {
public Boolean isFlushEnabled() {
return this.flushEnabled;
}

@Override
public boolean mustFlush() {
public Boolean mustFlush() {
return false;
}

Expand Down Expand Up @@ -338,13 +338,13 @@ public void setPreferredCollectionClass(Class<?> preferredCollectionClass) {
}

@Override
public void setFlushAfterClear(boolean flushAfterClear) {
public void setFlushAfterClear(Boolean flushAfterClear) {
throw new BeanConfigurationOperationNotAllowedException(
"Illegal to set flush after clear on the core configuration");
}

@Override
public void setFlushEnabled(boolean flushEnabled) {
public void setFlushEnabled(Boolean flushEnabled) {
this.flushEnabled = flushEnabled;
}

Expand Down
28 changes: 13 additions & 15 deletions src/main/java/io/beanmapper/config/OverrideConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public class OverrideConfiguration implements Configuration {

private Class<?> preferredCollectionClass = null;

private Boolean flushAfterClear = null;
private OverrideField<Boolean> flushAfterClear;

private Boolean flushEnabled = null;
private OverrideField<Boolean> flushEnabled;

public OverrideConfiguration(Configuration configuration) {
if (configuration == null) {
Expand All @@ -55,6 +55,8 @@ public OverrideConfiguration(Configuration configuration) {
this.beanInitializer = new OverrideField<>(configuration::getBeanInitializer);
this.parent = new OverrideField<>(configuration::getParent);
this.converterChoosable = new OverrideField<>(configuration::isConverterChoosable);
this.flushAfterClear = new OverrideField<>(configuration::isFlushAfterClear);
this.flushEnabled = new OverrideField<>(configuration::isFlushEnabled);
}

@Override
Expand Down Expand Up @@ -202,21 +204,17 @@ public BeanCollectionUsage getCollectionUsage() {
}

@Override
public boolean isFlushAfterClear() {
return this.flushAfterClear == null ?
parentConfiguration.isFlushAfterClear() :
this.flushAfterClear;
public Boolean isFlushAfterClear() {
return flushAfterClear.get();
}

@Override
public boolean isFlushEnabled() {
return this.flushEnabled == null ?
parentConfiguration.isFlushEnabled() :
this.flushEnabled;
public Boolean isFlushEnabled() {
return flushEnabled.get();
}

@Override
public boolean mustFlush() {
public Boolean mustFlush() {
return isFlushEnabled() && isFlushAfterClear();
}

Expand Down Expand Up @@ -341,13 +339,13 @@ public void setPreferredCollectionClass(Class<?> preferredCollectionClass) {
}

@Override
public void setFlushAfterClear(boolean flushAfterClear) {
this.flushAfterClear = flushAfterClear;
public void setFlushAfterClear(Boolean flushAfterClear) {
this.flushAfterClear.set(flushAfterClear);
}

@Override
public void setFlushEnabled(boolean flushEnabled) {
this.flushEnabled = flushEnabled;
public void setFlushEnabled(Boolean flushEnabled) {
this.flushEnabled.set(flushEnabled);
}

}
2 changes: 1 addition & 1 deletion src/main/java/io/beanmapper/config/OverrideField.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void set(T value) {
}
}

public void reset() {
public void block() {
this.block = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ public StrictMappingProperties(
this.applyStrictMappingConvention = applyStrictMappingConvention;
}

public BeanUnproxy getBeanUnproxy() {
return beanUnproxy;
}

public String getStrictSourceSuffix() {
return strictSourceSuffix;
}
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/io/beanmapper/core/BeanField.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,8 @@ public PropertyAccessor getProperty() {

public Object getObject(Object object) throws BeanMappingException {
Object valueObject = getCurrentField().getValue(object);
if (hasNext()) {
if (valueObject != null) {
return getNext().getObject(valueObject);
}
if (hasNext() && valueObject != null) {
return getNext().getObject(valueObject);
}
return valueObject;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

public class BeanFieldNoMatchException extends BeanMappingException {

public BeanFieldNoMatchException(String error) {
super(error);
public static final String ERROR = "No source field found while attempting to map to %s.%s";

public BeanFieldNoMatchException(Class clazz, String fieldName) {
super(String.format(ERROR, clazz, fieldName));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ public class BeanMissingPathException extends BeanMappingException {

public static final String ERROR = "The path for the class could not be resolved %s.%s";

public BeanMissingPathException(String error) {
super(error);
}

public BeanMissingPathException(Class<?> clazz, String name, Throwable rootCause) {
super(String.format(ERROR, clazz.getName(), name), rootCause);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ private void dealWithNonMatchingNode(BeanFieldMatch beanFieldMatch) {
if (beanFieldMatch.targetHasAnnotation(BeanDefault.class)) {
beanFieldMatch.setTarget(beanFieldMatch.getTargetDefaultValue());
} else if (beanFieldMatch.targetHasAnnotation(BeanProperty.class)) {
throw new BeanFieldNoMatchException("No source field found while attempting to map to " + beanFieldMatch.getTargetFieldName());
throw new BeanFieldNoMatchException(beanFieldMatch.getTargetClass(), beanFieldMatch.getTargetFieldName());
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/test/java/io/beanmapper/BeanMapperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@
import io.beanmapper.testmodel.encapsulate.ResultManyToMany;
import io.beanmapper.testmodel.encapsulate.ResultManyToOne;
import io.beanmapper.testmodel.encapsulate.ResultOneToMany;
import io.beanmapper.testmodel.encapsulate.sourceAnnotated.Car;
import io.beanmapper.testmodel.encapsulate.sourceAnnotated.CarDriver;
import io.beanmapper.testmodel.encapsulate.sourceAnnotated.Driver;
import io.beanmapper.testmodel.encapsulate.source_annotated.Car;
import io.beanmapper.testmodel.encapsulate.source_annotated.CarDriver;
import io.beanmapper.testmodel.encapsulate.source_annotated.Driver;
import io.beanmapper.testmodel.enums.ColorEntity;
import io.beanmapper.testmodel.enums.ColorResult;
import io.beanmapper.testmodel.enums.ColorStringResult;
Expand Down
Loading

0 comments on commit 7b45833

Please sign in to comment.