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

Updated dependencies and gradle #236

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
37 changes: 19 additions & 18 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@ buildscript {
}

plugins {
id 'com.gradle.build-scan' version '1.11'
id "com.jfrog.bintray" version "1.8.0"
id "org.sonarqube" version "2.6.1"
id 'org.unbroken-dome.test-sets' version '1.4.2'
id "info.solidsoft.pitest" version "1.2.4"
id 'com.gradle.build-scan' version '3.0'
id "com.jfrog.bintray" version "1.8.4"
id "org.sonarqube" version "2.8"
id 'org.unbroken-dome.test-sets' version '2.2.1'
id "info.solidsoft.pitest" version "1.4.5"
id "io.freefair.lombok" version "4.1.4"
}

ext {
JUNIT_JUPITER_VERSION = "5.0.2"
JUNIT_PLATFORM_VERSION = "1.0.2"
MOCKITO_VERSION = "2.12.0"
MOCKITO_VERSION = "3.1.0"
POWER_MOCK_UTILS_VERSION = "1.6.6"
ASSERTJ_CORE_VERSION = "3.8.0"
JACOCO_VERSION = "0.7.9"
JACOCO_VERSION = "0.8.5"
}

apply plugin: 'java'
Expand All @@ -35,8 +36,8 @@ apply plugin: 'org.junit.platform.gradle.plugin'
apply plugin: 'maven-publish'

buildScan {
licenseAgreementUrl = 'https://gradle.com/terms-of-service'
licenseAgree = 'yes'
termsOfServiceUrl = 'https://gradle.com/terms-of-service'
termsOfServiceAgree = 'yes'
publishAlways()
}

Expand Down Expand Up @@ -82,20 +83,19 @@ junitPlatform {
}

dependencies {
compile("org.slf4j:slf4j-api:1.7.25")
compile("org.apache.commons:commons-lang3:3.7")
compile("org.apache.commons:commons-collections4:4.1")
compile("com.googlecode.combinatoricslib:combinatoricslib:2.1")
compile("org.javassist:javassist:3.22.0-GA")
compile("org.slf4j:slf4j-api:1.7.29")
compile("org.apache.commons:commons-lang3:3.9")
compile("org.apache.commons:commons-collections4:4.4")
compile("com.googlecode.combinatoricslib:combinatoricslib:2.2")
compile("org.javassist:javassist:3.26.0-GA")

testCompile("org.projectlombok:lombok:1.16.18")
testCompile("org.junit.jupiter:junit-jupiter-api:${JUNIT_JUPITER_VERSION}") { changing = true }
testRuntime("org.junit.jupiter:junit-jupiter-engine:${JUNIT_JUPITER_VERSION}") { changing = true }
testCompile("org.junit.platform:junit-platform-runner:${JUNIT_PLATFORM_VERSION}") { changing = true }
testCompile("org.assertj:assertj-core:${ASSERTJ_CORE_VERSION}")
testCompile("org.mockito:mockito-core:${MOCKITO_VERSION}")
testCompile("org.powermock.tests:powermock-tests-utils:${POWER_MOCK_UTILS_VERSION}")
testCompileOnly("org.apiguardian:apiguardian-api:1.0.0")
testCompileOnly("org.apiguardian:apiguardian-api:1.1.0")
}

