Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ protected AbstractReactiveFeignConfigurator(int order) {

@Override
public int compareTo(ReactiveFeignConfigurator configurator){
if (this == configurator) {
return 0;
}
int compare = Integer.compare(order, ((AbstractReactiveFeignConfigurator) configurator).order);
if(compare == 0){
throw new IllegalArgumentException(String.format("Same order for different configurators: [%s], [%s]",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package reactivefeign.spring.config;

import org.junit.Test;
import reactivefeign.ReactiveFeignBuilder;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

public class AbstractReactiveFeignConfiguratorTest {

@Test
public void shouldCompareSameInstance() {
TestConfigurator configurator = new TestConfigurator(1);
assertThat(configurator.compareTo(configurator)).isEqualTo(0);
}

@Test
public void shouldCompareDifferentOrder() {
TestConfigurator configurator1 = new TestConfigurator(1);
TestConfigurator configurator2 = new TestConfigurator(2);

assertThat(configurator1.compareTo(configurator2)).isLessThan(0);
assertThat(configurator2.compareTo(configurator1)).isGreaterThan(0);
}

@Test
public void shouldThrowExceptionWhenSameOrder() {
TestConfigurator configurator1 = new TestConfigurator(1);
TestConfigurator configurator2 = new TestConfigurator(1);

assertThatThrownBy(() -> configurator1.compareTo(configurator2))
.isInstanceOf(IllegalArgumentException.class)
.hasMessageContaining("Same order for different configurators");
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The tests cover reflexivity and anti-symmetry from the Comparable contract, which is great. To make the test suite more comprehensive, I suggest also adding a test for transitivity ((x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0). This will ensure all key properties of the contract are verified.

    @Test
    public void shouldBeTransitive() {
        TestConfigurator configurator1 = new TestConfigurator(1);
        TestConfigurator configurator2 = new TestConfigurator(2);
        TestConfigurator configurator3 = new TestConfigurator(3);

        // Verifies that if c1 < c2 and c2 < c3, then c1 < c3
        assertThat(configurator1.compareTo(configurator2)).isLessThan(0);
        assertThat(configurator2.compareTo(configurator3)).isLessThan(0);
        assertThat(configurator1.compareTo(configurator3)).isLessThan(0);
    }

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jules The tests cover reflexivity and anti-symmetry from the Comparable contract, which is great. To make the test suite more comprehensive, I suggest also adding a test for transitivity ((x.compareTo(y) > 0 && y.compareTo(z) > 0) implies x.compareTo(z) > 0). This will ensure all key properties of the contract are verified.

@Test
public void shouldBeTransitive() {
    TestConfigurator configurator1 = new TestConfigurator(1);
    TestConfigurator configurator2 = new TestConfigurator(2);
    TestConfigurator configurator3 = new TestConfigurator(3);

    // Verifies that if c1 < c2 and c2 < c3, then c1 < c3
    assertThat(configurator1.compareTo(configurator2)).isLessThan(0);
    assertThat(configurator2.compareTo(configurator3)).isLessThan(0);
    assertThat(configurator1.compareTo(configurator3)).isLessThan(0);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the suggestion! I've added the shouldBeTransitive test case to ensure the transitivity property of the Comparable contract is also verified.

private static class TestConfigurator extends AbstractReactiveFeignConfigurator {
protected TestConfigurator(int order) {
super(order);
}

@Override
public ReactiveFeignBuilder configure(ReactiveFeignBuilder builder, ReactiveFeignNamedContext namedContext) {
return builder;
}
}
}
Loading