-
Notifications
You must be signed in to change notification settings - Fork 301
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow empty layers in LayeredArchitecture & OnionArchitecture when configured #273
Conversation
DeepCode's analysis on #e9f87d found:
💬 This comment has been generated by the DeepCode bot, installed by the owner of the repository. The DeepCode bot protects your repository by detecting and commenting on security vulnerabilities or other critical issues. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kewl, thanks a lot for your support 😄 I added a couple of thoughts in some places, tell me what you think. Also I'd be really interested in your input on #267 (comment)
EvaluationResult result = architecture.evaluate(classes); | ||
boolean expectViolation = allowEmptyLayers != Boolean.TRUE; | ||
assertThat(result.hasViolation()).as("result of evaluating empty layers has violation").isEqualTo(expectViolation); | ||
if (expectViolation) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering, if it would be better to have either two tests, or specify given and the assertion in the data point. I find conditionals in assertions harder to read and harder to maintain in the long run. What do you think?
I would see as alternatives to either extract the common given into a method or pass more into the data point, e.g. pass a function pair given{ architecture -> architecture.allowEmptyLayers(true) }
and expected{ failureReport -> assertThat(failureReport.isEmpty()).as("failure report").isTrue(); }
as data point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alternatively, we can also extract helper methods such as
private OnionArchitecture anOnionArchitectureWithEmptyLayers()
private void assertFailureOnionArchitectureWithEmptyLayers(EvaluationResult result)
and explicitly unroll the data points into
@Test public void onion_architecture_rejects_empty_layers_by_default()
@Test public void onion_architecture_allows_empty_layers_if_configured_to_allow()
@Test public void onion_architecture_rejects_empty_layers_if_explicitly_configured_to_not_allow()
archunit/src/main/java/com/tngtech/archunit/library/Architectures.java
Outdated
Show resolved
Hide resolved
LayeredArchitecture architecture = layeredArchitecture() | ||
.layer("Some").definedBy(absolute("should.not.be.found..")) | ||
.layer("Other").definedBy(absolute("also.not.found")) | ||
.layer("Okay").definedBy("..testclasses.."); | ||
if (allowEmptyLayers != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as below. For me it is also hard to immediately grasp at the first look, that those two conditional blocks relate to each other and are only set in conjunction...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no 1:1 correspondence, but an explicit test is probably still better than this implicit construction.
@hankem do you have any strong opinion regarding the discussion of #278 (the discussion if the new method should also become part of the description)? To me it seems that either both of these features, or none of them should add additional information to the description, since they are of similar type... |
No, I don't have a strong opinion. I initially considered A difference between those and this configuration specific to |
Signed-off-by: Manfred Hanke <Manfred.Hanke@tngtech.com>
Signed-off-by: Manfred Hanke <Manfred.Hanke@tngtech.com>
Signed-off-by: Manfred Hanke <Manfred.Hanke@tngtech.com>
Signed-off-by: Manfred Hanke <Manfred.Hanke@tngtech.com>
Signed-off-by: Manfred Hanke <Manfred.Hanke@tngtech.com>
Signed-off-by: Manfred Hanke <Manfred.Hanke@tngtech.com>
….optionalLayer Signed-off-by: Manfred Hanke <Manfred.Hanke@tngtech.com>
…y default Signed-off-by: Manfred Hanke <Manfred.Hanke@tngtech.com>
Signed-off-by: Manfred Hanke <Manfred.Hanke@tngtech.com>
14c7ffa
to
e9f87de
Compare
Looks noice now, thank you so much 😄 |
Resolves #267 & #271:
After #177 had prevented empty layers by default, this can now be overridden to re-allow empty layers in
LayeredArchitecture
&OnionArchitecture
.