Comments (9)
The big difference between the two of course is that equalsverifier actually creates the object and fills in all the fields and such. I'm just talking about comparing existing instances. It could be done in (I think) no more than three lines of code internally but that multiplies externally to every single comparison that you need to do.
from assertj.
I'm not sure I understand what you have in mind. In your example, the first assertion fails while the second succeeds.
from assertj.
I should I have used integer's, 🤦🏻♂️. Updated the original example. I just want one call to check that both things are true instead of only checking greater than, it should check greater than, and less than.
from assertj.
I just want one call to check that both things are true instead of only checking greater than, it should check greater than, and less than.
I guess you are looking for assertThat(value).isStrictlyBetween(startExclusive, endExclusive)
?
from assertj.
I guess you are looking for assertThat(value).isStrictlyBetween(startExclusive, endExclusive)?
no, that would require 3 inputs. What I'm saying is code like this should fail. If this compiled it would pass because it's ONLY checking isGreaterThan. It should also (under the hood) check isLessThan and isNotEqualTo. I think the term is reflexity. If s1 is greater than s2, then s2 must be less than s1 and s1 must not be equal to s2.
@Test
void gt() {
Comparable<String> s1 = that -> 1;
Comparable<String> s2 = that -> 0;
assertThat(s1).isGreaterThan(s2);
}
from assertj.
For the sake of a more complete example
package com.xenoterracide.gradle.semver;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.stream.Stream;
import org.apache.maven.artifact.versioning.ComparableVersion;
import org.gradle.util.VersionNumber;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.ArgumentsProvider;
import org.junit.jupiter.params.provider.ArgumentsSource;
import org.semver4j.Semver;
// not really our test, just test our assumptions about upstream parsing
@Disabled
public class VersionSortTest {
@ParameterizedTest
@ArgumentsSource(RcVersionList.class)
void maven(String thisVersion, String thatVersion) {
assertThat(new ComparableVersion(thisVersion)).isGreaterThan(new ComparableVersion(thatVersion));
}
@Disabled
@ParameterizedTest
@ArgumentsSource(RcVersionList.class)
void gradle(String thisVersion, String thatVersion) {
assertThat(VersionNumber.parse(thisVersion)).isGreaterThan(VersionNumber.parse(thatVersion));
}
@ParameterizedTest
@ArgumentsSource(RcVersionList.class)
void semver(String thisVersion, String thatVersion) {
assertThat(new Semver(thisVersion)).isGreaterThan(new Semver(thatVersion));
}
static class RcVersionList implements ArgumentsProvider {
@Override
public Stream<? extends Arguments> provideArguments(ExtensionContext context) {
return Stream.of(
Arguments.of("0.1.1-alpha.10.17129409589+6.g3aae11c", "0.1.1-alpha.10+1.g3aae11d"),
Arguments.of("0.1.1-alpha.10.17129409589+6.g3aae11c", "0.1.1-alpha.2.1712940957+2.g3aae11c"),
Arguments.of("0.1.1-alpha.10.17129409589+6.g3aae11c", "0.1.1-alpha.6.1712940957+6.g3aae11c"),
Arguments.of("0.1.1-alpha.10.17129409589+6.g3aae11c", "0.1.1-alpha.6.17129409589"),
Arguments.of("0.1.1-alpha.0.17129409589+6.g3aae11c", "0.1.1-alpha.0.10+1.g3aae11d"),
Arguments.of("0.1.1-alpha.0.17129409589+6.g3aae11c", "0.1.1-alpha.0.17129409578+2.g3aae11c"),
Arguments.of("0.1.1-alpha.0.17129409589+6.g3aae11c", "0.1.1-alpha.0.17129409578+10.g3aae11c"),
Arguments.of("0.1.1-alpha.0.17129409589+6.g3aae11c", "0.1.1-alpha.0.17129409588"),
Arguments.of("0.1.1-rc.10.17129409589+6.g3aae11b", "0.1.1-alpha.0.10+1.g3aae11d"),
Arguments.of("0.1.1-rc.10.17129409589+6.g3aae11b", "0.1.1-alpha.0.17129409578+2.g3aae11c"),
Arguments.of("0.1.1-rc.10.17129409589+6.g3aae11b", "0.1.1-alpha.0.17129409578+10.g3aae11c"),
Arguments.of("0.1.1-rc.10.17129409589+6.g3aae11b", "0.1.1-alpha.0.17129409588"),
Arguments.of("0.1.1-rc.10.17129409589+6.g3aae11b", "0.1.1-rc.1.17129409588+6.g3aae11b"),
Arguments.of("0.1.1-rc.10.17129409589+6.g3aae11b", "0.1.1-rc.1.17129409588"),
Arguments.of("0.1.1-rc.10", "0.1.1-rc.9")
);
}
}
}
I don't want to isGreaterThan
isLessThan
and 2x isNotEqualTo
for the reflective test. To be fair I control none of these classes so I assume their comparable implementation is generally not massively broken (although it turns out VersionNumber doesn't compare correctly, arguably correctly, but that's a different bug).
from assertj.
If I understand correctly, you're looking for a way to verify the correctness of a Comparable
implementation, similar to what EqualsVerifier
does with the equals
/hashCode
.
Usually, AssertJ doesn't have such responsibilities behind a single assertion method. Plus, I'd consider that users might end up with fancy combinations due to usingComparator
.
I was curious to see what the ecosystem offers today and I found jqno/equalsverifier#129 – I guess the world is small after all 🙂
What you're asking would impact all the ComparableAssert
methods, if we did it consistently. I'm not yet convinced that we should have such an aggressive change.
@joel-costigliola thoughts?
from assertj.
Oh, another thought I had. I'm not testing my own implementation of equals like I would use equalsverifier for. What I'm really doing here It is asserting that the versions I'm generating actually have the precedence that I think they do. Turns out nothing about how these particular classes are interpreting these are how I thought they interpret these.
from assertj.
My concern if we go that way is that the assertion error could be confusing on the additional hidden assertion because you are switching actual and expected.
With parameterized tests, you can achieve your goal with minimal effort IMHO so overall I'm not convinced of the value of such an evolution.
from assertj.
Related Issues (20)
- Standardize ShouldBeEqual and remove AssertionErrorFactory
- Failed containsOnlyNulls Assertion for Null-Extracted List Elements HOT 4
- Missing consistent order of Javadoc tags
- Merge assertj-core-java17 into assertj-core HOT 3
- Generating Javadoc in a Maven project using <detectLinks> does not work HOT 5
- Navigation to `assertj-core` or `guava` types from `assertj-guava` Javadoc site has unnecessary header
- `satisfiesOnlyOnce` stack trace does not point to failed nested assertion HOT 3
- Evaluate `DateTimeFormatter` as replacement of `SimpleDateFormat` for internal usage
- Support for Duration in Assertions.byLessThan, Assertions.within HOT 2
- Add an unwrap method to the API to get actual value HOT 3
- Unable to construct iterable assertions across a specific type easily HOT 7
- Ambiguous `assertThat` for `Temporal` instance implementing `Comparable` HOT 3
- 3.26 - Ambiguous assertThat with Temporal implementation HOT 1
- Extra variant for doesNotMatch
- Add an annotation Class navigation method
- Recursive Comparison With Ignored Fields Fails On Equal Collections HOT 4
- hasFieldOrPropertyWithValue accepting arrays
- reference to assertThat is ambiguous when asserting a `java.time.Year` HOT 1
- JPMS assertions HOT 2
- Do we have any way to describe the expected value? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from assertj.