Skip to content

Commit

Permalink
Merge pull request #755 from uhafner/no-equals-filtered-log
Browse files Browse the repository at this point in the history
Remove equals from `FilteredLog`
  • Loading branch information
uhafner authored May 9, 2023
2 parents 2f8b79b + 93fcde1 commit c5c70b4
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 54 deletions.
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
<commons.lang.version>3.12.0</commons.lang.version>
<commons.io.version>2.11.0</commons.io.version>
<javax.annotation-api.version>1.3.2</javax.annotation-api.version>
<byte-buddy.version>1.14.4</byte-buddy.version>

<!-- Project Test Dependencies Configuration -->
<equalsverifier.version>3.14.1</equalsverifier.version>
Expand Down Expand Up @@ -126,6 +127,11 @@
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>${byte-buddy.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -628,6 +634,7 @@
</dependency>
</dependencies>
<configuration>
<skip>true</skip>
<versionFormat>[-0-9.]*</versionFormat>
<failBuildOnProblemsFound>true</failBuildOnProblemsFound>
<checkDependencies>true</checkDependencies>
Expand Down
33 changes: 0 additions & 33 deletions src/main/java/edu/hm/hafner/util/FilteredLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.locks.ReentrantLock;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;

import com.google.errorprone.annotations.FormatMethod;

import edu.umd.cs.findbugs.annotations.CheckForNull;

/**
* Provides a log of info messages and a limited number of error messages. If the number of errors exceeds this limit,
* then subsequent error messages will be skipped. This class is thread-safe and can be used in a distributed
Expand Down Expand Up @@ -263,34 +260,4 @@ public void merge(final FilteredLog other) {
lock.unlock();
}
}

@Override @Generated
public boolean equals(@CheckForNull final Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
FilteredLog that = (FilteredLog) o;
return maxLines == that.maxLines && lines == that.lines && title.equals(that.title)
&& infoMessages.equals(that.infoMessages)
&& errorMessages.equals(that.errorMessages);
}

@Override @Generated
public int hashCode() {
return Objects.hash(title, maxLines, lines, infoMessages, errorMessages);
}

@Override @Generated
public String toString() {
return "FilteredLog{"
+ "title='" + title + '\''
+ ", maxLines=" + maxLines
+ ", lines=" + lines
+ ", infoMessages=" + infoMessages
+ ", errorMessages=" + errorMessages
+ '}';
}
}
3 changes: 0 additions & 3 deletions src/test/java/edu/hm/hafner/util/ArchitectureRules.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,6 @@ private ArchitectureRules() {
// prevents instantiation
}

/**
* Predicate to match exception constructor calls without contexts.
*/
private static ArchCondition<JavaMethod> beProtected() {
return new ShouldBeProtectedCondition();
}
Expand Down
8 changes: 7 additions & 1 deletion src/test/java/edu/hm/hafner/util/ArchitectureRulesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import com.tngtech.archunit.core.domain.JavaClasses;
import com.tngtech.archunit.core.importer.ClassFileImporter;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;

import static org.assertj.core.api.Assertions.*;

/**
Expand Down Expand Up @@ -139,7 +141,9 @@ private Object readResolve() {
}

@SuppressWarnings("all") @Generated // This class is just there to be used in architecture tests
@SuppressFBWarnings("SE")
public static class ArchitectureRulesAlsoViolatedTest implements Serializable {

/**
* Called after de-serialization to retain backward compatibility.
*
Expand All @@ -150,7 +154,8 @@ private Object readResolve() {
}
}

@SuppressWarnings("all") // This class is just there to be used in architecture tests
@SuppressWarnings("all") @Generated // This class is just there to be used in architecture tests
@SuppressFBWarnings("SE")
static final class ArchitectureRulesPassedTest implements Serializable {
@Test
void shouldPass() {
Expand All @@ -168,6 +173,7 @@ private Object readResolve() {
}

@SuppressWarnings("all") // This class is just there to be used in architecture tests
@SuppressFBWarnings("SE")
static class ArchitectureRulesAlsoPassedTest implements Serializable {
/**
* Called after de-serialization to retain backward compatibility.
Expand Down
20 changes: 3 additions & 17 deletions src/test/java/edu/hm/hafner/util/FilteredLogTest.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package edu.hm.hafner.util;

import java.util.concurrent.locks.ReentrantLock;

import org.apache.commons.lang3.StringUtils;
import org.assertj.core.api.recursive.comparison.RecursiveComparisonConfiguration;
import org.junit.jupiter.api.Test;

import nl.jqno.equalsverifier.EqualsVerifier;
import nl.jqno.equalsverifier.Warning;

import static edu.hm.hafner.util.assertions.Assertions.*;

/**
Expand Down Expand Up @@ -128,7 +124,7 @@ void shouldLog20ErrorsByDefault() {
@Override
protected void assertThatRestoredInstanceEqualsOriginalInstance(final FilteredLog original,
final FilteredLog restored) {
assertThat(original).isEqualTo(restored);
assertThat(original).usingRecursiveComparison(RecursiveComparisonConfiguration.builder().withIgnoredFields("lock").build()).isEqualTo(restored);
}

private FilteredLog createLogWith20Elements() {
Expand All @@ -154,16 +150,6 @@ void shouldManuallyUseSerializationHelpers() {
byte[] bytes = toByteArray(serializable);
FilteredLog restored = restore(bytes);

assertThat(restored).isEqualTo(serializable);
}

@Test
void shouldObeyEqualsContract() {
EqualsVerifier.forClass(FilteredLog.class)
.usingGetClass()
.withPrefabValues(ReentrantLock.class, new ReentrantLock(), new ReentrantLock())
.withRedefinedSuperclass()
.suppress(Warning.NONFINAL_FIELDS)
.verify();
assertThatRestoredInstanceEqualsOriginalInstance(serializable, restored);
}
}

0 comments on commit c5c70b4

Please sign in to comment.