Skip to content

Add WmiUtil unit test - #3271

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:test/wmi-util-coverage
May 19, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:test/wmi-util-coverage

Conversation

@dbwiddis

@dbwiddis dbwiddis commented May 19, 2026 •

Copy link
Copy Markdown
Member

Adds a WmiUtilTest in oshi-common that exercises the common WMI infrastructure on all platforms using a mock WmiResult implementation.

Covers:

  • WmiUtil — getString, getUint32, getUint64, getUint32asLong, getFloat, queryToString, type mismatch exceptions
  • WmiQuery — constructor null validation
  • WmiConstants — CIM/VT type constants used in assertions
  • WmiResult — interface contract via mock

This improves coverage for the common code introduced in the WMI refactoring PRs.

Summary by CodeRabbit

  • Tests
    • Added comprehensive unit tests for Windows WMI utilities covering query construction, string/number/float conversions, null and wrong-type handling, unsigned interpretations, and constructor null-check validation.
  • Chores
    • Updated test JVM module openness directive to allow access to the Windows WMI test package during testing.

Review Change Stack

@coderabbitai

coderabbitai Bot commented May 19, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: dd3c31cd-73af-471d-bd06-72d6ee089299

📥 Commits

Reviewing files that changed from the base of the PR and between a9da34c and 6909d68.

📒 Files selected for processing (2)
  • oshi-common/src/test/java/module-info.test
  • oshi-common/src/test/java/oshi/driver/common/windows/wmi/WmiUtilTest.java
🚧 Files skipped from review as they are similar to previous changes (1)
  • oshi-common/src/test/java/oshi/driver/common/windows/wmi/WmiUtilTest.java
📜 Recent review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
  • GitHub Check: Test JDK 21, windows-latest
  • GitHub Check: Test JDK 11, macos-latest
  • GitHub Check: Test JDK 21, macos-latest
  • GitHub Check: Test JDK 11, windows-latest
  • GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
  • GitHub Check: JMH Benchmarks, macos-latest
  • GitHub Check: JMH Benchmarks, ubuntu-latest
  • GitHub Check: JMH Benchmarks, windows-latest
  • GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
  • GitHub Check: Analyze (java)
🔇 Additional comments (1)
oshi-common/src/test/java/module-info.test (1)

43-44: LGTM!


📝 Walkthrough

Walkthrough

Adds a new JUnit test class WmiUtilTest with a MockWmiResult test double and tests for WmiUtil query formatting, string/number conversion helpers, and WmiQuery constructor null validation; also updates test JVM --add-opens for the windows.wmi test package.

Changes

WMI Utility Test Coverage

Layer / File(s) Summary
Test class infrastructure and mock WmiResult
oshi-common/src/test/java/oshi/driver/common/windows/wmi/WmiUtilTest.java
Establishes the test class, TestProp enum, and MockWmiResult<T> test double implementing WmiResult<T> to provide CIM/VT metadata and values.
WmiQuery constructor validation
oshi-common/src/test/java/oshi/driver/common/windows/wmi/WmiUtilTest.java
Validates WmiQuery constructor throws NullPointerException for null namespace, class, or property arguments.
WmiUtil conversion function tests
oshi-common/src/test/java/oshi/driver/common/windows/wmi/WmiUtilTest.java
Tests queryToString formatting (with/without namespace), getString (valid, null, type-mismatch), getUint32/getUint64/getUint32asLong numeric conversions, and getFloat.
Test JVM --add-opens update
oshi-common/src/test/java/module-info.test
Adds --add-opens for com.github.oshi.common/oshi.driver.common.windows.wmi to the test JVM arguments.

🎯 2 (Simple) | ⏱️ ~10 minutes

🐰 A neat test hops into the tree,
Mock results show what values be,
Queries, strings, numbers too,
Constructor checks—true through and through,
🥕 Windows WMI now tested, whee!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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.
Title check ✅ Passed The title 'Add WmiUtil unit test' directly and clearly summarizes the main change: adding a new unit test class for WmiUtil with comprehensive test coverage.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 and usage tips.

@dbwiddis dbwiddis changed the title Add cross-platform WmiUtil unit test Add WmiUtil unit test May 19, 2026
Tests WmiUtil type extraction methods, WmiQuery constructor validation,
and WmiConstants usage with a mock WmiResult implementation. Runs on all
platforms to improve coverage of the common WMI infrastructure.
@dbwiddis
dbwiddis force-pushed the test/wmi-util-coverage branch from a9da34c to 6909d68 Compare May 19, 2026 01:41
@codecov

codecov Bot commented May 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.31%. Comparing base (528dc34) to head (6909d68).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3271      +/-   ##
============================================
- Coverage     74.42%   74.31%   -0.11%     
  Complexity       73       73              
============================================
  Files           406      406              
  Lines         16047    16047              
  Branches       2554     2554              
============================================
- Hits          11943    11926      -17     
- Misses         2623     2629       +6     
- Partials       1481     1492      +11     
Flag Coverage Δ
linux 38.77% <ø> (+0.04%) ⬆️
macos 39.35% <ø> (+0.05%) ⬆️
windows 47.19% <ø> (-0.10%) ⬇️

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.

@dbwiddis
dbwiddis merged commit 6841a0b into oshi:master May 19, 2026
19 checks passed
@dbwiddis
dbwiddis deleted the test/wmi-util-coverage branch May 19, 2026 02:13
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