-
Notifications
You must be signed in to change notification settings - Fork 394
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
Show the "GitHub" link for Workflow projects #105
Show the "GitHub" link for Workflow projects #105
Conversation
@Override | ||
public Collection<? extends Action> createFor(Job j) { | ||
GithubProjectProperty prop = | ||
(GithubProjectProperty) ((Job<?, ?>) j).getProperty(GithubProjectProperty.class); |
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.
Are you sure that you need cast it? Why job is also recasted?
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 remember my IDE complaining here for both of these.
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.
If you cast to Job<?,?>
you should get a well-typed return value from getProperty
. Or you can use (GithubProjectProperty) j.getProperty(GithubProjectProperty.class)
.
Thank you for this pull request! Please check this document for how the Jenkins project handles pull requests. |
} | ||
|
||
@Override | ||
public Collection<? extends Action> createFor(Job j) { |
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.
Have you tried (Job<?, ?> j)
here and remove casts?
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.
it doesn't work, as it should have same signature as in generic
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.
Right, due to Java erasure it is not possible to do better, except perhaps with more exotic type tokens.
Please also add simple unit test which will call |
7f6f32c
to
7ff5ee9
Compare
@lanwen I fixed the code issues and will add unit tests asap. |
7ff5ee9
to
fd19ca8
Compare
Hey @lanwen @jglick @KostyaSha I just updated this PR to include test cases. Please keep the feedback coming, I usually don't do Java development, so my knowledge of "Java best-practices" is spotty at best and I'm happy for any suggestions that you might have. |
fd19ca8
to
eed2d6b
Compare
@lanwen Do I need to resolve the comments pointed out by @dummy-lanwen-bot ? I don't feel that adding custom error messages to these assertions is going to help a lot, but if that's something that is important, I can fix this up. |
@arthurschreiber yes, describe something. After 1 year it will be very difficult understand what happened in test when you get this error from some integration system. |
assertThat(actions.size(), is(equalTo(1))); | ||
|
||
GithubLinkAction action = (GithubLinkAction) actions.iterator().next(); | ||
assertThat(action.getUrlName(), is(equalTo("https://github.com/jenkinsci/github-plugin/"))); |
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.
please add here comment "url name".
Also is(equalTo())
is the same as simple is()
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 added some descriptions for all assertions.
d6a2a70
to
f6815e2
Compare
@KostyaSha I'm not new to unit testing, but I often feel there's cases where adding a custom description ends up as being nothing more than boilerplate that no one ever needs. As long as the checks that are done inside the test cases (1 assertion per test), the test names should be enough description. And if your tests end up using many assertions, a custom matcher with a custom error formatting might be more appropriate. Anyway, I performed all the suggested changes, feel free to review again. |
@Test | ||
public void shouldCreateGithubLinkActionForJobWithGithubProjectProperty() throws IOException { | ||
WorkflowJob job = createExampleJob(); | ||
String url = "https://github.com/jenkinsci/github-plugin/"; |
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.
please move it to const
private static final String GH_PROJECT = "..."
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.
Sorry to ask, but what would be the benefit of that? This value is not used in any other test case, so making it a property on the class does not make me feel like it has any obvious benefits.
Again, I'm no Java Expert, so if there's benefits to this, feel free to let me know. Learning new things is always good. 😄
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.
its not the test value itself, its just a some data which should remain the same in this test.
Vars should be used if they make some active role in the test
http://xunitpatterns.com/, page 192 (Irrelevant information)
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.
Thanks for the explanation! ❤️
3fc843e
to
c6cdaa0
Compare
@arthurschreiber u're right for 1 assertion for one test and custom matchers ❤️ I've commented the examples of such comments |
c6cdaa0
to
fa368bd
Compare
I'll perform your suggested changes (you are maintaining the project, overall). ❤️
Yeah, I feel that using plain Did I miss anything? |
only const for url now. Add it, and i'll merge and release |
…Actions`. This makes the "GitHub" link also show up for Workflow projects.
fa368bd
to
054719a
Compare
@lanwen Can you check again? 👍 |
return rule.getInstance().createProject(WorkflowJob.class, "example"); | ||
} | ||
|
||
private GithubProjectProperty createExampleProperty() { |
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.
could be inlined, but nvm
…upport Show the "GitHub" link for Workflow projects
Thank you so much for putting up with my lack of Java knowledge. And thanks for merging this and releasing it so quickly. 😄 |
thanks for PR and quick review fixes |
This will make the "GitHub" Link show up on Workflow Jobs and other similar types (like Multibranch Workflow Jobs).