afterEvaluate {
Expand Down Expand Up @@ -124,10 +124,11 @@ pitest {
threads = 4
outputFormats = ['XML', 'HTML']
}

/*
task wrapper(type: Wrapper) {
gradleVersion = '4.4'
gradleVersion = '5.6.4'
}
*/

def pomConfig = {
licenses {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
7 changes: 4 additions & 3 deletions src/main/java/pl/pojo/tester/internal/utils/FieldUtils.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package pl.pojo.tester.internal.utils;

import org.paukov.combinatorics.Factory;
import org.paukov.combinatorics.CombinatoricsVector;
import org.paukov.combinatorics.Generator;
import org.paukov.combinatorics.ICombinatoricsVector;
import org.paukov.combinatorics.subsets.SubSetGenerator;
import pl.pojo.tester.internal.GetOrSetValueException;

import java.lang.reflect.Field;
Expand Down Expand Up @@ -33,8 +34,8 @@ public static List<Field> getAllFieldsExcluding(final Class<?> clazz, final List
}

public static List<List<Field>> permutations(final List<Field> fields) {
final ICombinatoricsVector<Field> vector = Factory.createVector(fields);
final Generator<Field> subSetGenerator = Factory.createSubSetGenerator(vector);
final ICombinatoricsVector<Field> vector = new CombinatoricsVector(fields);
final Generator<Field> subSetGenerator = new SubSetGenerator(vector);
return subSetGenerator.generateAllObjects()
.stream()
.map(ICombinatoricsVector::getVector)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,124 @@
package pl.pojo.tester.internal.field.primitive;
package pl.pojo.tester.internal.utils;


import org.junit.jupiter.api.Test;
import org.paukov.combinatorics.CombinatoricsVector;
import org.paukov.combinatorics.Generator;
import org.paukov.combinatorics.ICombinatoricsVector;
import org.paukov.combinatorics.subsets.SubSetGenerator;
import pl.pojo.tester.internal.GetOrSetValueException;

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public final class FieldUtils {

import static org.assertj.core.api.Assertions.assertThat;
private static final String MODIFIERS_FIELD_NAME_IN_FIELD_CLASS = "modifiers";

private FieldUtils() {
}

class AbstractPrimitiveValueChangerTest {
public static List<Field> getAllFields(final Class<?> clazz) {
return Arrays.stream(clazz.getDeclaredFields())
.filter(FieldUtils::isNotSynthetic)
.filter(FieldUtils::isNotStatic)
.collect(Collectors.toList());
}

@Test
void Should_Return_False_When_Field_Is_Not_Primitive() throws Exception {
// given
final Field field = Thread.class.getDeclaredField("threadQ");
final AbstractPrimitiveValueChanger<Object> changerMock = new ImplementationForTest();
public static List<Field> getAllFieldsExcluding(final Class<?> clazz, final List<String> excludedFields) {
return getAllFields(clazz).stream()
.filter(field -> doesNotContain(field, excludedFields))
.collect(Collectors.toList());
}

// when
final boolean result = changerMock.canChange(field.getType());
public static List<List<Field>> permutations(final List<Field> fields) {
final ICombinatoricsVector<Field> vector = new CombinatoricsVector(fields);
final Generator<Field> subSetGenerator = new SubSetGenerator(vector);
return subSetGenerator.generateAllObjects()
.stream()
.map(ICombinatoricsVector::getVector)
.filter(FieldUtils::excludeEmptySet)
.collect(Collectors.toList());
}

// then
assertThat(result).isFalse();
public static List<String> getAllFieldNames(final Class<?> clazz) {
return getAllFields(clazz).stream()
.map(Field::getName)
.collect(Collectors.toList());
}

private class ImplementationForTest extends AbstractPrimitiveValueChanger<Object> {
public static Object getValue(final Object targetObject, final Field field) {
try {
makeModifiable(field);
return field.get(targetObject);
} catch (final IllegalAccessException e) {
throw new GetOrSetValueException(field.getName(), targetObject.getClass(), e);
}
}

public static void setValue(final Object targetObject, final Field field, final Object value) {
try {
makeModifiable(field);
field.set(targetObject, value);
} catch (final IllegalAccessException e) {
throw new GetOrSetValueException(field.getName(), targetObject.getClass(), e);
}
}

public static List<Field> getFields(final Class<?> testedClass, final Predicate<String> predicate) {
return getAllFields(testedClass).stream()
.filter(eachField -> predicate.test(eachField.getName()))
.collect(Collectors.toList());
}

public static boolean isFinal(final Field field) {
final int fieldModifiers = field.getModifiers();
return Modifier.isFinal(fieldModifiers);
}

public static List<Field> getSpecifiedFields(final Class<?> clazz, final List<String> names) {
return names.stream()
.map(name -> getField(clazz, name))
.collect(Collectors.toList());
}

private static void makeModifiable(final Field field) {
final Class<? extends Field> clazz = field.getClass();
try {
field.setAccessible(true);
final Field modifierField = clazz.getDeclaredField(MODIFIERS_FIELD_NAME_IN_FIELD_CLASS);
modifierField.setAccessible(true);

final int modifiers = field.getModifiers() & ~Modifier.FINAL;
modifierField.setInt(field, modifiers);
} catch (IllegalAccessException | NoSuchFieldException e) {
throw new GetOrSetValueException(MODIFIERS_FIELD_NAME_IN_FIELD_CLASS, clazz, e);
}
}

private static boolean excludeEmptySet(final List<Field> fields) {
return !fields.isEmpty();
}

private static boolean isNotSynthetic(final Field field) {
return !field.isSynthetic();
}

private static boolean isNotStatic(final Field field) {
return !Modifier.isStatic(field.getModifiers());
}

private static boolean doesNotContain(final Field field, final List<String> excludedFields) {
return !excludedFields.contains(field.getName());
}

@Override
protected Object increase(final Object value) {
return null;
private static Field getField(final Class<?> clazz, final String name) {
try {
return clazz.getDeclaredField(name);
} catch (final java.lang.NoSuchFieldException e) {
throw new GetOrSetValueException(name, clazz, e);
}
}
}