Skip to content

ut: login service ut,jsonUtil ut#317

Merged
hexqi merged 1 commit into
opentiny:developfrom
msslulu:feat/ut_dev
Jun 30, 2026
Merged

ut: login service ut,jsonUtil ut#317
hexqi merged 1 commit into
opentiny:developfrom
msslulu:feat/ut_dev

Conversation

@msslulu

@msslulu msslulu commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

login service ut,jsonUtil ut

Summary by CodeRabbit

  • Tests

    • Added comprehensive coverage for JSON handling, including encoding, decoding, pretty-printing, list conversion, and nested data cases.
    • Added login service tests covering validation, error handling, duplicate accounts, key checks, and password recovery flows.
  • Refactor

    • Adjusted an internal login helper’s visibility to support broader in-package usage without changing behavior.

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

validatorPublicKey in LoginServiceImpl is changed from private to package-private. Two new JUnit 5 test classes are added: LoginServiceImplTest (242 lines) covering createUser, forgotPassword, and SM2 cryptographic validation; and JsonUtilsTest (884 lines) covering encode, decode, getList, encodePrettily, and convertValue.

Changes

LoginServiceImpl visibility fix and tests

Layer / File(s) Summary
validatorPublicKey visibility change
base/src/main/java/com/tinyengine/it/login/service/impl/LoginServiceImpl.java
Removes private modifier from validatorPublicKey to make it package-private.
LoginServiceImpl unit tests
base/src/test/java/com/tinyengine/it/login/service/impl/LoginServiceImplTest.java
Adds Mockito-based test class with reflection-based UserMapper injection; covers createUser null/empty/duplicate inputs, forgotPassword invalid-key/mismatched-key/user-not-found/empty-key/invalid-salt paths, and SM2 key-pair generation to assert validatorPublicKey returns true.

JsonUtils test suite

Layer / File(s) Summary
JsonUtilsTest full coverage
base/src/test/java/com/tinyengine/it/common/utils/JsonUtilsTest.java
Adds 884-line test class with cases for encode (maps, lists, null, booleans, unicode, special chars), decode (success, nested, byte arrays, multiple invalid-JSON failure modes), getList (strings, arrays, null, unsupported types, nested/mixed structures, duplicates, deep nesting), encodePrettily, and convertValue with helper types MixedTypeObject, ComplexObject, and DeepNestedObject.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • chilingling

Poem

🐇 A method once hidden, now seen by its kin,
Tests sprouted like carrots both deep and within.
JSON decoded and lists double-checked,
SM2 keys encrypted, no edge case neglected.
The warren is tested — hop in and begin! 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.40% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title is related to the main change by indicating unit tests for login service and JsonUtils.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (3)
base/src/main/java/com/tinyengine/it/login/service/impl/LoginServiceImpl.java (1)

127-127: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Avoid widening production visibility just to satisfy the test.

validatorPublicKey(...) is still an internal helper of forgotPassword(...). Making it package-private couples the test suite to an implementation detail and expands the service surface in production. Prefer keeping this private and exercising it through forgotPassword(...), or extract the crypto check into a separate collaborator that can be tested directly.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@base/src/main/java/com/tinyengine/it/login/service/impl/LoginServiceImpl.java`
at line 127, The helper validatorPublicKey in LoginServiceImpl should not be
made package-private just for test access; keep it private and verify the
behavior through forgotPassword instead, or move the crypto verification into a
separate collaborator that can be tested directly. Update the implementation so
the test suite targets the public forgotPassword flow while preserving the
internal helper as an implementation detail.
base/src/test/java/com/tinyengine/it/common/utils/JsonUtilsTest.java (2)

26-90: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Collapse the repeated string-encoding cases into one table-driven test.

These methods all exercise the same path with different literals, so they add a lot of noise without adding distinct coverage. A single loop/helper-based test would keep the suite much easier to maintain and debug.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@base/src/test/java/com/tinyengine/it/common/utils/JsonUtilsTest.java` around
lines 26 - 90, The JsonUtilsTest class has several nearly identical
string-encoding tests that only differ by the literal value, so replace them
with a single table-driven test or parameterized-style loop covering all cases.
Keep the same assertions around JsonUtils.encode and use the shared helper/test
method to verify each input value, so the repeated test methods are removed
while preserving coverage.

