sbabcoc / JUnit-Foundation

JUnit Foundation is a lightweight collection of JUnit watchers, interfaces, and static utility classes that supplement and augment the functionality provided by the JUnit API.
Apache License 2.0
22 stars 6 forks source link

Uncomfortable way to initialize listeners, watchers etc. #61

Closed brutskov closed 4 years ago

brutskov commented 4 years ago

You are using service loader to load customer listeners and watchers by component (one listener - one service file). It makes sense to create some marker interface (like LifecycleItem) and load all listeners and watchers on one ServiceLoader call. You'l resolve and collect our listeners by type on your side but users will be have only one META-INF/services/LifecycleItem file in the classpath.

image

sbabcoc commented 4 years ago

Good suggestion. I'll see about rolling that out soon.

brutskov commented 4 years ago

@sbabcoc , thank you!

sbabcoc commented 4 years ago

I have a pull request that implements the revised watcher attachment strategy: https://github.com/Nordstrom/JUnit-Foundation/pull/63 This set of revisions consolidates the declaration of JUnit Foundation service providers into a single configuration file. Support for the previous file-per-interface approach is retained to provide backward compatibility. One significant benefit to switching from ServiceLoaders to pre-initialized unmodifiable lists is that I no longer need to synchronize my iterators. The code is therefore smaller and less complicated. Another benefit is that we no longer end up with multiple instances of each service provider that implements multiple interfaces. Previously, a separate instance would be instantiated for each implemented interface.