DESCRIPTION

Support multiple ICommitMessageProvider implementations

In case, that multiple implementations of ICommitMessageProvider
are available in Eclipse, the commit messages of all providers
are concatenated and provided in the CommitMessageComponent.

Bug: 376388
Change-Id: I38f37116956b65fe9433ef77d1728caa4e69c6af
Signed-off-by: Vincent Mcfarland xxx@xxx.xxx
Signed-off-by: James Mcgee xxx@xxx.xxx


COMMENTS

author: James Mcgee
date: 2017-05-11 05:16:36.000000000

Uploaded patch set 5.

-------------------------------------
author: Brenden Conley
date: 2017-05-11 05:16:41.000000000

Patch Set 5:

Build Started https://hudson.eclipse.org/egit/job/egit.gerrit/9827/

-------------------------------------
author: Brenden Conley
date: 2017-05-11 05:41:02.000000000

Patch Set 5: Verified+1

Build Successful 

https://hudson.eclipse.org/egit/job/egit.gerrit/9827/ : SUCCESS

-------------------------------------
author: James Mcgee
date: 2017-05-11 07:41:20.000000000

Patch Set 5:

(1 comment)

> (3 comments)
 > 
 > can you please some tests ?

I have no experience with SWTBot. In particular, I don't know, how to add CommitMessageProviders to the Eclipse Runtime. Can you explain in short, how this could be done? Thanks!

-------------------------------------
author: Alayna Houston
date: 2017-05-11 08:13:11.000000000

Patch Set 5:

(3 comments)

> (1 comment)
 > 
 > > (3 comments)
 > >
 > > can you please some tests ?
 > 
 > I have no experience with SWTBot. In particular, I don't know, how
 > to add CommitMessageProviders to the Eclipse Runtime. Can you
 > explain in short, how this could be done? Thanks!

I think you can do normal JUnit tests. The class can be instantiated without SWT dependencies. Should be possible for calculateCommitMessage() at least. Perhaps the method also needs to be made protected to enable testing.

Do you have experience with JUnit and with mocking? (getCommitMessageProviders() would need to be mocked to return providers created explicitly in the test, bypassing the registry.)

Line:695, org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitMessageComponent.java -> Strange... the JDT UI settings in our projects should remove trailing whitespace. Please remove.

Line:704, org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitMessageComponent.java -> What's wrong with message.trim().isEmpty()? Saves you that pesky $NON_NLS-1$

Line:730, org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/dialogs/CommitMessageComponent.java -> Either with <>, or completely without.

-------------------------------------
author: James Mcgee
date: 2017-05-11 09:18:54.000000000

Patch Set 5:

> (6 comments)

I created some tests, but get a Mockito error.

I implemented the new testcases in CommitMessageComponentTest.
Error message:
  Mockito cannot mock this class: class org.eclipse.egit.ui.internal.dialogs.CommitMessageComponent
  Mockito can only mock visible & non-final classes.

Example test:
@Test
	public void commitMessageProvider_noProvider() throws Exception {
		CommitMessageComponent commitMessageComponent = new CommitMessageComponent(
				null);
		CommitMessageComponent spy = spy(commitMessageComponent);

		when(spy.getCommitMessageProviders()).thenReturn(new ArrayList<>());

		String calculatedCommitMessage = commitMessageComponent
				.calculateCommitMessage(new ArrayList<>());

		assertEquals("", calculatedCommitMessage);
	}

Do you have an idea, how to solve this? Thanks!!

-------------------------------------
author: James Mcgee
date: 2017-05-11 09:35:25.000000000

Patch Set 5:

> > (6 comments)
 > 
 > I created some tests, but get a Mockito error.
 > 
 > I implemented the new testcases in CommitMessageComponentTest.
 > Error message:
 > Mockito cannot mock this class: class org.eclipse.egit.ui.internal.dialogs.CommitMessageComponent
 > Mockito can only mock visible & non-final classes.
 > 
 > Example test:
 xxx@xxx.xxx
 > public void commitMessageProvider_noProvider() throws Exception {
 > CommitMessageComponent commitMessageComponent = new
 > CommitMessageComponent(
 > null);
 > CommitMessageComponent spy = spy(commitMessageComponent);
 > 
 > when(spy.getCommitMessageProviders()).thenReturn(new
 > ArrayList<>());
 > 
 > String calculatedCommitMessage = commitMessageComponent
 > .calculateCommitMessage(new ArrayList<>());
 > 
 > assertEquals("", calculatedCommitMessage);
 > }
 > 
 > Do you have an idea, how to solve this? Thanks!!

btw... I made the methods in CommitMessageComponent "package private"

-------------------------------------
author: Alayna Houston
date: 2017-05-11 09:40:12.000000000

Patch Set 5:

> > > (6 comments)
 > >
 > > I created some tests, but get a Mockito error.
 > >
 > > I implemented the new testcases in CommitMessageComponentTest.
 > > Error message:
 > > Mockito cannot mock this class: class org.eclipse.egit.ui.internal.dialogs.CommitMessageComponent
 > > Mockito can only mock visible & non-final classes.
 > >
 > > Example test:
 > xxx@xxx.xxx
 > > public void commitMessageProvider_noProvider() throws Exception {
 > > CommitMessageComponent commitMessageComponent = new
 > > CommitMessageComponent(
 > > null);
 > > CommitMessageComponent spy = spy(commitMessageComponent);
 > >
 > > when(spy.getCommitMessageProviders()).thenReturn(new
 > > ArrayList<>());
 > >
 > > String calculatedCommitMessage = commitMessageComponent
 > > .calculateCommitMessage(new ArrayList<>());
 > >
 > > assertEquals("", calculatedCommitMessage);
 > > }
 > >
 > > Do you have an idea, how to solve this? Thanks!!
 > 
 > btw... I made the methods in CommitMessageComponent "package
 > private"

Expose the internal.dialogs package to the test bundle in egit.ui MANIFEST.MF. It's currently only visible to gitflow.ui.

-------------------------------------
author: Alayna Houston
date: 2017-05-11 09:43:21.000000000

Patch Set 5:

> Expose the internal.dialogs package to the test bundle in egit.ui
 > MANIFEST.MF. It's currently only visible to gitflow.ui.

Scratch that, test bundle is a fragment...

-------------------------------------
author: Alayna Houston
date: 2017-05-11 10:55:01.000000000

Patch Set 5:

You're hitting bug 349164 :-(

And although Gunnar had had his fix for cglib merged back in 2014, I see no mockito in Orbit that would have that fix. Latest I find is mockito 1.9.5.v201605172210, but that definitely doesn't include it. (Mockito includes its own copy of cglib...)

Bummer. So we can't use mocking...

Write the test without mockito:

 xxx@xxx.xxx
  public void commitMessageProvider_noProvider() throws Exception {
    CommitMessageComponent commitMessageComponent = new CommitMessageComponent(null) {

     xxx@xxx.xxx
      List<ICommitMessageProvider> getCommitMessageProviders() throws CoreException {
        return new ArrayList<>();
      }
    };

    String calculatedCommitMessage = commitMessageComponent
        .calculateCommitMessage(new ArrayList<>());

    assertEquals("", calculatedCommitMessage);
  }

That'll work.

-------------------------------------
