Skip to content
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

The API should support testing for "equivalence" to classes #60

Closed
codecholeric opened this issue Jan 10, 2018 · 2 comments
Closed

The API should support testing for "equivalence" to classes #60

codecholeric opened this issue Jan 10, 2018 · 2 comments

Comments

@codecholeric
Copy link
Collaborator

Sometimes a rule only targets a single class (e.g. class Foo is only accessed by classes matching a certain pattern). It should be possible to supply the class object in that case, instead of writing classes().that().haveFullyQualifiedName(Foo.class.getName()). Thus I propose an API extension:

  • classes().that().areEquivalentTo(Foo.class)
  • classes().should().beEquivalentTo(Foo.class)

which just pipes to JavaClass.isEquivalentTo(Foo.class).

@alex0ptr
Copy link

I like the idea, but I feel the proposal looks kind of verbose and could be more precise.
Maybe the(Foo.class) would be more readable. However theClass(Foo.class) or singleClass(Foo.class) would be closer to classes().

I would prefer
the(Foo.class).should()...
over
classes().that().areEquivalentTo(Foo.class).should()...

@codecholeric
Copy link
Collaborator Author

You're right, that would be more concise 😃
Guess the should part could then also be should().be(Foo.class)? Sounds a little strange maybe, since the rule clearly talks about a single class, so why do I have to start with classes()...
I think I like theClass(Foo.class) the best, since as you mentioned, it's closer to classes(), so it might be easier to find, if you just browse methods. (my favorite one would be class(Foo.class) if that was possible 😉 )
Hmm, maybe an empty one would make sense for the point above

theClass().that().isAnnotatedWith(Bar.class).should().be(Foo.class)

Or theOnlyClass()? Either way it could automatically ensure, that the that clause really only leaves one class.

msherman32 pushed a commit to msherman32/ArchUnit that referenced this issue May 24, 2018
I worked on adding theClass(String className) to the ArchRuleDefinition class so that users can easily select a specifc class to test

Signed-off-by: Michael Sherman <msherman32@gatech.edu>
msherman32 pushed a commit to msherman32/ArchUnit that referenced this issue May 25, 2018
msherman32 pushed a commit to msherman32/ArchUnit that referenced this issue May 28, 2018
Signed-off-by: Michael Sherman <msherman32@gatech.edu>
msherman32 pushed a commit to msherman32/ArchUnit that referenced this issue Jun 12, 2018
Issue: TNG#60
Signed-off-by: Michael Sherman <msherman32@gatech.edu>
msherman32 pushed a commit to msherman32/ArchUnit that referenced this issue Jun 14, 2018
Issue: TNG#60
Signed-off-by: Michael Sherman <msherman32@gatech.edu>
msherman32 pushed a commit to msherman32/ArchUnit that referenced this issue Jun 14, 2018
Issue: TNG#60
Signed-off-by: Michael Sherman <msherman32@gatech.edu>
msherman32 pushed a commit to msherman32/ArchUnit that referenced this issue Jun 14, 2018
Issue: TNG#60
Signed-off-by: Michael Sherman <msherman32@gatech.edu>
msherman32 pushed a commit to msherman32/ArchUnit that referenced this issue Jun 19, 2018
Issue: TNG#60
Signed-off-by: Michael Sherman <msherman32@gatech.edu>
msherman32 pushed a commit to msherman32/ArchUnit that referenced this issue Jun 19, 2018
noClass(..) entry point to create rules based on a specific class. Also
added should().be(..) and should().notBe().

Issue: TNG#60
Signed-off-by: Michael Sherman <msherman32@gatech.edu>
codecholeric added a commit to msherman32/ArchUnit that referenced this issue Jun 19, 2018
…l with the new (not)be(..) methods)

Issue: TNG#60
Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
codecholeric added a commit to msherman32/ArchUnit that referenced this issue Jun 19, 2018
…uld().be(..) and should().notBe(..)

Issue: TNG#60
Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
msherman32 pushed a commit to msherman32/ArchUnit that referenced this issue Jun 27, 2018
noClass(..) entry point to create rules based on a specific class. Also
added should().be(..) and should().notBe().

Issue: TNG#60
Signed-off-by: Michael Sherman <msherman32@gatech.edu>
msherman32 pushed a commit to msherman32/ArchUnit that referenced this issue Jun 27, 2018
…l with the new (not)be(..) methods)

Issue: TNG#60
Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
msherman32 pushed a commit to msherman32/ArchUnit that referenced this issue Jun 27, 2018
…uld().be(..) and should().notBe(..)

Issue: TNG#60
Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
@codecholeric codecholeric added this to the 0.9.0 milestone Aug 19, 2018
codecholeric pushed a commit that referenced this issue Feb 21, 2021
noClass(..) entry point to create rules based on a specific class. Also
added should().be(..) and should().notBe().

Issue: #60
Signed-off-by: Michael Sherman <msherman32@gatech.edu>
codecholeric added a commit that referenced this issue Feb 21, 2021
…l with the new (not)be(..) methods)

Issue: #60
Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
codecholeric added a commit that referenced this issue Feb 21, 2021
…uld().be(..) and should().notBe(..)

Issue: #60
Signed-off-by: Peter Gafert <peter.gafert@tngtech.com>
codecholeric added a commit that referenced this issue Feb 21, 2021
Adds theClass(..), noClass(..), should().be(..) and should().notBe(..)

Resolves: #60
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants