Skip to content

GH-3652: Use assertThat checks in parquet-common tests#3654

Open
nastra wants to merge 1 commit into
apache:masterfrom
nastra:assertj-parquet-common
Open

GH-3652: Use assertThat checks in parquet-common tests#3654
nastra wants to merge 1 commit into
apache:masterfrom
nastra:assertj-parquet-common

Conversation

@nastra

@nastra nastra commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Rationale for this change

Switching assertions from JUnit4-style Assert to AssertJ makes code easier to read and debug when tests fail.

What changes are included in this PR?

This updates parquet-common tests to use AssertJ checks, which provide more fluent assertions and more detailed information when assertions fails on CI.

The changes in this PR were done with the help of Claude but I manually reviewed every single LOC

Are these changes tested?

yes, existing tests

Are there any user-facing changes?

no

@nastra nastra force-pushed the assertj-parquet-common branch from 3263eec to 03372b2 Compare July 9, 2026 06:21
@nastra nastra changed the title Assertj parquet common GH-3652: Use assertThat checks in parquet-common tests Jul 9, 2026
* @param expected An Exception class that the Runnable should throw
* @param callable A Callable that is expected to throw the exception
*/
public static void assertThrows(String message, Class<? extends Exception> expected, Callable callable) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've replaced all usages of these methods because using assertThatThrownBy() directly gives you greater flexibility in testing

assertThat(new SemanticVersion(1, 8, 0)).isLessThan(new SemanticVersion(1, 8, 1));
assertThat(new SemanticVersion(1, 8, 2)).isGreaterThan(new SemanticVersion(1, 8, 1));

assertTrue(new SemanticVersion(1, 8, 1).compareTo(new SemanticVersion(1, 8, 1)) == 0);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

these 3 checks were checking the same thing and were duplicates


assertThrows(
"Should throw EOFException at end of stream", EOFException.class, (Callable<Integer>) stream::read);
assertThatThrownBy(stream::read).isInstanceOf(EOFException.class);

@nastra nastra Jul 9, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

the exception message is null so we're omitting the hasMessage() check here and in a few other places. Depending on the JDK version, it's also possible that the exception either has a null message or has some message, so it's safer to omit the check

assertThat(stream.read()).isEqualTo(i);
}

assertThrows(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we're replacing all usages of assertThrows because using assertThatThrownBy gives you greater flexibility for localized testing, in case a test case would want to add some additional checks on top of what already is being checked

int i = 0;

ByteBuffer one = buffers.get(0);
Assert.assertSame("Should use the same backing array", one.array(), data.array());

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this is an example where the actual/expected parameters are flipped in the JUnit4 Assert. We're expecting one to be the actual object and compare it against data

@nastra nastra force-pushed the assertj-parquet-common branch from 03372b2 to 6799b64 Compare July 9, 2026 07:05

// one is a view of the first buffer because it is smaller
ByteBuffer one = buffers.get(0);
Assert.assertSame(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

actual/expected were flipped here as well

assertThat(Strings.expandGlob("{}a")).containsExactly("a");
assertThat(Strings.expandGlob("a{}")).containsExactly("a");
assertThat(Strings.expandGlob("{,}")).containsExactly("", "");
assertThat(Strings.expandGlob("a{b,{},c}")).containsExactly("ab", "a", "ac");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we don't need to compare against actual lists. It's easier to just verify that the actual contains those elements in that specified order

assertMatches(wp, "foo", "foo.x", "foo.x.y");
assertDoesNotMatch(wp, "xfoo", "xfoox", "fooa.x.y");

assertThat(wp.matches("foo")).isTrue();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

it is easier to debug a single line if the test ever fails

@nastra nastra force-pushed the assertj-parquet-common branch from 6799b64 to 8741775 Compare July 9, 2026 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant