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

SWITCHYARD-2959 - ensuring that previous version is in SY version #634

Merged
merged 1 commit into from
Nov 3, 2016

Conversation

bfitzpat
Copy link
Member

drop-down list. In this case, 2.0.0.Final

Copy link
Collaborator

@apupier apupier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we can add a test quite easily by calling populateRuntimeVersionsList and checking that the availableVersions returned contains what is expected (previous, default and the normalone)

_availableVersions.add(defaultVersion);
}

// for SWITCHYARD-2959 - add previous version as well
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer not setting JIRA number, would be better to extract a method with a name like ensureDefaultAndPreviousVersionAvailable

Copy link
Member Author

@bfitzpat bfitzpat Nov 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that a stylistic thing (not setting JIRA # in the comment)? Because you didn't comment on it in the changes for #637

If it is a style thing and something we want to achieve going forward, I'm fine with it - but I personally like leaving breadcrumbs back to the reasons behind why certain changes were made. The goal of comments is to make the code more readable and this just gives us more information. Just my opinion of course.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for popping this out to another method, I'm good with that - it holds with the principles of "Building Maintainable Software" pretty closely.

@bfitzpat
Copy link
Member Author

bfitzpat commented Nov 3, 2016

@apupier I have updated this PR per your suggestions. Had to do a bit of refactoring (probably more than I needed, but it made sense to move more things back to M2EUtils), but I moved the new code into a new method and added a new test. Works locally and tests all pass. Just waiting for the PR build

final ArtifactVersion defaultVersion = M2EUtils.parseVersion(NewSwitchYardProjectWizard.DEFAULT_RUNTIME_VERSION);
final ArtifactVersion previousVersion = M2EUtils.parseVersion(NewSwitchYardProjectWizard.PREVIOUS_RUNTIME_VERSION);

assertTrue("Versions list missing default SwitchYard Version", versions.contains(defaultVersion));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional:
I like to use AssertJ to check for collections.
For instance here, it will be something like:
assertThat(versions).as("Versions list missing default SwitchYard Version").contains(defaultVersion);
but maybe a matter of taste

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ok with the older approach, but I see your point. I'll look at more prescriptive assert statements as we go forward but don't see this as necessary for now.

@@ -353,4 +358,14 @@ protected void execute(IProgressMonitor monitor) throws CoreException {

}

public void testVersionsListHasDefaultAndPreviousVersions() throws Exception {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional: might worth adding a second test to ensure that they are not added twice

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you point out below, it's a set, so they're unique.

public static Set<ArtifactVersion> ensureDefaultAndPreviousVersionAvailable(final Set<ArtifactVersion> versions) {
// add default version
final ArtifactVersion defaultVersion = parseVersion(NewSwitchYardProjectWizard.DEFAULT_RUNTIME_VERSION);
if (!versions.contains(defaultVersion)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just realizing now: if it is a Set we don't need to check if it is contained inside first

drop-down list. In this case, 2.0.0.Final

- also refactored some code for a bit easier testing
- added new test
- updated to remove if (!contains) statements (unneeded since we're
adding to a set, which guarantees uniqueness)
final Set<ArtifactVersion> versions = filterSwitchYardVersions(resolveSwitchYardVersionRange(monitor));
return versions;
} catch (CoreException e) {
final Set<ArtifactVersion> versions = new LinkedHashSet<ArtifactVersion>();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional: directly return new LinkedHashSet();

@bfitzpat
Copy link
Member Author

bfitzpat commented Nov 3, 2016

Thanks Aurelien

@bfitzpat bfitzpat merged commit b46ce78 into jboss-switchyard:master Nov 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants