Skip to content

Add unit and integration tests for untested web layer classes#31

Open
devin-ai-integration[bot] wants to merge 1 commit into
masterfrom
devin/1774621507-add-web-module-tests
Open

Add unit and integration tests for untested web layer classes#31
devin-ai-integration[bot] wants to merge 1 commit into
masterfrom
devin/1774621507-add-web-module-tests

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Mar 27, 2026

Copy link
Copy Markdown

Description of what I changed

Added 8 new test files covering previously untested web layer classes, totaling 98 new tests:

Test File Tests Type Covers
OpenmrsFilterTest 11 Unit Filter chain delegation, UserContext lifecycle, CSRF cache headers, cleanup after exception
ListenerTest 14 Unit Static state flags (runtimePropertiesFound, setupNeeded, openmrsStarted), error handling, contextDestroyed
DispatcherServletTest 2 Unit Constructor, stopAndCloseApplicationContext null-safety
StaticDispatcherServletTest 2 Unit Constructor, stopAndCloseApplicationContext null-safety
OpenmrsBindingInitializerTest 34 Integration Property editor registration for 30+ OpenMRS domain types via WebDataBinder
JspClassLoaderFilterTest 5 Unit Thread context classloader set to OpenmrsClassLoader, restoration behavior on exception
GZIPResponseWrapperTest 15 Unit Stream/writer creation, mutual exclusion, finishResponse, flushBuffer, setContentLength no-op
GZIPResponseStreamTest 15 Unit Write operations, GZIP compression validity, close/flush, double-close, write-after-close

Note on DispatcherServlet tests: Spring 6 marks FrameworkServlet.getWebApplicationContext() as final, preventing mock-based testing of most servlet behavior via subclass overrides. Tests are limited to constructor and stopAndCloseApplicationContext null-handling.

Things for reviewers to look at closely

  1. ListenerTest uses ReflectionTestUtils.setField to manipulate private static fields — fragile if field names are refactored. The contextDestroyed test swallows exceptions from an uninitialized Context, so it only verifies the openmrsStarted flag transition.
  2. GZIPResponseWrapperTest.sendError_shouldSetErrorCode has a weak assertion (assertNotNull(wrapper)) — it doesn't actually verify the error code was stored.
  3. OpenmrsBindingInitializerTest extends BaseWebContextSensitiveTest (requires Spring context/DB). Each of the 34 tests checks a single type registration individually rather than using parameterized tests.

Issue I worked on

N/A — test coverage improvement for the web module.

Checklist: I completed these to help reviewers :)

  • My IDE is configured to follow the code style of this project.
  • I have added tests to cover my changes. (If you refactored existing code that was well tested you do not have to add tests)
  • I ran mvn clean package right before creating this pull request and added all formatting changes to my commit.
  • All new and existing tests passed.
  • My pull request is based on the latest changes of the master branch.

Link to Devin session: https://app.devin.ai/sessions/2d842dff86fe4872ac461c051bb01f16
Requested by: @dillonvargo


Open with Devin

New test files:
- OpenmrsFilterTest: 11 tests for servlet filter behavior, UserContext lifecycle, cache headers
- ListenerTest: 14 tests for static methods, state management, error handling
- DispatcherServletTest: 2 tests for constructor and stopAndCloseApplicationContext
- StaticDispatcherServletTest: 2 tests for constructor and stopAndCloseApplicationContext
- OpenmrsBindingInitializerTest: 34 tests for property editor registration
- JspClassLoaderFilterTest: 5 tests for classloader management
- GZIPResponseWrapperTest: 15 tests for GZIP response wrapper
- GZIPResponseStreamTest: 15 tests for GZIP response stream

Total: 98 new tests across 8 test files
Co-Authored-By: Dillon Vargo <dillonvargo@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Devin Review found 1 potential issue.

View 4 additional findings in Devin Review.

Open in Devin Review

Comment on lines +136 to +140
void getRuntimeProperties_shouldReturnNonNullResult() {
// getRuntimeProperties delegates to OpenmrsUtil.getRuntimeProperties
// It may return null if no runtime properties file is found, but should not throw
Listener.getRuntimeProperties();
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

🟡 Test name claims non-null assertion but has no assertion at all

The test getRuntimeProperties_shouldReturnNonNullResult claims to verify a non-null return value, but contains no assertion whatsoever — it only calls Listener.getRuntimeProperties() without checking the result. The comment on line 138 even acknowledges "It may return null", directly contradicting the test name. This means the test will pass regardless of the return value (null or non-null), giving a false sense that the non-null contract is verified. If the intended behavior is to verify no exception is thrown, the test should be renamed (e.g., shouldNotThrow). If non-null is expected, assertNotNull should be added.

Suggested change
void getRuntimeProperties_shouldReturnNonNullResult() {
// getRuntimeProperties delegates to OpenmrsUtil.getRuntimeProperties
// It may return null if no runtime properties file is found, but should not throw
Listener.getRuntimeProperties();
}
void getRuntimeProperties_shouldNotThrowException() {
// getRuntimeProperties delegates to OpenmrsUtil.getRuntimeProperties
// It may return null if no runtime properties file is found, but should not throw
Listener.getRuntimeProperties();
}
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

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