Skip to content

Commit 4e49725

Browse files
committed
Adds test for DefaultDisplayService choosing the matching display with the highest priority
1 parent 209a55d commit 4e49725

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package org.scijava.display;
2+
3+
public class CustomTextDisplay extends AbstractDisplay<String> implements
4+
TextDisplay
5+
{
6+
7+
public CustomTextDisplay() {
8+
super(String.class);
9+
}
10+
11+
@Override
12+
public void append(final String text) {
13+
add(text);
14+
}
15+
16+
}

src/test/java/org/scijava/display/DisplayTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939

4040
import org.junit.Test;
4141
import org.scijava.Context;
42+
import org.scijava.Priority;
43+
import org.scijava.plugin.PluginInfo;
44+
import org.scijava.plugin.PluginService;
45+
46+
import java.util.List;
4247

4348
/**
4449
* Unit tests for core {@link Display} classes.
@@ -132,4 +137,20 @@ public void testText() {
132137
assertEquals(value, result);
133138
}
134139

140+
@Test
141+
public void testMultipleDisplaysPriorityMatch() {
142+
final Context context = new Context(DisplayService.class);
143+
PluginInfo<Display> info = PluginInfo.create(CustomTextDisplay.class, Display.class);
144+
info.setPriority(Priority.HIGH);
145+
context.service(PluginService.class).addPlugin(info);
146+
final DefaultDisplayService displayService =
147+
context.getService(DefaultDisplayService.class);
148+
final String name = "Text";
149+
final String value = "Hello";
150+
List<Display<?>> matchingDisplays = displayService.getMatchingDisplays(value);
151+
assertNotNull(matchingDisplays);
152+
assertTrue(matchingDisplays.size() > 1);
153+
Display<?> display = displayService.createDisplay(name, value);
154+
assertEquals(CustomTextDisplay.class, display.getClass());
155+
}
135156
}

0 commit comments

Comments
 (0)