riy / degraph

Test and Visualize and Manage Dependencies of classes and packages in JVM Byte Code (think Scala and Java)
http://riy.github.io/degraph/
Other
311 stars 36 forks source link

How to check for unidirectional dependency #71

Closed derTobsch closed 7 years ago

derTobsch commented 7 years ago

I have three packages below coffee.synyx.autoconfigure for example and want to ensure that they do not use each other.

coffee.synyx.autoconfigure.discovery
coffee.synyx.autoconfigure.logging
coffee.synyx.autoconfigure.security

how do I write a unit test to test this? I only found documentation to say e.g. that logging is allowed to use security but not the other way. That would be done with allow() or allowDirect(). But how do I write a test that says nobody is allowed to use the other ones?

schauder commented 7 years ago

can't actually try it right now, but the following should work:

.withSlicing("parts", "coffee.synyx.autoconfigure.(*).**")
    .allow(oneOf( "discovery", "logging", "security"))

oneOf is intended when a bunch of slices may depend on different group but not on each other. If used as above only the second part has an effect, which should be exactly what you want.

Let me know if it works.

And sorry for insisting on a github issue, but this way we can have proper formatted code examples, and others have a chance to find this as well.

derTobsch commented 7 years ago

Thanks for your help. That does what I want. I knew oneOf() already, but never thought of using it without a "second" part.

It does work. Thanks for your help.