Skip to content

Commit

Permalink
Readded units4j dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-schnell committed Feb 25, 2024
1 parent 4351a73 commit f6387b6
Show file tree
Hide file tree
Showing 15 changed files with 75 additions and 291 deletions.
6 changes: 6 additions & 0 deletions common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.fuin</groupId>
<artifactId>units4j</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand Down
47 changes: 1 addition & 46 deletions common/src/test/java/org/fuin/objects4j/common/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,14 @@
*/
package org.fuin.objects4j.common;

import com.tngtech.archunit.core.domain.JavaClass;
import com.tngtech.archunit.core.domain.JavaModifier;
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchIgnore;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.lang.ArchCondition;
import com.tngtech.archunit.lang.ArchRule;
import com.tngtech.archunit.lang.ConditionEvents;
import com.tngtech.archunit.lang.SimpleConditionEvent;

import java.util.Collection;
import java.util.Set;

import static com.tngtech.archunit.lang.ConditionEvent.createMessage;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
import static java.util.Collections.emptySet;
import static java.util.stream.Collectors.toSet;
import static org.fuin.units4j.archunit.AllTopLevelClassesHaveATestCondition.haveACorrespondingClassEndingWith;

@AnalyzeClasses(packagesOf = BaseTest.class)
class BaseTest {
Expand All @@ -50,41 +41,5 @@ class BaseTest {
.and().areNotAnnotatedWith(ArchIgnore.class)
.should(haveACorrespondingClassEndingWith("Test"));

private static ArchCondition<JavaClass> haveACorrespondingClassEndingWith(String suffix) {
return new AllTopLevelClassesHaveATestCondition(suffix);
}

private static class AllTopLevelClassesHaveATestCondition extends ArchCondition<JavaClass> {

private final String suffix;

private Set<String> testedClassNames;

public AllTopLevelClassesHaveATestCondition(final String suffix) {
super("have a corresponding test class with suffix '" + suffix + "'");
this.suffix = suffix;
this.testedClassNames = emptySet();
}

@Override
public void init(Collection<JavaClass> allClasses) {
testedClassNames = allClasses.stream()
.map(JavaClass::getName)
.filter(className -> className.endsWith(suffix))
.map(className -> className.substring(0, className.length() - suffix.length()))
.collect(toSet());
}

@Override
public void check(JavaClass clazz, ConditionEvents events) {
if (!clazz.getName().endsWith(suffix)) {
boolean satisfied = testedClassNames.contains(clazz.getName());
String message = createMessage(clazz, "has " + (satisfied ? "a" : "no") + " corresponding test class");
events.add(new SimpleConditionEvent(clazz, satisfied, message));
}
}

}

}

6 changes: 6 additions & 0 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.fuin</groupId>
<artifactId>units4j</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand Down
32 changes: 20 additions & 12 deletions core/src/main/java/org/fuin/objects4j/core/KeyValue.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/**
* Copyright (C) 2015 Michael Schnell. All rights reserved.
* Copyright (C) 2015 Michael Schnell. All rights reserved.
* http://www.fuin.org/
*
* <p>
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option) any
* later version.
*
* <p>
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* <p>
* You should have received a copy of the GNU Lesser General Public License
* along with this library. If not, see http://www.gnu.org/licenses/.
*/
Expand Down Expand Up @@ -46,7 +46,7 @@ protected KeyValue() {

/**
* Constructor with key and value.
*
*
* @param key
* Key.
* @param value
Expand All @@ -62,7 +62,7 @@ public KeyValue(@NotNull @TrimmedNotEmpty final String key, final Object value)

/**
* Returns the key.
*
*
* @return Key.
*/
public final String getKey() {
Expand All @@ -71,7 +71,7 @@ public final String getKey() {

/**
* Returns the value.
*
*
* @return Value.
*/
public final Object getValue() {
Expand All @@ -80,7 +80,7 @@ public final Object getValue() {

/**
* Returns the value as string.
*
*
* @return Value or "null".
*/
public final String getValueString() {
Expand All @@ -90,15 +90,23 @@ public final String getValueString() {
return value.toString();
}

@Override
public String toString() {
return "KeyValue{" +
"key='" + key + '\'' +
", value=" + value +
'}';
}

/**
* Replaces all variables in the format "${NAME}" with the corresponding value. NAME is the name of a key from the <code>keyValue</code>
* array.
*
*
* @param message
* Message to replace.
* @param keyValue
* Array of key values or {@literal null}.
*
*
* @return Replaced message.
*/
public static String replace(final String message, final KeyValue... keyValue) {
Expand Down Expand Up @@ -134,12 +142,12 @@ private static String nullSafeAsString(final Object obj) {

/**
* Replaces all variables inside a string with values from a map.
*
*
* @param str
* Text with variables (Format: ${key} ) - May be {@literal null} or empty.
* @param vars
* Map with key/values (both of type <code>String</code> - Cannot be {@literal null}.
*
*
* @return String with replaced variables. Unknown variables will remain unchanged.
*/
public static String replaceVars(final String str, final Map<String, String> vars) {
Expand Down
47 changes: 1 addition & 46 deletions core/src/test/java/org/fuin/objects4j/core/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,14 @@
*/
package org.fuin.objects4j.core;

import com.tngtech.archunit.core.domain.JavaClass;
import com.tngtech.archunit.core.domain.JavaModifier;
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchIgnore;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.lang.ArchCondition;
import com.tngtech.archunit.lang.ArchRule;
import com.tngtech.archunit.lang.ConditionEvents;
import com.tngtech.archunit.lang.SimpleConditionEvent;

import java.util.Collection;
import java.util.Set;

import static com.tngtech.archunit.lang.ConditionEvent.createMessage;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
import static java.util.Collections.emptySet;
import static java.util.stream.Collectors.toSet;
import static org.fuin.units4j.archunit.AllTopLevelClassesHaveATestCondition.haveACorrespondingClassEndingWith;

@AnalyzeClasses(packagesOf = BaseTest.class)
class BaseTest {
Expand All @@ -50,41 +41,5 @@ class BaseTest {
.and().areNotAnnotatedWith(ArchIgnore.class)
.should(haveACorrespondingClassEndingWith("Test"));

private static ArchCondition<JavaClass> haveACorrespondingClassEndingWith(String suffix) {
return new AllTopLevelClassesHaveATestCondition(suffix);
}

private static class AllTopLevelClassesHaveATestCondition extends ArchCondition<JavaClass> {

private final String suffix;

private Set<String> testedClassNames;

public AllTopLevelClassesHaveATestCondition(final String suffix) {
super("have a corresponding test class with suffix '" + suffix + "'");
this.suffix = suffix;
this.testedClassNames = emptySet();
}

@Override
public void init(Collection<JavaClass> allClasses) {
testedClassNames = allClasses.stream()
.map(JavaClass::getName)
.filter(className -> className.endsWith(suffix))
.map(className -> className.substring(0, className.length() - suffix.length()))
.collect(toSet());
}

@Override
public void check(JavaClass clazz, ConditionEvents events) {
if (!clazz.getName().endsWith(suffix)) {
boolean satisfied = testedClassNames.contains(clazz.getName());
String message = createMessage(clazz, "has " + (satisfied ? "a" : "no") + " corresponding test class");
events.add(new SimpleConditionEvent(clazz, satisfied, message));
}
}

}

}

6 changes: 6 additions & 0 deletions jackson/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.fuin</groupId>
<artifactId>units4j</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand Down
48 changes: 1 addition & 47 deletions jackson/src/test/java/org/fuin/objects4j/jackson/BaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,14 @@
*/
package org.fuin.objects4j.jackson;

import com.tngtech.archunit.core.domain.JavaClass;
import com.tngtech.archunit.core.domain.JavaModifier;
import com.tngtech.archunit.junit.AnalyzeClasses;
import com.tngtech.archunit.junit.ArchIgnore;
import com.tngtech.archunit.junit.ArchTest;
import com.tngtech.archunit.lang.ArchCondition;
import com.tngtech.archunit.lang.ArchRule;
import com.tngtech.archunit.lang.ConditionEvents;
import com.tngtech.archunit.lang.SimpleConditionEvent;

import java.util.Collection;
import java.util.Set;

import static com.tngtech.archunit.lang.ConditionEvent.createMessage;
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
import static java.util.Collections.emptySet;
import static java.util.stream.Collectors.toSet;
import static org.fuin.units4j.archunit.AllTopLevelClassesHaveATestCondition.haveACorrespondingClassEndingWithTest;

@AnalyzeClasses(packagesOf = CurrencyAmountJacksonSerializer.class)
public class BaseTest {
Expand All @@ -50,42 +41,5 @@ public class BaseTest {
.and().areNotAnnotatedWith(ArchIgnore.class)
.should(haveACorrespondingClassEndingWithTest());

private static ArchCondition<JavaClass> haveACorrespondingClassEndingWithTest() {
return new AllTopLevelClassesHaveATestCondition("Test");
}

private static class AllTopLevelClassesHaveATestCondition extends ArchCondition<JavaClass> {

private final String suffix;

private Set<String> testedClassNames;

public AllTopLevelClassesHaveATestCondition(final String suffix) {
super("have a corresponding test class with suffix '" + suffix + "'");
this.suffix = suffix;
this.testedClassNames = emptySet();
}

@Override
public void init(Collection<JavaClass> allClasses) {
testedClassNames = allClasses.stream()
.map(JavaClass::getName)
.filter(className -> className.endsWith(suffix))
.map(className -> className.substring(0, className.length() - suffix.length()))
.collect(toSet());
}

@Override
public void check(JavaClass clazz, ConditionEvents events) {
if (!clazz.getName().endsWith(suffix)) {
boolean satisfied = testedClassNames.contains(clazz.getName());
String message = createMessage(clazz, "has " + (satisfied ? "a" : "no") + " corresponding test class");
events.add(new SimpleConditionEvent(clazz, satisfied, message));
}
}

}


}

6 changes: 6 additions & 0 deletions jaxb/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
<artifactId>jsr305</artifactId>
</dependency>

<dependency>
<groupId>org.fuin</groupId>
<artifactId>units4j</artifactId>
<scope>test</scope>
</dependency>

<!-- Test -->

<dependency>
Expand Down
Loading

0 comments on commit f6387b6

Please sign in to comment.