Skip to content

Add test to validate <choose> tag's <otherwise> fallback when parameter is null #3500

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ku1551
Copy link

@ku1551 ku1551 commented Jul 10, 2025

Summary

This PR adds a unit test to ensure that <choose> with <when> conditions correctly falls back to <otherwise> when a parameter is missing or null.

Motivation

While MyBatis already appears to handle OGNL evaluation with missing parameters gracefully, there wasn't an explicit test to guarantee this behavior.

By adding this test, we can be more confident that:

  • When name is not provided, the when condition fails safely.
  • The otherwise clause executes as expected, producing AND status = 'ACTIVE'.

Details

  • Added ChooseWhenTest under submitted.choosewhen to verify this edge case.
  • Uses H2 in-memory database and CreateDB.sql for test setup.

Notes

I wanted to provide a clear test case that proves <choose> properly falls back to <otherwise>.
This improves test coverage and helps ensure future refactoring doesn't accidentally break this logic.


Let me know if you'd like any adjustments!

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