Skip to content

Unify settings files by prioritizing mockk.properties in MockKSettings#1474

Merged
Raibaz merged 8 commits intomockk:masterfrom
snowykte0426:master
Jan 8, 2026
Merged

Unify settings files by prioritizing mockk.properties in MockKSettings#1474
Raibaz merged 8 commits intomockk:masterfrom
snowykte0426:master

Conversation

@snowykte0426
Copy link
Contributor

Summary

This PR addresses #1468 by unifying MockK's configuration files into a single location, which should help streamline the configuration experience for users.

Problem

Currently, MockK uses two separate configuration files:

  • io/mockk/settings.properties for MockKSettings (relaxed mode, stack traces, etc.)
  • mockk.properties for RestrictMockkConfiguration (restricted mocking settings)

This dual-file approach has caused some confusion about where to configure different settings.

Solution

I've modified MockKSettings.kt to prioritize loading from mockk.properties at the classpath root, with a fallback to the legacy io/mockk/settings.properties
location for backward compatibility.

Changes

  • Updated MockKSettings initialization to:
    a. First attempt to load from mockk.properties (unified location)
    b. Fall back to io/mockk/settings.properties if not found (legacy support)
  • No changes needed for RestrictMockkConfiguration (already uses mockk.properties)

Benefits

  • Simplified configuration: One file for all MockK settings
  • Reduced confusion: Clear, unified configuration location
  • Full backward compatibility: No breaking changes for existing users
  • Future-ready: Lays the groundwork for a potential deprecation path

Testing

The change maintains compatibility with existing test suites:

  • All settings properties remain accessible with the same keys
  • No property name conflicts (RestrictMockk settings use mockk. prefix)
  • Existing tests continue to pass without modification

Future Considerations (Optional)

If the maintainers think it would be valuable, I'd be happy to follow up with:

  • Documentation updates to guide users toward the unified mockk.properties approach
  • Deprecation warnings when loading from the legacy location
  • Any other improvements you'd suggest

Please let me know if you'd like me to tackle any of these in this PR or in a follow-up!

Fixes #1468

@github-actions
Copy link

There is a problem with the Gemini CLI PR review. Please check the action logs for details.

Comment on lines 9 to 19
val unifiedPropertiesStream = Thread.currentThread().contextClassLoader
.getResourceAsStream("mockk.properties")

if (unifiedPropertiesStream != null) {
unifiedPropertiesStream.use(properties::load)
} else {
// Fallback to the legacy settings.properties for backward compatibility
MockKSettings::class.java
.getResourceAsStream("settings.properties")
?.use(properties::load)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

How about compacting this logic by using the same class as entry point to the class path? We can leverage the resource path resolution, that is

  • "/file" is read from the class path root
  • "file" is read relative to this class (like the initial code)

Then with a scope function we can shorten it:

Suggested change
val unifiedPropertiesStream = Thread.currentThread().contextClassLoader
.getResourceAsStream("mockk.properties")
if (unifiedPropertiesStream != null) {
unifiedPropertiesStream.use(properties::load)
} else {
// Fallback to the legacy settings.properties for backward compatibility
MockKSettings::class.java
.getResourceAsStream("settings.properties")
?.use(properties::load)
}
MockKSettings::class.java.run {
getResourceAsStream("/mockk.properties")
// Fallback to the legacy file for backward compatibility
?: getResourceAsStream("settings.properties")
}?.use(properties::load)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the suggestion!

I considered this approach, but opted to fully encapsulate the loading logic in UnifiedPropertiesLoader instead of keeping it inline. This addresses your
broader concern about duplication with RestrictMockkConfiguration and DefaultPropertiesLoader.

Now MockKSettings simply delegates to UnifiedPropertiesLoader().loadProperties(), which centralizes the fallback mechanism and the path constants in one
place. This makes it easier to maintain and test.

Let me know if you prefer the inline approach—I can adjust if needed.

d8bc492

@polarene
Copy link
Contributor

There is still one duplication remaining: RestrictMockkConfiguration uses DefaultPropertiesLoader, which is yet another mechanism for reading properties and duplicates the "mockk.properties" path. Maybe we should refactor MockKSettings or this one to unify the loading logic. I'm not familiar with multiplatform projects, and I can't understand if 'mockk-dsl' module depends on 'mockk', but we should try to remove duplication.

@snowykte0426
Copy link
Contributor Author

snowykte0426 commented Dec 12, 2025

There is still one duplication remaining: RestrictMockkConfiguration uses DefaultPropertiesLoader, which is yet another mechanism for reading properties and duplicates the "mockk.properties" path. Maybe we should refactor MockKSettings or this one to unify the loading logic. I'm not familiar with multiplatform projects, and I can't understand if 'mockk-dsl' module depends on 'mockk', but we should try to remove duplication.

@polarene Thanks for pointing out the duplication in DefaultPropertiesLoader

I started refactoring before seeing your comment, so I initially missed that path duplication. I've now updated the implementation to address the issues you
raised.

What's updated

  1. Introduced a unified loader
    • Added UnifiedPropertiesLoader in mockk-core
    • All property resolution goes through this implementation
    "mockk.properties" is now defined in a single place

  2. Removed duplication across modules
    MockKSettings now uses the unified loader
    DefaultPropertiesLoader delegates to it (marked as @Deprecated)
    RestrictMockkConfiguration picks it up automatically via the updated loader

  3. Module dependency rationale
    mockk-dsl does not depend on mockk
    • Dependency chain: mockk-coremockk-dslmockk
    • Placing the loader in mockk-core ensures both sides can use it without breaking boundaries

  4. Compatibility
    • Deprecated paths still work as fallbacks
    • No breaking changes for existing configurations

All tests pass and the behavior matches previous versions.
Let me know if you'd like this organized differently.

@polarene
Copy link
Contributor

Thanks @snowykte0426, I'm reviewing the latest changes.

README.md Outdated
## Configuration File

To adjust parameters globally, there are a few settings you can specify in a resource file.
To adjust parameters globally, you can specify settings in a unified configuration file.
Copy link
Contributor

Choose a reason for hiding this comment

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

Unifying the configurations is a feature we pulled off, but as a reader I don't care about it. I just want the current information to state things as if they've always been that way.

Suggested change
To adjust parameters globally, you can specify settings in a unified configuration file.
To adjust parameters globally, you can specify settings in a configuration file.

README.md Outdated

### How to use:

1. Create a `mockk.properties` file in `src/test/resources/`.
Copy link
Contributor

Choose a reason for hiding this comment

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

It's better to specify the whole path at once, so a user can create it easily by copying and pasting directly in the shell or IDE.

Suggested change
1. Create a `mockk.properties` file in `src/test/resources/`.
1. Create the configuration file at `src/test/resources/mockk.properties`.

README.md Outdated
Comment on lines 1414 to 1419
### Legacy Configuration (Backward Compatibility)

For backward compatibility, MockK also supports the legacy configuration file location:
- `src/test/resources/io/mockk/settings.properties`

If both files exist, `mockk.properties` takes precedence. The legacy location is deprecated and may be removed in a future version.
Copy link
Contributor

Choose a reason for hiding this comment

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

A few style and wording suggestions:

Suggested change
### Legacy Configuration (Backward Compatibility)
For backward compatibility, MockK also supports the legacy configuration file location:
- `src/test/resources/io/mockk/settings.properties`
If both files exist, `mockk.properties` takes precedence. The legacy location is deprecated and may be removed in a future version.
### Legacy Configuration
For backward compatibility, MockK also supports the legacy configuration file:

src/test/resources/io/mockk/settings.properties


If both files exist, `mockk.properties` takes precedence. The legacy location is deprecated and will be removed in a future version.

README.md Outdated
You can configure Restricted Mocking behavior using the `mockk.properties` file.

#### 1. Creating the `mockk.properties` File
You can configure Restricted Mocking behavior using the unified `mockk.properties` configuration file described in the [Configuration File](#configuration-file) section.
Copy link
Contributor

Choose a reason for hiding this comment

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

Same reason as above

Suggested change
You can configure Restricted Mocking behavior using the unified `mockk.properties` configuration file described in the [Configuration File](#configuration-file) section.
You can configure Restricted Mocking behavior using the `mockk.properties` configuration file described in the [Configuration File](#configuration-file) section.

README.md Outdated
You can configure Restricted Mocking behavior using the unified `mockk.properties` configuration file described in the [Configuration File](#configuration-file) section.

Place the file in one of the following directories:
Add the following properties to your `src/test/resources/mockk.properties` file:
Copy link
Contributor

Choose a reason for hiding this comment

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

Better not duplicate paths, instead a link would be best.

Suggested change
Add the following properties to your `src/test/resources/mockk.properties` file:
Add the following properties to your [configuration file](#configuration-file):

Copy link
Contributor

Choose a reason for hiding this comment

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

The code around, and this test especially, were clearly written with an LLM, but don't worry: we have code reviews exactly for improving it before merging, we can make it better. 😉
Just remember to always double-check ai-generated code.

Comment on lines 7 to 8
class UnifiedPropertiesLoaderTest {

Copy link
Contributor

Choose a reason for hiding this comment

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

The subject under test (SUT) initialization is the same for every test (in addition to being stateless), so we can extract it here. The default JUnit lifecycle will instantiate the test class for every case, so it doesn't matter state-wise anyway.

Suggested change
class UnifiedPropertiesLoaderTest {
class UnifiedPropertiesLoaderTest {
val loader = UnifiedPropertiesLoader()

Comment on lines 11 to 18
// Given: A loader with no properties files in the test resources
val loader = UnifiedPropertiesLoader()

// When: Loading properties
val properties = loader.loadProperties()

// Then: Should return empty properties without throwing an exception
assertTrue(properties.isEmpty, "Properties should be empty when no file exists")
Copy link
Contributor

Choose a reason for hiding this comment

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

This test is fine, we just don't need these comments.

Suggested change
// Given: A loader with no properties files in the test resources
val loader = UnifiedPropertiesLoader()
// When: Loading properties
val properties = loader.loadProperties()
// Then: Should return empty properties without throwing an exception
assertTrue(properties.isEmpty, "Properties should be empty when no file exists")
val properties = loader.loadProperties()
assertTrue(properties.isEmpty, "Properties should be empty when no file exists")

Comment on lines 21 to 29
@Test
fun `UNIFIED_PROPERTIES_FILE constant has correct value`() {
assertEquals("mockk.properties", UnifiedPropertiesLoader.UNIFIED_PROPERTIES_FILE)
}

@Test
fun `LEGACY_PROPERTIES_FILE constant has correct value`() {
assertEquals("settings.properties", UnifiedPropertiesLoader.LEGACY_PROPERTIES_FILE)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

These tests are completely unnecessary: they're not testing any useful behavior, and should be removed. In addition, the constants should be made private, or at least internal for test purposes.

Comment on lines 31 to 42
@Test
fun `loadProperties uses correct context class loader`() {
// Given: A loader instance
val loader = UnifiedPropertiesLoader()

// When: Loading properties
val properties = loader.loadProperties()

// Then: Should not throw an exception even if no files exist
// This verifies that the correct class loader is being used
assertTrue(properties != null, "Properties should not be null")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This case isn't testing anything of what it says because:

  1. the return type can never be null
  2. resource loading never throws an exception, apart from the path being null
  3. there still aren't any configuration files on the classpath, so the behavior is identical to the first test case

This is just plain LLM hallucination :)

To properly test the loading mechanism, we need to create the resource files needed for every case, and delete them afterward. This way we can effectively check the loading behavior with real but temporary files. We just need a few utilities to make the tests easy to read:

Suggested change
@Test
fun `loadProperties uses correct context class loader`() {
// Given: A loader instance
val loader = UnifiedPropertiesLoader()
// When: Loading properties
val properties = loader.loadProperties()
// Then: Should not throw an exception even if no files exist
// This verifies that the correct class loader is being used
assertTrue(properties != null, "Properties should not be null")
}
@Test
fun `read default config`() {
writeToClasspath(UnifiedPropertiesLoader.UNIFIED_PROPERTIES_FILE, "name=default")
val config = loader.loadProperties()
assertEquals(config["name"], "default")
deleteFromClasspath(UnifiedPropertiesLoader.UNIFIED_PROPERTIES_FILE)
}
@Test
fun `read legacy config`() {
writeToClasspath(UnifiedPropertiesLoader.LEGACY_PROPERTIES_FILE, "name=legacy")
val config = loader.loadProperties()
assertEquals(config["name"], "legacy")
deleteFromClasspath(UnifiedPropertiesLoader.LEGACY_PROPERTIES_FILE)
}
@Test
fun `default config takes precedence over legacy`() {
writeToClasspath(UnifiedPropertiesLoader.UNIFIED_PROPERTIES_FILE, "name=default")
writeToClasspath(UnifiedPropertiesLoader.LEGACY_PROPERTIES_FILE, "name=legacy")
val config = loader.loadProperties()
assertEquals(config["name"], "default")
deleteFromClasspath(UnifiedPropertiesLoader.UNIFIED_PROPERTIES_FILE)
deleteFromClasspath(UnifiedPropertiesLoader.LEGACY_PROPERTIES_FILE)
}
fun writeToClasspath(path: String, content: String) {
getRoot().resolve(path.removePrefix("/")).run {
createParentDirectories()
writeText(content)
}
}
fun deleteFromClasspath(path: String) {
getRoot().resolve(path.removePrefix("/")).deleteExisting()
}
fun getRoot(): Path = Path.of(this::class.java.getResource("/")!!.toURI())

* This loader attempts to load properties from [UNIFIED_PROPERTIES_FILE] at the classpath root first.
* If not found, it falls back to the legacy [LEGACY_PROPERTIES_FILE] location for backward compatibility.
*/
class UnifiedPropertiesLoader : PropertiesLoader {
Copy link
Contributor

Choose a reason for hiding this comment

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

Last thing: since this class is stateless, consider changing it to object.

@snowykte0426
Copy link
Contributor Author

snowykte0426 commented Dec 22, 2025

Thank you for the detailed review! I've addressed all your feedback.

Changes Made

I refactored the implementation based on your suggestions:

UnifiedPropertiesLoader.kt:

  • Fixed the path resolution issue by using absolute paths with leading /
  • Converted to object since the class is stateless
  • Simplified loadProperties() using idiomatic Kotlin (scope functions + Elvis operator)
  • Made constants internal for test access
  • Unified ClassLoader usage to prevent the broken fallback mechanism

UnifiedPropertiesLoaderTest.kt:

  • Removed the AI-generated tests (you were right—those were weak assertions)
  • Added comprehensive tests for actual file loading scenarios
  • Switched to kotlin.test.Test
  • Implemented helper methods for dynamic resource file creation/deletion

README.md:

  • Removed "unified" references (implementation detail users don't need)
  • Made paths more copy-paste friendly
  • Used link references to eliminate duplication
  • Strengthened deprecation language

Additional Refactoring

To fully eliminate the duplication you identified in RestrictMockkConfiguration, I also:

Removed deprecated files:

  • Deleted DefaultPropertiesLoader.kt (was only delegating to UnifiedPropertiesLoader)
  • Removed the PropertiesLoader type alias in io.mockk.impl.restrict.propertiesloader
  • Updated RestrictMockkConfiguration to use UnifiedPropertiesLoader directly
  • Updated API declarations accordingly

Question: I assumed these were internal-only since they were deprecated, but I realize DefaultPropertiesLoader was in the public API. Should I revert
this removal and keep the deprecated classes for a transition period, or is it acceptable to remove them now since UnifiedPropertiesLoader provides the
same functionality?

Note on the Tests

I apologize for not catching the AI-generated code in my initial implementation. I used an LLM to help with some parts and focused on the core logic, but I
should have been more thorough in reviewing the test quality before pushing.

The new tests are completely rewritten with proper file I/O testing.

Let me know if any adjustments are needed!

@snowykte0426
Copy link
Contributor Author

I've updated the test implementation to use kotlin.io.path extensions as you suggested in your code review (commit: 778f2d5). I replaced the
java.io.File API with kotlin.io.path extensions (writeText, deleteExisting) and used Files.createDirectories() for parent directory creation.
While attempting to use createParentDirectories(), I encountered an "Unresolved reference" error from the IDE and the build failed with:

> Task :modules:mockk-core:compileTestKotlinJvm FAILED
e: file:///Users/snowykte0426/Programming/mockk/modules/mockk-core/src/jvmTest/kotlin/io/mockk/core/config/UnifiedPropertiesLoaderTest.kt:49:13 Unresolved
reference: createParentDirectories

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':modules:mockk-core:compileTestKotlinJvm'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details

So I used the standard Java NIO Files.createDirectories() instead for that specific operation. All tests pass with this implementation and it now matches
the approach you recommended. However, if there's a better solution or something I might have missed, please let me know.

@Raibaz
Copy link
Collaborator

Raibaz commented Dec 26, 2025

Can you please rebase on top of the master branch? It should be just a matter of formatting after I merged #1483

Fixes #1468

Signed-off-by: Kim Tae Eun <snowykte0426@naver.com>
Addresses polarene's feedback on #1474

- Create UnifiedPropertiesLoader in mockk-core as single source of truth
- Refactor MockKSettings to use UnifiedPropertiesLoader
- Refactor DefaultPropertiesLoader to delegate to UnifiedPropertiesLoader
- Eliminate "mockk.properties" path duplication (2 occurrences → 1 constant)
- Update README.md to document unified configuration approach
- Add comprehensive tests for UnifiedPropertiesLoader
- Update API declarations for mockk-core and mockk modules

This eliminates the duplication identified in code review where both
MockKSettings and DefaultPropertiesLoader had separate implementations
for loading mockk.properties. All configuration loading now flows through
a single unified mechanism while maintaining backward compatibility.

Fixes #1468
- Fix critical path resolution bug in UnifiedPropertiesLoader
  * Use absolute paths with leading '/' for correct classpath resolution
  * Consolidate ClassLoader usage to single instance
  * Refactor loadProperties() to idiomatic Kotlin with scope functions

- Convert UnifiedPropertiesLoader to singleton object
  * Class is stateless, object pattern is more appropriate
  * Update MockKSettings to use object reference

- Rewrite UnifiedPropertiesLoaderTest with comprehensive coverage
  * Add tests for actual file loading from unified location
  * Add tests for fallback to legacy location
  * Add test for precedence (unified over legacy)
  * Remove AI-generated tests with weak assertions
  * Use kotlin.test instead of JUnit-specific imports

- Simplify README documentation
  * Remove implementation detail references ("unified")
  * Improve file path clarity for copy-paste usage
  * Use link references to avoid duplication
  * Strengthen deprecation notice for legacy location

Addresses all feedback from @polarene's review.
Fixes fallback mechanism that was broken due to relative path usage.

Signed-off-by: Kim Tae Eun <snowykte0426@naver.com>
Replace java.io.File API with kotlin.io.path extensions and Java NIO
as suggested in code review. Uses Files.createDirectories() for parent
directory creation since kotlin.io.path.createParentDirectories() is
not available in the current Kotlin stdlib version.

All tests pass with this implementation.

Signed-off-by: Kim Tae Eun <snowykte0426@naver.com>
@snowykte0426
Copy link
Contributor Author

Can you please rebase on top of the master branch? It should be just a matter of formatting after I merged #1483

@Raibaz I've rebased on top of the latest master (58750d3) after #1483 merge. Resolved the Spotless formatting conflicts and applied all formatting
rules. All commits are now cleanly rebased.

@snowykte0426
Copy link
Contributor Author

Fixed CI failures in fd9fbd5 - replaced kotlin.io.path extensions with Java NIO APIs.

The tests were using kotlin.io.path.writeText and deleteExisting, which are only available in Kotlin 1.8.0+. However, CI runs tests against Kotlin
1.7.22 (and 1.5.32), causing compilation errors.

I switched to Java NIO APIs (Files.writeString, Files.delete) for backward compatibility, but I'm wondering - should I just keep using kotlin.io.path
and let the older Kotlin version tests fail? Or is backward compatibility with Kotlin 1.7.22 important for this project?

Let me know your preference and I can adjust accordingly.

@Raibaz
Copy link
Collaborator

Raibaz commented Dec 27, 2025

We have to maintain backwards compatibility with 1.7.*, yes.

- Replace kotlin.io.path.writeText with Files.writeString
- Replace kotlin.io.path.deleteExisting with Files.delete
- kotlin.io.path extensions require Kotlin 1.8.0+
- CI tests with Kotlin 1.7.22 were failing due to missing APIs

Fixes CI failures in Check [java=21, kotlin=1.7.22] and similar jobs
@polarene
Copy link
Contributor

polarene commented Jan 5, 2026

Hi! Catching up now, thanks for the updates. Let me review the changes again.

import kotlin.test.assertTrue

class UnifiedPropertiesLoaderTest {
private val loader = UnifiedPropertiesLoader
Copy link
Contributor

Choose a reason for hiding this comment

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

This property is useless now that UnifiedPropertiesLoader is an object, consider inlining it.

Comment on lines +45 to +48
private fun writeToClasspath(
path: String,
content: String,
) {
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to format like this, the signature fits on one line

Suggested change
private fun writeToClasspath(
path: String,
content: String,
) {
private fun writeToClasspath(path: String, content: String) {

Copy link
Contributor Author

@snowykte0426 snowykte0426 Jan 6, 2026

Choose a reason for hiding this comment

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

The review feedback suggested formatting the signature on one line, but Spotless automatically formats it as:

private fun writeToClasspath(
    path: String,
    content: String,
) {
  @@ -39,7 +39,10 @@
   ········deleteFromClasspath(UnifiedPropertiesLoader.LEGACY_PROPERTIES_FILE)
   ····}

  -····private·fun·writeToClasspath(path:·String,·content:·String)·{
  +····private·fun·writeToClasspath(
  +········path:·String,
  +········content:·String,
  +····)·{
   ········resolveFromClasspath(path).run·{
   ············parent?.let·{·Files.createDirectories(it)·}
   ············Files.writeString(this,·content)

This formatting conflict prevents the CI from passing. Should we keep the Spotless format or override it to match the review preference?
@polarene

image

Copy link
Contributor

Choose a reason for hiding this comment

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

Hello! Oh right, I didn't remember Raibaz introduced Spotless just recently. Sure, if the formatting is enforced with that style so be it, ignore my style suggestion.

) {
getRoot().resolve(path.removePrefix("/")).run {
parent?.let { Files.createDirectories(it) }
Files.writeString(this, content, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)
Copy link
Contributor

Choose a reason for hiding this comment

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

These options are included by default when not passed, so we can simplify the call

Suggested change
Files.writeString(this, content, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)
Files.writeString(this, content)

}

private fun deleteFromClasspath(path: String) {
Files.delete(getRoot().resolve(path.removePrefix("/")))
Copy link
Contributor

Choose a reason for hiding this comment

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

I realized the expression getRoot().resolve(path.removePrefix("/")) is duplicated so it would be better to extract it to another function, for example resolveFromClasspath(path: String).

Files.delete(getRoot().resolve(path.removePrefix("/")))
}

private fun getRoot(): Path = Path.of(this::class.java.getResource("/")!!.toURI())
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a shorter extension property available:

Suggested change
private fun getRoot(): Path = Path.of(this::class.java.getResource("/")!!.toURI())
private fun getRoot(): Path = Path.of(javaClass.getResource("/")!!.toURI())

- Inline loader property since UnifiedPropertiesLoader is now an object
- Simplify method signatures to single line
- Remove unnecessary StandardOpenOption parameters (default behavior)
- Extract duplicated path resolution to resolveFromClasspath()
- Use javaClass extension instead of this::class.java

All tests pass.
@polarene
Copy link
Contributor

polarene commented Jan 5, 2026

Question: I assumed these were internal-only since they were deprecated, but I realize DefaultPropertiesLoader was in the public API. Should I revert this removal and keep the deprecated classes for a transition period, or is it acceptable to remove them now since UnifiedPropertiesLoader provides the same functionality?

Note on the Tests

@snowykte0426 thanks for your updates, everything seems good now. About DefaultPropertiesLoader I don't think it would be a problem removing it, despite being part of the public API it's not directly referenced by library users. @Raibaz do you see any problems?

Sorry for the incompatible suggestions regarding kotlin.io.path. I didn't know about the 1.7 compatibility, I always use the latest Kotlin.

@snowykte0426
Copy link
Contributor Author

snowykte0426 commented Jan 5, 2026

@polarene
I’ve applied all five inline code suggestions in commit d784011:

  • Inlined the loader property to remove an unnecessary intermediate variable
  • Removed redundant StandardOpenOption parameters that are already defaults
  • Extracted resolveFromClasspath() to eliminate duplication and improve maintainability
  • Replaced the reference with the javaClass extension property

All tests are passing (4/4). Please let me know if you’d like any further adjustments.

@snowykte0426
Copy link
Contributor Author

CI failed: https://github.com/mockk/mockk/actions/runs/20718814279/job/59562044513?pr=1474

The apiCheck failed because UnifiedPropertiesLoader was changed to an object, which modified the public API. Fixed by updating the API dump.(6d14427)

@Raibaz
Copy link
Collaborator

Raibaz commented Jan 8, 2026

Thank you both, @snowykte0426 and @polarene !

@Raibaz Raibaz merged commit 1b44e99 into mockk:master Jan 8, 2026
24 checks 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.

Unify settings files

3 participants