Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KAFKA-16652: add unit test for ClusterTemplate offering zero ClusterConfig #15862

Merged
merged 4 commits into from
Jun 1, 2024

Conversation

TaiJuWu
Copy link
Contributor

@TaiJuWu TaiJuWu commented May 5, 2024

*More detailed description of your change,
refactor processClusterTemplate and add unit test for empty config

*Summary of testing strategy (including rationale)

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

@TaiJuWu TaiJuWu requested review from soarez and chia7712 May 10, 2024 01:12
Copy link
Contributor

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

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

@TaiJuWu thanks for updated PR.

@TaiJuWu
Copy link
Contributor Author

TaiJuWu commented May 22, 2024

@soarez @chia7712 Please review, thanks a lot.

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class ClusterTestExtensionsUnitTest {

static class StubTest {
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems this nested class is unnecessary. For example:

    static List<ClusterConfig> cfgEmpty() {
        return new ArrayList<ClusterConfig>();
    }

    @SuppressWarnings({"unchecked", "rawtypes"})
    private ExtensionContext buildExtensionContext(String methodName) throws Exception {
        ExtensionContext extensionContext = mock(ExtensionContext.class);
        Class clazz = ClusterTestExtensionsUnitTest.class;
        Method method = clazz.getDeclaredMethod(methodName);
        when(extensionContext.getRequiredTestClass()).thenReturn(clazz);
        when(extensionContext.getRequiredTestMethod()).thenReturn(method);
        return extensionContext;
    }

BTW, methodName is always "cfgEmpty", so maybe we can remove it from input argument.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In my mind, keeping the argument will make this function reusable if needed.

@soarez
Copy link
Member

soarez commented May 27, 2024

@TaiJuWu sorry it has taken me a while to get back to this.

I agree with the simplification @chia7712 I suggesting.

@TaiJuWu TaiJuWu requested a review from chia7712 May 28, 2024 08:01
@chia7712
Copy link
Contributor

@TaiJuWu Could you please rebase code?

Copy link
Contributor

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

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

@TaiJuWu nice patch! please take a look at one last comment :)

@TaiJuWu TaiJuWu requested a review from chia7712 May 31, 2024 09:39
when(annot.value()).thenReturn("").thenReturn(" ");
when(annot.value()).thenReturn("").thenReturn(" ").thenReturn("cfgEmpty");

Assertions.assertEquals(
Copy link
Contributor

Choose a reason for hiding this comment

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

This test is equal to next one, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but the first one is for @clusterTemplate(""), the other is @ClusterTemplate(" ").

@chia7712 chia7712 merged commit db2a09f into apache:trunk Jun 1, 2024
1 check failed
wernerdv pushed a commit to wernerdv/kafka that referenced this pull request Jun 3, 2024
…nfig (apache#15862)

Reviewers: Chia-Ping Tsai <chia7712@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants