Skip to content

add unit tests - #27

Open
devops-thiago wants to merge 1 commit into
masterfrom
add_unit_tests
Open

add unit tests#27
devops-thiago wants to merge 1 commit into
masterfrom
add_unit_tests

Conversation

@devops-thiago

Copy link
Copy Markdown
Owner

No description provided.

@devops-thiago
devops-thiago requested review from Copilot and removed request for Copilot September 1, 2025 20:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds comprehensive unit tests to the mongocom library, replacing the outdated JUnit 4 configuration with modern JUnit 5 and Mockito for better testing capabilities.

  • Adds comprehensive unit test coverage for core library components
  • Migrates from JUnit 4 to JUnit 5 with Mockito integration
  • Fixes documentation formatting issues in JavaDoc comments

Reviewed Changes

Copilot reviewed 20 out of 26 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
Multiple test files New unit tests covering utilities, types, management classes, exceptions, and annotations
pom.xml Updated to JUnit 5 and added Mockito dependencies with Surefire plugin configuration
Type classes Fixed HTML encoding in JavaDoc author tags
CollectionManager.java Minor code improvements and documentation fixes
MongoQuery.java Return defensive copies and improved documentation
CollectionManagerFactory.java Enhanced exception handling for illegal arguments

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines 118 to 140

public Document getQuery() {
return query;
return query != null ? new Document(query) : null;
}

public Document getConstraints() {
return constraints;
return constraints != null ? new Document(constraints) : null;
}

public Document getOrderBy() {

Copilot AI Sep 1, 2025

Copy link

Choose a reason for hiding this comment

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

[nitpick] The defensive copying approach is inconsistent with the original implementation and may break existing code that expects direct references. Consider documenting this breaking change or providing configuration options to maintain backward compatibility.

Copilot uses AI. Check for mistakes.
@codecov

codecov Bot commented Sep 1, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.77215% with 13 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.46%. Comparing base (26d868b) to head (7570a48).

Files with missing lines Patch % Lines
...volivre/mongocom/management/CollectionManager.java 91.50% 7 Missing and 2 partials ⚠️
.../mongocom/management/CollectionManagerFactory.java 93.61% 0 Missing and 3 partials ⚠️
...m/arquivolivre/mongocom/management/MongoQuery.java 66.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             master      #27       +/-   ##
=============================================
+ Coverage      0.00%   90.46%   +90.46%     
- Complexity        0      182      +182     
=============================================
  Files            10       10               
  Lines           537      556       +19     
  Branches         97      100        +3     
=============================================
+ Hits              0      503      +503     
+ Misses          537       38      -499     
- Partials          0       15       +15     
Flag Coverage Δ
unittests 90.46% <91.77%> (+90.46%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@devops-thiago
devops-thiago force-pushed the add_unit_tests branch 5 times, most recently from 57bff32 to 021c1bd Compare September 2, 2025 21:05
@sonarqubecloud

sonarqubecloud Bot commented Sep 2, 2025

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@devops-thiago

Copy link
Copy Markdown
Owner Author

/summary

@thrillhousebot

thrillhousebot Bot commented Jul 1, 2026

Copy link
Copy Markdown

⚠️ Large PR — partial review. 7 file(s) were omitted because the diff exceeded the size budget; the findings and verdict below cover only the reviewed portion.

🤖 ThrillhouseBot PR Summary

What this PR does

Primarily adds a large suite of unit tests covering annotations, exceptions, CollectionManager, and utilities using JUnit 5 and Mockito. Beyond tests, the code refactors CollectionManager to use getDeclaredConstructor().newInstance() instead of deprecated Class.newInstance(), renames the public method createCollectionManagerFromURI to createCollectionManagerFromUri, adds thread-safety when creating MongoClient instances, and implements defensive copies in MongoQuery getters.

⚠️ Description vs. Implementation

The PR description does not fully match the change:

  • The PR description only says 'add unit tests' but the diff also contains: a breaking rename of the public method createCollectionManagerFromURI to createCollectionManagerFromUri; addition of synchronized client creation and client closing logic in CollectionManagerFactory; replacement of Class.newInstance() calls with getDeclaredConstructor().newInstance(); defensive copy creation in MongoQuery getters.
  • No mention of the thread-safety changes or the client lifecycle management (closing previous clients on new factory calls).
  • No acknowledgment that the API rename is a breaking change that may require downstream code updates.

Control-Flow Diagram

🔀 Show diagram
flowchart TD
  A["Call createCollectionManager()"] --> B["createBaseCollectionManager"]
  B --> C["getConn(uri)"]
  C --> D["Create new ConnectionString & MongoClient"]
  D --> E{"Existing client?"}
  E -->|yes| F["Close old client"]
  E -->|no| G["Assign new client"]
  F --> G
  G --> H["Return ConnectionString"]
  B --> I["Return new CollectionManager with client and dbName"]
  A --> J["setup(ServletContext) also calls getConn"]
Loading

Changes Overview

  • Files changed: 42
  • Lines added: +5653
  • Lines removed: -361

Changed Files

File Change Summary
.copilot-instructions.md Modified -
.github/workflows/ci.yml Modified -
.github/workflows/pr-validation.yml Modified -
README.md Modified -
examples/src/com/example/collections/Address.java Modified -
examples/src/com/example/collections/Contact.java Modified -
examples/src/com/example/collections/Phone.java Modified -
examples/src/com/example/collections/types/ContactType.java Modified -
examples/src/com/example/collections/types/PhoneType.java Modified -
examples/src/com/example/main/Main.java Modified -
src/main/java/com/arquivolivre/mongocom/annotations/Document.java Modified -
src/main/java/com/arquivolivre/mongocom/annotations/GeneratedValue.java Modified -
src/main/java/com/arquivolivre/mongocom/annotations/Id.java Modified -
src/main/java/com/arquivolivre/mongocom/annotations/Index.java Modified -
src/main/java/com/arquivolivre/mongocom/annotations/Internal.java Modified -
src/main/java/com/arquivolivre/mongocom/annotations/ObjectId.java Modified -
src/main/java/com/arquivolivre/mongocom/annotations/Reference.java Modified -
src/main/java/com/arquivolivre/mongocom/annotations/Trigger.java Modified -
src/main/java/com/arquivolivre/mongocom/exceptions/NoSuchMongoCollectionException.java Modified -
src/main/java/com/arquivolivre/mongocom/management/CollectionManager.java Modified Major changes: replace deprecated reflection APIs, add ClassCastException handling for _id, wrap setAccessible with AccessController, import reorganization, and Javadoc additions.

…and 22 more file(s).

Risk Assessment

Risk Count
🔴 Critical 0
🟠 High 1
🟡 Medium 1
🔵 Low 1

Key Findings

  • HIGH: Breaking API rename from createCollectionManagerFromURI to createCollectionManagerFromUri (src/main/java/com/arquivolivre/mongocom/management/CollectionManagerFactory.java:106)
  • MEDIUM: Client closure in setup/getConn may break existing CollectionManager instances (src/main/java/com/arquivolivre/mongocom/management/CollectionManagerFactory.java:225)
  • LOW: Description gap: PR only mentions adding tests but includes functional changes (src/main/java/com/arquivolivre/mongocom/management/CollectionManagerFactory.java:176)

⚠️ Required CI Checks Status

Some required checks are still pending or have failed:

Check Type Status Detail
SonarCloud Code Analysis check-run ❌ Failed failure

Automated review by ThrillhouseBot. Reply with /review to re-run.

@@ -73,21 +106,14 @@ public static CollectionManager createCollectionManager(
* @param uri MongoDB connection URI (e.g., "mongodb://user:password@host:port/database")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 HIGH — Breaking API rename from createCollectionManagerFromURI to createCollectionManagerFromUri

The method name changed from createCollectionManagerFromURI to createCollectionManagerFromUri, altering the public API. This will cause compilation failures in any code that calls the old name. The PR description only mentions adding unit tests and does not warn of this breaking change. Change: line 106 shows the new signature public static CollectionManager createCollectionManagerFromUri(String uri).

Suggested change
* @param uri MongoDB connection URI (e.g., "mongodb://user:password@host:port/database")
// If renaming is desired, document it as a breaking change; otherwise revert the name.
public static CollectionManager createCollectionManagerFromURI(String uri) {

if (host.isEmpty()) {
builder.append("localhost");
} else {
builder.append(host);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 MEDIUM — Client closure in setup/getConn may break existing CollectionManager instances (medium confidence — verify before acting)

The new getConn method (line 264) and the fallback path in setup (line 225) now close the currently stored client and replace it with a new one. If multiple CollectionManager instances are created via the factory (e.g., in a server application with many managers), the old client becomes unusable, causing operations on previously created managers to fail. The old code did not close previous clients, allowing them to coexist. This regressive behaviour is not mentioned in the PR description or tested in the unit tests.

@@ -164,67 +187,83 @@ public static CollectionManager setup(ServletContext context) {
if (props == null) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 LOW — Description gap: PR only mentions adding tests but includes functional changes (low confidence — verify before acting)

The PR description states 'add unit tests', but the diff includes many non-test changes: API rename, thread-safe client creation, client lifecycle changes, defensive copies in MongoQuery, and replacement of deprecated Class.newInstance(). The description does not mention any of these functional modifications.

@thrillhousebot thrillhousebot 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.

ThrillhouseBot requested changes — see inline comments on the diff.

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