Skip to content

Commit

Permalink
Merge pull request #44 from Nylle/JAVAFIXTURE-43-introduce-editorconf…
Browse files Browse the repository at this point in the history
…ig-codestyle-settings

JAVAFIXTURE-43: Add root EditorConfig file
  • Loading branch information
Nylle authored Oct 12, 2020
2 parents fbcdb44 + 29117e2 commit bf2c09a
Show file tree
Hide file tree
Showing 48 changed files with 255 additions and 794 deletions.
634 changes: 0 additions & 634 deletions .codestyle/Default.codestyle.json

This file was deleted.

30 changes: 30 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
indent_style = space
tab_width = 4
insert_final_newline = true
trim_trailing_whitespace = true

ij_continuation_indent_size = 8
ij_smart_tabs = false
ij_wrap_on_typing = false

[*.java]
ij_java_imports_layout = com.**, org.**, |, *, |, java.**, javax.**, |, $*
ij_java_class_count_to_use_import_on_demand = 999
ij_java_names_count_to_use_import_on_demand = 999
ij_java_insert_inner_class_imports = false
ij_java_layout_static_imports_separately = true

ij_java_blank_lines_after_package = 1
ij_java_blank_lines_after_imports = 1

[*.json]
indent_size = 2

[{*.yaml, *.yml}]
indent_size = 2
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

Expand Down
28 changes: 14 additions & 14 deletions src/main/java/com/github/nylle/javafixture/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@ public Configuration(final int maxCollectionSize, final int minCollectionSize, f
this.usePositiveNumbersOnly = usePositiveNumbersOnly;
}

/**
* Creates a new default configuration with the following values
* <p><ul>
* <li>maxCollectionSize = 10
* <li>minCollectionSize = 2
* <li>streamSize = 3
* <li>usePositiveNumbersOnly = false
* <li>clock = Clock.fixed(Instant.now(), ZoneOffset.UTC)
* </ul><p>
*/
public static Configuration configure() {
return new Configuration();
}

/**
* @return the maximum size of arrays, collections and maps
*/
Expand Down Expand Up @@ -97,20 +111,6 @@ public boolean usePositiveNumbersOnly() {
return this.usePositiveNumbersOnly;
}

/**
* Creates a new default configuration with the following values
* <p><ul>
* <li>maxCollectionSize = 10
* <li>minCollectionSize = 2
* <li>streamSize = 3
* <li>usePositiveNumbersOnly = false
* <li>clock = Clock.fixed(Instant.now(), ZoneOffset.UTC)
* </ul><p>
*/
public static Configuration configure() {
return new Configuration();
}

/**
* @param streamSize the stream size when creating many objects at once
* @return this {@code Configuration}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/github/nylle/javafixture/Context.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class Context {

public Context(Configuration configuration) {

if(configuration == null) {
if (configuration == null) {
throw new IllegalArgumentException("configuration: null");
}

Expand Down
32 changes: 16 additions & 16 deletions src/main/java/com/github/nylle/javafixture/Fixture.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,22 @@ public static Fixture fixture() {
return new Fixture();
}

/**
* Returns a new default configuration with the following values
* <p><ul>
* <li>maxCollectionSize = 10
* <li>minCollectionSize = 2
* <li>streamSize = 3
* <li>usePositiveNumbersOnly = false
* <li>clock = Clock.fixed(Instant.now(), ZoneOffset.UTC)
* </ul><p>
*
* @return {@code Configuration}
*/
public static Configuration configuration() {
return new Configuration();
}

/**
* Creates a new object of the specified type, recursively populated with random values
*
Expand Down Expand Up @@ -157,20 +173,4 @@ public <T> void addManyTo(Collection<T> result, final Class<T> type) {
public <T> void addManyTo(Collection<T> result, final SpecimenType<T> type) {
result.addAll(new SpecimenBuilder<>(type, configuration).createMany().collect(Collectors.toList()));
}

/**
* Returns a new default configuration with the following values
* <p><ul>
* <li>maxCollectionSize = 10
* <li>minCollectionSize = 2
* <li>streamSize = 3
* <li>usePositiveNumbersOnly = false
* <li>clock = Clock.fixed(Instant.now(), ZoneOffset.UTC)
* </ul><p>
*
* @return {@code Configuration}
*/
public static Configuration configuration() {
return new Configuration();
}
}
18 changes: 9 additions & 9 deletions src/main/java/com/github/nylle/javafixture/InstanceFactory.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.github.nylle.javafixture;

import static java.lang.String.format;
import static java.util.Arrays.stream;
import static java.util.stream.Collectors.toList;
import org.objenesis.Objenesis;
import org.objenesis.ObjenesisStd;
import org.objenesis.instantiator.ObjectInstantiator;

import javassist.util.proxy.ProxyFactory;

import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
Expand All @@ -11,11 +13,9 @@
import java.util.Map;
import java.util.Random;

import org.objenesis.Objenesis;
import org.objenesis.ObjenesisStd;
import org.objenesis.instantiator.ObjectInstantiator;

