-
Notifications
You must be signed in to change notification settings - Fork 55
/
CustomCommandResourceViewFactoryTest.java
62 lines (56 loc) · 2.41 KB
/
CustomCommandResourceViewFactoryTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package de.bastiankrol.startexplorer.customcommands;
import static de.bastiankrol.startexplorer.customcommands.CommandConfigObjectMother.*;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import org.eclipse.core.commands.Command;
import org.eclipse.jface.action.IContributionItem;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@RunWith(PowerMockRunner.class)
@PrepareForTest(Command.class)
public class CustomCommandResourceViewFactoryTest extends AbstractCustomCommandFactoryTest
{
@Override
AbstractCustomCommandFactory createFactory()
{
return new CustomCommandResourceViewFactory();
}
@Test
public void oneCommandForResourceView() throws Exception
{
// given a configuration with only one command config for resource view
when(this.preferenceUtilMock.getCommandConfigListFromPreferences())
.thenReturn(oneForBoth());
// when getContributionItems is called by the Eclipse platform
IContributionItem[] contributionItems = this.customCommandFactory
.getContributionItems();
// it should return one contribution item
assertEquals(1, contributionItems.length);
verify(this.customCommandFactory).createContributionItem(
this.parameterCaptor.capture());
assertEquals("command/both/resource", this.parameterCaptor.getAllValues()
.get(0).label);
}
@Test
public void twoCommandsForResourceViewOneEditorCommandToBeIgnored()
throws Exception
{
// given a configuration with two command configs for resource view and one
// only for editor
when(this.preferenceUtilMock.getCommandConfigListFromPreferences())
.thenReturn(oneForBothOneForResourceOneForEditor());
// when getContributionItems is called by the Eclipse platform
IContributionItem[] contributionItems = this.customCommandFactory
.getContributionItems();
// it should return two contribution items
assertEquals(2, contributionItems.length);
verify(this.customCommandFactory, times(2)).createContributionItem(
this.parameterCaptor.capture());
assertEquals("command/both/resource", this.parameterCaptor.getAllValues()
.get(0).label);
assertEquals("command/resource",
this.parameterCaptor.getAllValues().get(1).label);
}
}