Skip to content

Commit

Permalink
Code quality improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisJehan committed Sep 11, 2024
1 parent 30001ac commit 9946e56
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,15 @@ final class DsvMendCandidateTest {
private static final String[] VALUE = ObjectArrays.of("foo");
private static final double SCORE = 1.0d;

private final DsvMendCandidate mendCandidate = new DsvMendCandidate(VALUE, SCORE);
private final DsvMendCandidate dsvMendCandidate = new DsvMendCandidate(VALUE, SCORE);

@Test
void testConstructorImmutable() {
final var value = VALUE.clone();
final var mendCandidate = new DsvMendCandidate(value, SCORE);
value[0] = null;
assertThat(mendCandidate.getValue()).isEqualTo(VALUE);
assertThat(new DsvMendCandidate(value, SCORE)).satisfies(immutableDsvMendCandidate -> {
value[0] = null;
assertThat(immutableDsvMendCandidate.getValue()).isEqualTo(VALUE);
});
}

@Test
Expand All @@ -59,38 +60,38 @@ void testConstructorInvalid() {

@Test
void testEqualsAndHashCodeAndToString() {
assertThat(mendCandidate.equals(mendCandidate)).isTrue();
assertThat(mendCandidate).isNotEqualTo(new Object());
assertThat(new DsvMendCandidate(VALUE, SCORE)).satisfies(otherMendCandidate -> {
assertThat(mendCandidate).isNotSameAs(otherMendCandidate);
assertThat(mendCandidate).isEqualTo(otherMendCandidate);
assertThat(mendCandidate).hasSameHashCodeAs(otherMendCandidate);
assertThat(mendCandidate).hasToString(otherMendCandidate.toString());
assertThat(dsvMendCandidate.equals(dsvMendCandidate)).isTrue();
assertThat(dsvMendCandidate).isNotEqualTo(new Object());
assertThat(new DsvMendCandidate(VALUE, SCORE)).satisfies(otherDsvMendCandidate -> {
assertThat(otherDsvMendCandidate).isNotSameAs(dsvMendCandidate);
assertThat(otherDsvMendCandidate).isEqualTo(dsvMendCandidate);
assertThat(otherDsvMendCandidate).hasSameHashCodeAs(dsvMendCandidate);
assertThat(otherDsvMendCandidate).hasToString(dsvMendCandidate.toString());
});
assertThat(new DsvMendCandidate(ObjectArrays.of("bar"), SCORE)).satisfies(otherMendCandidate -> {
assertThat(mendCandidate).isNotSameAs(otherMendCandidate);
assertThat(mendCandidate).isNotEqualTo(otherMendCandidate);
assertThat(mendCandidate).doesNotHaveSameHashCodeAs(otherMendCandidate);
assertThat(mendCandidate).doesNotHaveToString(otherMendCandidate.toString());
assertThat(new DsvMendCandidate(ObjectArrays.of("bar"), SCORE)).satisfies(otherDsvMendCandidate -> {
assertThat(otherDsvMendCandidate).isNotSameAs(dsvMendCandidate);
assertThat(otherDsvMendCandidate).isNotEqualTo(dsvMendCandidate);
assertThat(otherDsvMendCandidate).doesNotHaveSameHashCodeAs(dsvMendCandidate);
assertThat(otherDsvMendCandidate).doesNotHaveToString(dsvMendCandidate.toString());
});
assertThat(new DsvMendCandidate(VALUE, 2.0d)).satisfies(otherMendCandidate -> {
assertThat(mendCandidate).isNotSameAs(otherMendCandidate);
assertThat(mendCandidate).isNotEqualTo(otherMendCandidate);
assertThat(mendCandidate).doesNotHaveSameHashCodeAs(otherMendCandidate);
assertThat(mendCandidate).doesNotHaveToString(otherMendCandidate.toString());
assertThat(new DsvMendCandidate(VALUE, 2.0d)).satisfies(otherDsvMendCandidate -> {
assertThat(otherDsvMendCandidate).isNotSameAs(dsvMendCandidate);
assertThat(otherDsvMendCandidate).isNotEqualTo(dsvMendCandidate);
assertThat(otherDsvMendCandidate).doesNotHaveSameHashCodeAs(dsvMendCandidate);
assertThat(otherDsvMendCandidate).doesNotHaveToString(dsvMendCandidate.toString());
});
}

@Test
void testGetters() {
assertThat(mendCandidate.getValue()).isEqualTo(VALUE);
assertThat(mendCandidate.getScore()).isEqualTo(SCORE);
assertThat(dsvMendCandidate.getValue()).isEqualTo(VALUE);
assertThat(dsvMendCandidate.getScore()).isEqualTo(SCORE);
}

@Test
void testGettersImmutable() {
assertThat(mendCandidate.getValue()).isEqualTo(VALUE);
mendCandidate.getValue()[0] = null;
assertThat(mendCandidate.getValue()).isEqualTo(VALUE);
assertThat(dsvMendCandidate.getValue()).isEqualTo(VALUE);
dsvMendCandidate.getValue()[0] = null;
assertThat(dsvMendCandidate.getValue()).isEqualTo(VALUE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,15 @@ final class DsvMendResultTest {
BEST_CANDIDATE = candidate;
}

private final DsvMendResult mendResult = new DsvMendResult(VALUE, CANDIDATES, BEST_CANDIDATE);
private final DsvMendResult dsvMendResult = new DsvMendResult(VALUE, CANDIDATES, BEST_CANDIDATE);

@Test
void testConstructorImmutable() {
final var value = VALUE.clone();
final var mendResult = new DsvMendResult(value, CANDIDATES, BEST_CANDIDATE);
value[0] = null;
assertThat(mendResult.getValue()).isEqualTo(VALUE);
assertThat(new DsvMendResult(value, CANDIDATES, BEST_CANDIDATE)).satisfies(immutableDsvMendResult -> {
value[0] = null;
assertThat(immutableDsvMendResult.getValue()).isEqualTo(VALUE);
});
}

@Test
Expand All @@ -75,31 +76,31 @@ void testConstructorInvalid() {

@Test
void testEqualsAndHashCodeAndToString() {
assertThat(mendResult.equals(mendResult)).isTrue();
assertThat(mendResult).isNotEqualTo(new Object());
assertThat(dsvMendResult.equals(dsvMendResult)).isTrue();
assertThat(dsvMendResult).isNotEqualTo(new Object());
assertThat(
new DsvMendResult(
VALUE,
CANDIDATES,
BEST_CANDIDATE
)
).satisfies(otherMendResult -> {
assertThat(mendResult).isNotSameAs(otherMendResult);
assertThat(mendResult).isEqualTo(otherMendResult);
assertThat(mendResult).hasSameHashCodeAs(otherMendResult);
assertThat(mendResult).hasToString(otherMendResult.toString());
).satisfies(otherDsvMendResult -> {
assertThat(otherDsvMendResult).isNotSameAs(dsvMendResult);
assertThat(otherDsvMendResult).isEqualTo(dsvMendResult);
assertThat(otherDsvMendResult).hasSameHashCodeAs(dsvMendResult);
assertThat(otherDsvMendResult).hasToString(dsvMendResult.toString());
});
assertThat(
new DsvMendResult(
ObjectArrays.of("bar"),
CANDIDATES,
BEST_CANDIDATE
)
).satisfies(otherMendResult -> {
assertThat(mendResult).isNotSameAs(otherMendResult);
assertThat(mendResult).isNotEqualTo(otherMendResult);
assertThat(mendResult).doesNotHaveSameHashCodeAs(otherMendResult);
assertThat(mendResult).doesNotHaveToString(otherMendResult.toString());
).satisfies(otherDsvMendResult -> {
assertThat(otherDsvMendResult).isNotSameAs(dsvMendResult);
assertThat(otherDsvMendResult).isNotEqualTo(dsvMendResult);
assertThat(otherDsvMendResult).doesNotHaveSameHashCodeAs(dsvMendResult);
assertThat(otherDsvMendResult).doesNotHaveToString(dsvMendResult.toString());
});
assertThat(
new DsvMendResult(
Expand All @@ -110,37 +111,37 @@ void testEqualsAndHashCodeAndToString() {
),
BEST_CANDIDATE
)
).satisfies(otherMendResult -> {
assertThat(mendResult).isNotSameAs(otherMendResult);
assertThat(mendResult).isNotEqualTo(otherMendResult);
assertThat(mendResult).doesNotHaveSameHashCodeAs(otherMendResult);
assertThat(mendResult).doesNotHaveToString(otherMendResult.toString());
).satisfies(otherDsvMendResult -> {
assertThat(otherDsvMendResult).isNotSameAs(dsvMendResult);
assertThat(otherDsvMendResult).isNotEqualTo(dsvMendResult);
assertThat(otherDsvMendResult).doesNotHaveSameHashCodeAs(dsvMendResult);
assertThat(otherDsvMendResult).doesNotHaveToString(dsvMendResult.toString());
});
assertThat(
new DsvMendResult(
VALUE,
CANDIDATES,
new DsvMendCandidate(ObjectArrays.of("bar"), 2.0d)
)
).satisfies(otherMendResult -> {
assertThat(mendResult).isNotSameAs(otherMendResult);
assertThat(mendResult).isNotEqualTo(otherMendResult);
assertThat(mendResult).doesNotHaveSameHashCodeAs(otherMendResult);
assertThat(mendResult).doesNotHaveToString(otherMendResult.toString());
).satisfies(otherDsvMendResult -> {
assertThat(otherDsvMendResult).isNotSameAs(dsvMendResult);
assertThat(otherDsvMendResult).isNotEqualTo(dsvMendResult);
assertThat(otherDsvMendResult).doesNotHaveSameHashCodeAs(dsvMendResult);
assertThat(otherDsvMendResult).doesNotHaveToString(dsvMendResult.toString());
});
}

@Test
void testGetters() {
assertThat(mendResult.getValue()).isEqualTo(VALUE);
assertThat(mendResult.getCandidates()).isEqualTo(CANDIDATES);
assertThat(mendResult.getBestCandidate()).isEqualTo(BEST_CANDIDATE);
assertThat(dsvMendResult.getValue()).isEqualTo(VALUE);
assertThat(dsvMendResult.getCandidates()).isEqualTo(CANDIDATES);
assertThat(dsvMendResult.getBestCandidate()).isEqualTo(BEST_CANDIDATE);
}

@Test
void testGettersImmutable() {
assertThat(mendResult.getValue()).isEqualTo(VALUE);
mendResult.getValue()[0] = null;
assertThat(mendResult.getValue()).isEqualTo(VALUE);
assertThat(dsvMendResult.getValue()).isEqualTo(VALUE);
dsvMendResult.getValue()[0] = null;
assertThat(dsvMendResult.getValue()).isEqualTo(VALUE);
}
}

0 comments on commit 9946e56

Please sign in to comment.