use of org.eclipse.xtext.ui.label.DefaultEObjectLabelProvider in project xtext-eclipse by eclipse.
the class DefaultEObjectLabelProviderTest method testSimple.
@Test
public void testSimple() throws Exception {
final List<String> calls = new ArrayList<String>();
@SuppressWarnings("unused") DefaultEObjectLabelProvider lp = new DefaultEObjectLabelProvider(null) {
{
setImageHelper(new IImageHelper.NullImageHelper());
}
public String text(String object) {
return object;
}
public String text(Integer object) {
return object.toString();
}
public String image(String obj) {
calls.add(obj);
return null;
}
public String image(Integer obj) {
calls.add(obj.toString());
return null;
}
};
assertEquals("foo", lp.getText("foo"));
assertEquals("89", lp.getText(new Integer(89)));
assertTrue(calls.isEmpty());
lp.getImage(true);
assertTrue(calls.isEmpty());
lp.getImage("String");
assertTrue(calls.contains("String"));
lp.getImage(new Integer(45));
assertTrue(calls.contains("45"));
assertTrue(calls.size() == 2);
}
use of org.eclipse.xtext.ui.label.DefaultEObjectLabelProvider in project xtext-eclipse by eclipse.
the class DefaultEObjectLabelProviderTest method testErrorHandling.
@Test
public void testErrorHandling() throws Exception {
final List<Object> calls = new ArrayList<Object>();
@SuppressWarnings("unused") DefaultEObjectLabelProvider defaultLabelProvider = new DefaultEObjectLabelProvider() {
{
setImageHelper(new IImageHelper.NullImageHelper());
}
public String text(String object) {
throw new NullPointerException();
}
public String text(Integer object) {
throw new IllegalArgumentException();
}
public String image(String obj) {
throw new NullPointerException();
}
public String image(Integer obj) {
throw new IllegalArgumentException();
}
@Override
protected String getDefaultText() {
return DEFAULT_TEXT;
}
@Override
protected Object handleImageError(Object[] params, Throwable e) {
calls.add(params[0]);
return super.handleImageError(params, e);
}
@Override
protected Object handleTextError(Object[] params, Throwable e) {
calls.add(params[0]);
return super.handleTextError(params, e);
}
};
assertEquals(DEFAULT_TEXT, defaultLabelProvider.getText("foo"));
assertEquals(1, calls.size());
try {
assertEquals("89", defaultLabelProvider.getText(new Integer(89)));
fail();
} catch (RuntimeException e) {
assertTrue(e instanceof IllegalArgumentException);
}
assertEquals(2, calls.size());
assertNull(defaultLabelProvider.getImage("String"));
assertEquals(3, calls.size());
try {
defaultLabelProvider.getImage(new Integer(45));
fail();
} catch (RuntimeException e) {
assertTrue(e instanceof IllegalArgumentException);
}
assertEquals(4, calls.size());
}
use of org.eclipse.xtext.ui.label.DefaultEObjectLabelProvider in project xtext-eclipse by eclipse.
the class DefaultEObjectLabelProviderTest method testGetTextCharSequence.
@Test
public void testGetTextCharSequence() throws Exception {
DefaultEObjectLabelProvider defaultLabelProvider = new DefaultEObjectLabelProvider() {
@SuppressWarnings("unused")
public Object text(ParserRule parserRule) {
StringConcatenation _builder = new StringConcatenation();
_builder.append(parserRule.getName());
return _builder;
}
};
ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule();
parserRule.setName("testCreateStyledString");
String styledText = defaultLabelProvider.getText(parserRule);
assertEquals("testCreateStyledString", styledText);
}
use of org.eclipse.xtext.ui.label.DefaultEObjectLabelProvider in project xtext-eclipse by eclipse.
the class DefaultEObjectLabelProviderTest method testGetStyledTextFallbackText.
@Test
public void testGetStyledTextFallbackText() throws Exception {
DefaultEObjectLabelProvider defaultLabelProvider = new DefaultEObjectLabelProvider();
ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule();
parserRule.setName("testCreateStyledString");
StyledString styledText = defaultLabelProvider.getStyledText(parserRule);
assertEquals("testCreateStyledString", styledText.getString());
}
use of org.eclipse.xtext.ui.label.DefaultEObjectLabelProvider in project xtext-eclipse by eclipse.
the class DefaultEObjectLabelProviderTest method testGetTextWithExistingStyledStringLabel.
@Test
public void testGetTextWithExistingStyledStringLabel() throws Exception {
DefaultEObjectLabelProvider defaultLabelProvider = new DefaultEObjectLabelProvider() {
@SuppressWarnings("unused")
public StyledString text(ParserRule parserRule) {
return new StyledString(parserRule.getName());
}
};
ParserRule parserRule = XtextFactory.eINSTANCE.createParserRule();
parserRule.setName("testGetTextWithStyledStringLabel");
assertEquals("testGetTextWithStyledStringLabel", defaultLabelProvider.getText(parserRule));
}
Aggregations