import javassist.util.proxy.ProxyFactory;
import static java.lang.String.format;
import static java.util.Arrays.stream;
import static java.util.stream.Collectors.toList;

public class InstanceFactory {

Expand Down Expand Up @@ -63,7 +63,7 @@ public <T> Object proxy(final SpecimenType<T> type) {
}

public <T> Object proxy(final SpecimenType<T> type, final Map<String, ISpecimen<?>> specimens) {
if(type.isInterface()) {
if (type.isInterface()) {
return Proxy.newProxyInstance(
type.asClass().getClassLoader(),
new Class[] { type.asClass() },
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/com/github/nylle/javafixture/JavaFixture.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
*/
@Deprecated()
public class JavaFixture extends Fixture {
public JavaFixture() { super(); }
public JavaFixture(Configuration configuration) { super(configuration); }
public JavaFixture() {
super();
}

public JavaFixture(Configuration configuration) {
super(configuration);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.github.nylle.javafixture;

import javassist.util.proxy.MethodHandler;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
Expand All @@ -9,8 +11,6 @@

import static java.util.Arrays.stream;

import javassist.util.proxy.MethodHandler;

public class ProxyInvocationHandler implements InvocationHandler, MethodHandler {

private final SpecimenFactory specimenFactory;
Expand Down
40 changes: 20 additions & 20 deletions src/main/java/com/github/nylle/javafixture/SpecimenType.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,22 @@ public static <T> SpecimenType<T> fromRawType(final Class<?> rawType, final Type
return new SpecimenType<>(TypeCapture.create(rawType, actualTypeArguments));
}

public static Class<?> castToClass(Type type) {
if (type instanceof WildcardType) {
return Object.class;
}

if (isParameterized(type)) {
return (Class<?>) ((ParameterizedType) type).getRawType();
}

return (Class<?>) type;
}

public static boolean isParameterized(final Type type) {
return type instanceof ParameterizedType && ((ParameterizedType) type).getActualTypeArguments().length > 0;
}

public Class<T> asClass() {
return (Class<T>) castToClass(type);
}
Expand Down Expand Up @@ -73,23 +89,23 @@ public String getTypeParameterName(final int index) {
}

public Class<?> getComponentType() {
if(isArray()) {
if (isArray()) {
return asClass().getComponentType();
}

throw new SpecimenTypeException(format("%s is not an array", type));
}

public T[] getEnumConstants() {
if(isEnum()) {
if (isEnum()) {
return asClass().getEnumConstants();
}

throw new SpecimenTypeException(format("%s is not an enum", type));
}

public String getName() {
if(isParameterized()) {
if (isParameterized()) {
return asParameterizedType().getTypeName();
}

Expand Down Expand Up @@ -162,22 +178,6 @@ public boolean isAbstract() {
return Modifier.isAbstract(asClass().getModifiers());
}

public static Class<?> castToClass(Type type) {
if (type instanceof WildcardType) {
return Object.class;
}

if (isParameterized(type)) {
return (Class<?>) ((ParameterizedType) type).getRawType();
}

return (Class<?>) type;
}

public static boolean isParameterized(final Type type) {
return type instanceof ParameterizedType && ((ParameterizedType) type).getActualTypeArguments().length > 0;
}

@Override
public boolean equals(final Object o) {
if (this == o) {
Expand All @@ -190,7 +190,7 @@ public boolean equals(final Object o) {

final SpecimenType that = (SpecimenType) o;

if(isParameterized() != that.isParameterized()) {
if (isParameterized() != that.isParameterized()) {
return false;
}

Expand Down
20 changes: 10 additions & 10 deletions src/main/java/com/github/nylle/javafixture/TypeCapture.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,6 @@
import static java.lang.String.format;

abstract class TypeCapture<T> {
final Type capture() {
Type superclass = getClass().getGenericSuperclass();

if(!(superclass instanceof ParameterizedType)) {
throw new IllegalArgumentException(format("%s doesn't seem to have been instantiated with generic type arguments", superclass));
}

return ((ParameterizedType) superclass).getActualTypeArguments()[0];
}

static ParameterizedType create(final Class<?> rawType, final Type[] actualTypeArguments) {
if (rawType == null) {
throw new IllegalArgumentException("rawType: null");
Expand Down Expand Up @@ -72,4 +62,14 @@ public int hashCode() {
}
};
}

final Type capture() {
Type superclass = getClass().getGenericSuperclass();

if (!(superclass instanceof ParameterizedType)) {
throw new IllegalArgumentException(format("%s doesn't seem to have been instantiated with generic type arguments", superclass));
}

return ((ParameterizedType) superclass).getActualTypeArguments()[0];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
@ParameterizedTest
public @interface TestWithFixture {
int minCollectionSize() default 10;

int maxCollectionSize() default 10;

boolean positiveNumbersOnly() default false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private <T> T invoke(Method method, TestCase testCase) {
}

private <T> List<T> addTo(List<T> list, T value) {
if(list == null) {
if (list == null) {
list = new ArrayList<>();
}

Expand Down
Loading

0 comments on commit bf2c09a

Please sign in to comment.