250-266: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Don’t lock the pretty-print test to one formatter layout.

Checking for line breaks is enough to prove prettification here. Matching exact spacing around : makes the test brittle to serializer formatting changes that do not change behavior. Prefer parsing the output back and asserting structural equality.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@base/src/test/java/com/tinyengine/it/common/utils/JsonUtilsTest.java` around
lines 250 - 266, The JsonUtilsTest.testEncodePrettily_ComplexObject assertion is
too tightly coupled to a specific pretty-print spacing layout. Update this test
to focus on behavior by keeping the line-break check and replacing the exact
string matches for key/value spacing with parsing the output back through the
JSON utility or an equivalent JSON parser and asserting the resulting structure
matches the original data. Keep the test anchored around
JsonUtils.encodePrettily so it remains resilient to formatter changes.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@base/src/test/java/com/tinyengine/it/common/utils/JsonUtilsTest.java`:
- Around line 120-127: The invalid JSON tests in JsonUtilsTest are asserting
parser-specific exception message text, which is brittle across parser versions.
Update testDecode_InvalidJson and the other affected invalid-JSON cases to
assert only the thrown exception type or JsonUtils-specific wrapping behavior
from JsonUtils.decode, and remove any checks against message contents like
parser token text. Use the existing JsonUtils.decode calls and
assertThrows-based tests to keep the contract stable.

In
`@base/src/test/java/com/tinyengine/it/login/service/impl/LoginServiceImplTest.java`:
- Around line 172-180: The exception tests in LoginServiceImplTest are currently
hitting an unstubbed query path, so createUser() fails on users.isEmpty() before
the empty-username/null-salt branch is exercised. In the test methods around
testCreateUser_EmptyUsername and the matching null-salt case, stub
queryUserByCondition(...) to return Collections.emptyList() so
loginService.createUser(user) reaches the intended validation branch, or add
explicit input validation in LoginServiceImpl.createUser and assert that
behavior instead. Use the createUser() and queryUserByCondition(...) symbols to
update the tests so they verify the named input case rather than Mockito’s
default null.

---

Nitpick comments:
In
`@base/src/main/java/com/tinyengine/it/login/service/impl/LoginServiceImpl.java`:
- Line 127: The helper validatorPublicKey in LoginServiceImpl should not be made
package-private just for test access; keep it private and verify the behavior
through forgotPassword instead, or move the crypto verification into a separate
collaborator that can be tested directly. Update the implementation so the test
suite targets the public forgotPassword flow while preserving the internal
helper as an implementation detail.

In `@base/src/test/java/com/tinyengine/it/common/utils/JsonUtilsTest.java`:
- Around line 26-90: The JsonUtilsTest class has several nearly identical
string-encoding tests that only differ by the literal value, so replace them
with a single table-driven test or parameterized-style loop covering all cases.
Keep the same assertions around JsonUtils.encode and use the shared helper/test
method to verify each input value, so the repeated test methods are removed
while preserving coverage.
- Around line 250-266: The JsonUtilsTest.testEncodePrettily_ComplexObject
assertion is too tightly coupled to a specific pretty-print spacing layout.
Update this test to focus on behavior by keeping the line-break check and
replacing the exact string matches for key/value spacing with parsing the output
back through the JSON utility or an equivalent JSON parser and asserting the
resulting structure matches the original data. Keep the test anchored around
JsonUtils.encodePrettily so it remains resilient to formatter changes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f0dec557-dc12-4fae-a66f-5c4996896abd

📥 Commits

Reviewing files that changed from the base of the PR and between e24a8eb and c46b7a9.

📒 Files selected for processing (3)
  • base/src/main/java/com/tinyengine/it/login/service/impl/LoginServiceImpl.java
  • base/src/test/java/com/tinyengine/it/common/utils/JsonUtilsTest.java
  • base/src/test/java/com/tinyengine/it/login/service/impl/LoginServiceImplTest.java

@hexqi hexqi changed the title feat:login service ut,jsonUtil ut ut: login service ut,jsonUtil ut Jun 30, 2026
@hexqi hexqi merged commit a770605 into opentiny:develop Jun 30, 2026
1 check passed
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.

2 participants