testing custom validator - different behaviour for assertWarning() vs assertWarningContains()? [message #794973] |
Thu, 09 February 2012 18:16  |
Eclipse User |
|
|
|
Writing unit tests for custom validation and confused by behaviour. Would appreciate any suggestions.
Custom validator as follows:
@Check
public void domainShouldStartWithCapital(Domain domain) {
if (!Character.isUpperCase(domain.getName().charAt(0))) {
warning("Name should start with a capital",
domain,
OoaPackage.Literals.DOMAIN__NAME,
101);
}
}
If I write unit test as follows it works:
public void testDomainShouldStartWithCapital(){
Domain domain = OoaFactory.eINSTANCE.createDomain();
domain.setName("domain");
tester.validator().domainShouldStartWithCapital(domain);
tester.diagnose().assertWarningContains("Name should start with a capital");
}
However if I replace the diagnose() call (last line) with the following it fails:
tester.diagnose().assertWarning(101);
Failure:
java.lang.AssertionError: Predicate (WARNING code=101) does not match Diagnostic WARNING "Name should start with a capital" at Domain'domain'.name=="domain"
at org.eclipse.xtext.junit.validation.AssertableDiagnostics.fail(AssertableDiagnostics.java:272)
...
Don't understand why and couldn't figure it out. Any suggestions?
Thanks.
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03903 seconds