Skip to content
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package io.beanmother.builder;

import java.lang.reflect.InvocationTargetException;

import io.beanmother.core.AbstractBeanMother;
import io.beanmother.core.common.FixtureMap;
import io.beanmother.core.common.FixtureTemplate;
import io.beanmother.core.common.FixtureValue;
import io.beanmother.core.converter.ConverterFactory;
import io.beanmother.core.mapper.ConstructHelper;
import io.beanmother.core.mapper.DefaultFixtureMapper;
import io.beanmother.core.postprocessor.PostProcessor;

import java.lang.reflect.InvocationTargetException;

public class BuilderObjectMother extends AbstractBeanMother {

private final static BuilderObjectMother beanMother = new BuilderObjectMother();
private static final BuilderObjectMother beanMother = new BuilderObjectMother();

public static BuilderObjectMother getInstance() {
return beanMother;
Expand All @@ -22,10 +20,10 @@ public static BuilderObjectMother getInstance() {
/**
* A key of FixtureMap that is a kind of source for creating a instance, using builder pattern.
*/
public final static String INIT_BUILDER_KEY = "_initBuilder";
public final static String FINISH_BUILDER_KEY = "_finishBuilder";
public final static String TARGET_BUILDER_KEY = "_targetClass";
public final static String CONSTRUCT_BUILDER_KEY = "_construct";
public static final String INIT_BUILDER_KEY = "_initBuilder";
public static final String FINISH_BUILDER_KEY = "_finishBuilder";
public static final String TARGET_BUILDER_KEY = "_targetClass";
public static final String CONSTRUCT_BUILDER_KEY = "_construct";

public BuilderObjectMother() {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class ObjectMother extends AbstractBeanMother {

private final static ObjectMother beanMother = new ObjectMother();
private static final ObjectMother beanMother = new ObjectMother();

public static ObjectMother getInstance() {
return beanMother;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public boolean hasParent() {

@Override
public boolean equals(Object obj) {
if (obj == null || !(obj instanceof FixtureValue)) return false;
if (!(obj instanceof FixtureValue)) return false;
return ((FixtureValue) obj).getValue().equals(this.getValue());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
public abstract class KnownConverterModuleLoader {

private final static String[] knownConverterModules;
private static final String[] knownConverterModules;

static {
knownConverterModules = new String[]{
Expand Down Expand Up @@ -39,9 +39,7 @@ public static List<ConverterModule> load() {
} catch (Exception e) {
e.printStackTrace();
}
} catch (ClassNotFoundException e) {
// Do nothing
} catch (ClassCastException e) {
} catch (ClassNotFoundException | ClassCastException e) {
// Do nothing
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ public class StringToBooleanConverter extends AbstractGenericConverter<String, B
/**
* Strings that represent true value.
*/
private final static Set<String> TRUE_STRING;
private static final Set<String> TRUE_STRING;

/**
* Strings that represent false value.
*/
private final static Set<String> FALSE_STRING;
private static final Set<String> FALSE_STRING;

static {
TRUE_STRING = new HashSet<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
*/
public class StringToCalendarConverter extends AbstractGenericConverter<String, Calendar> {

private final static StringToDateConverter stringToDateConverter = new StringToDateConverter();
private final static DateToCalendarConverter dateToCalendarConverter = new DateToCalendarConverter();
private static final StringToDateConverter stringToDateConverter = new StringToDateConverter();
private static final DateToCalendarConverter dateToCalendarConverter = new DateToCalendarConverter();

@Override
public Calendar convert(String source) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
* @see <a href="http://natty.joestelmach.com">natty</a>
*/
public class StringToDateConverter extends AbstractGenericConverter<String, Date> {
private final static Parser dateParser = new Parser();
private static final Parser dateParser = new Parser();

@Override
public Date convert(String source) {
List<DateGroup> groups = dateParser.parse(source);
if (groups.size() > 0 && groups.get(0).getDates().size() > 0) {
if (!groups.isEmpty() && !groups.get(0).getDates().isEmpty()) {
return groups.get(0).getDates().get(0);
}
throw new ConverterException("can not convert '" + source + "' to java.util.Date");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
*/
public class StringToSQLDateConverter extends AbstractGenericConverter<String, Date> {

private final static StringToDateConverter stringToDateConverter = new StringToDateConverter();
private final static DateToSQLDateConverter dateToSQLDateConverter = new DateToSQLDateConverter();
private static final StringToDateConverter stringToDateConverter = new StringToDateConverter();
private static final DateToSQLDateConverter dateToSQLDateConverter = new DateToSQLDateConverter();

@Override
public Date convert(String source) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ public class YamlFixtureParser implements FixtureParser {
@SuppressWarnings("unchecked")
@Override
public Map<String, FixtureMap> parse(String fixture) {
Map<String, ? extends Object> fixtures = buildYaml().loadAs(fixture, Map.class);;
Map<String, ?> fixtures = buildYaml().loadAs(fixture, Map.class);
Map<String, FixtureMap> fixtureMaps = new HashMap<>();

for (String key : fixtures.keySet()) {
if (fixtures.get(key) instanceof Map) {
FixtureMap fixtureMap = FixtureTemplateWrapper.wrap((Map) fixtures.get(key), key, null);
for (Map.Entry<String, ?> entry : fixtures.entrySet()) {
if (entry.getValue() instanceof Map) {
FixtureMap fixtureMap = FixtureTemplateWrapper.wrap((Map<String, ?>) entry.getValue(), entry.getKey(), null);
fixtureMap.setRoot(true);
fixtureMaps.put(key, fixtureMap);
fixtureMaps.put(entry.getKey(), fixtureMap);
} else {
throw new FixtureFormatException(key, " the root of fixture data should be key - value");
throw new FixtureFormatException(entry.getKey(), " the root of fixture data should be key - value");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public List<File> scan(Location location) {
/**
* Check the file is a fixture file or not.
* Subclass can override this method to determine which file is a fixture file.
* @param file
* @param file file
* @return {@code true} if the file is a fixture file.
*/
protected boolean isFixtureFile(File file) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public interface FixtureScanner {

/**
* Find all fixture files in the location.
* @param location
* @param location location
* @return All fixture files.
*/
List<File> scan(Location location);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
public class DefaultFixturesStore implements FixturesStore {

private final static Logger logger = LoggerFactory.getLogger(DefaultFixtureMapper.class);
private static final Logger logger = LoggerFactory.getLogger(DefaultFixtureMapper.class);

/**
* Scanner to load fixture files.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public abstract class ConstructHelper {
/**
* A key of FixtureMap that is a kind of source for creating a instance.
*/
private final static String CONSTRUCT_KEY = "_construct";
private static final String CONSTRUCT_KEY = "_construct";

/**
* Create instance of a given type.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ public interface FixtureConverter {

/**
* Convert the fixtureTemplate to the give type.
* @param fixtureTemplate
* @param typeToken
* @param fixtureTemplate fixture template
* @param typeToken type token
* @return converted object
*/
Object convert(FixtureTemplate fixtureTemplate, TypeToken<?> typeToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@
*/
@SuppressWarnings("unchecked")
public class FixtureConverterImpl implements FixtureConverter {
private final static Logger logger = LoggerFactory.getLogger(FixtureConverterImpl.class);
private static final Logger logger = LoggerFactory.getLogger(FixtureConverterImpl.class);

private final static String java8OptionalConverterKlass = "io.beanmother.java8.converter.OptionalTypeFixtureConverter";
private final static String guavaOptionalConverterKlass = "io.beanmother.guava.converter.OptionalTypeFixtureConverter";
private static final String java8OptionalConverterKlass = "io.beanmother.java8.converter.OptionalTypeFixtureConverter";
private static final String guavaOptionalConverterKlass = "io.beanmother.guava.converter.OptionalTypeFixtureConverter";

private MapperMediator mapperMediator;
private ConverterFactory converterFactory;

/**
* Create a FixtureConverterImpl
* @param mapperMediator
* @param converterFactory
* @param mapperMediator mapper mediator
* @param converterFactory converter factory
*/
public FixtureConverterImpl(MapperMediator mapperMediator, ConverterFactory converterFactory) {
this.mapperMediator = mapperMediator;
Expand Down Expand Up @@ -120,11 +120,9 @@ protected Object convert(FixtureValue fixtureValue, TypeToken<?> typeToken) {

/**
* Convert the fixtureList to the given TypeToken
* @param fixtureList
* @param typeToken
* @param fixtureList fixture list
* @param typeToken type token
* @return converted object from fixtureList.
* @throws IllegalAccessException
* @throws InstantiationException
*/
protected Object convert(FixtureList fixtureList, TypeToken<?> typeToken) {
boolean isArray = typeToken.isArray();
Expand Down Expand Up @@ -158,7 +156,7 @@ protected Object convert(FixtureList fixtureList, TypeToken<?> typeToken) {
}

// not found converter
if (convertedList.size() == 0) return null;
if (convertedList.isEmpty()) return null;

if(isArray) {
if (elementTypeToken.isPrimitive()) {
Expand All @@ -176,11 +174,9 @@ protected Object convert(FixtureList fixtureList, TypeToken<?> typeToken) {

/**
* Convert FixtureMap to given type
* @param fixtureMap
* @param typeToken
* @param fixtureMap fixture Map
* @param typeToken type token
* @return converted Object from fixtureMap
* @throws IllegalAccessException
* @throws InstantiationException
*/
protected Object convert(FixtureMap fixtureMap, TypeToken<?> typeToken) {
if (typeToken.isSubtypeOf(Map.class)) {
Expand Down Expand Up @@ -226,7 +222,6 @@ protected Object convert(FixtureMap fixtureMap, TypeToken<?> typeToken) {
}

private boolean isJava8OptionalTypeToken(TypeToken<?> typeToken) {
String name = typeToken.getRawType().getName();
return typeToken.getRawType().getName().equals("java.util.Optional");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public interface FixtureMapper {

/**
* map data to target object.
* @param fixtureMap
* @param target
* @param fixtureMap fixture map
* @param target target
*/
void map(FixtureMap fixtureMap, Object target);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class MapperMediatorImpl implements MapperMediator {

/**
* Create a MapperMediatorImpl.
* @param converterFactory
* @param converterFactory coverter factory
*/
public MapperMediatorImpl(ConverterFactory converterFactory) {
this.fixtureConverter = new FixtureConverterImpl(this, converterFactory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@
* It maps target object properties by setter and maps public field as a fallback.
*/
public class SetterAndFieldFixtureMapper extends AbstractFixtureMapper implements FixtureMapper {
private final static Logger logger = LoggerFactory.getLogger(SetterAndFieldFixtureMapper.class);
private static final Logger logger = LoggerFactory.getLogger(SetterAndFieldFixtureMapper.class);

/**
* A prefix of setter names
*/
private final static String SETTER_PREFIX = "set";
private static final String SETTER_PREFIX = "set";

/**
* Create a SetterAndFieldFixtureMapper
*
* @param mapperMediator
* @param mapperMediator mapper mediator
*/
public SetterAndFieldFixtureMapper(MapperMediator mapperMediator) {
super(mapperMediator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public abstract class PostProcessor<T> implements Comparable<PostProcessor<T>> {
/**
* Default priority.
*/
public final static int DEFAULT_PRIORITY = 5;
public static final int DEFAULT_PRIORITY = 5;

private int priority = DEFAULT_PRIORITY;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public abstract class MethodReflectionEvalScriptRunner implements ScriptRunner {

private final static ConverterFactory converterFactory = new ConverterFactory();
private static final ConverterFactory converterFactory = new ConverterFactory();

public abstract Object getTargetObject();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ public class ScriptFragment {
/**
* Script pattern of the value inside of {@link FixtureValue}
*/
private final static Pattern FIXTURE_VALUE_SCRIPT_PATTERN = Pattern.compile("(?<=\\$\\{)(.+?)(?=})");
private static final Pattern FIXTURE_VALUE_SCRIPT_PATTERN = Pattern.compile("(?<=\\$\\{)(.+?)(?=})");

/**
* Script Arguments pattern
*/
private final static Pattern ARGUMENTS_PATTERN = Pattern.compile("(?<=\\()(.*?)(?=\\))");
private static final Pattern ARGUMENTS_PATTERN = Pattern.compile("(?<=\\()(.*?)(?=\\))");


private final static String FRAGMENT_DELIM = "\\.";
private static final String FRAGMENT_DELIM = "\\.";

/**
* Script method name
Expand Down Expand Up @@ -98,16 +98,16 @@ public static boolean isScript(FixtureValue fixtureValue) {

/**
* Create a ScriptFragment
* @param methodName
* @param methodName method name
*/
public ScriptFragment(String methodName) {
this.methodName = methodName.trim();
}

/**
* Create a ScriptFragment.
* @param methodName
* @param arguments
* @param methodName method name
* @param arguments arguments
*/
public ScriptFragment(String methodName, String ... arguments) {
this(methodName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public interface ScriptHandler {

/**
* Run script and return the result.
* @param scriptFragment
* @param scriptFragment script fragment
*/
Object runScript(ScriptFragment scriptFragment);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
*/
public class FakerScriptRunner extends MethodReflectionEvalScriptRunner {

private final static String SCRIPT_NAMESPACE = "faker";
private final static String OPTION_FAKER_FRAGMENT_METHOD_NAME = "options";
private static final String SCRIPT_NAMESPACE = "faker";
private static final String OPTION_FAKER_FRAGMENT_METHOD_NAME = "options";

private final static Faker faker = new Faker();
private static final Faker faker = new Faker();

@Override
public Object run(ScriptFragment scriptFragment) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
*/
public class SequenceScriptRunner implements ScriptRunner {

private final static String NAMESPACE = "sequence";
private static final String NAMESPACE = "sequence";

private final static String NUMBER_SEQUENCE_METHOD_NAME = "number";
private static final String NUMBER_SEQUENCE_METHOD_NAME = "number";

private AtomicLong longSequence = new AtomicLong(0);

Expand Down
Loading