1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 17:05:26 +02:00

Move assertInstance() up from AST2TestBase to BaseTestCase

Change-Id: Ibe45d247f6f027691625a04fcc8971f84e2764a7
Signed-off-by: Nathan Ridge <zeratul976@hotmail.com>
This commit is contained in:
Nathan Ridge 2015-12-25 20:08:55 -05:00
parent 102c7b58cf
commit 2cc3e248b4
2 changed files with 12 additions and 10 deletions

View file

@ -505,16 +505,6 @@ public class AST2TestBase extends BaseTestCase {
return TestSourceReader.getContentsForTest(plugin.getBundle(), "parser", getClass(), getName(), sections);
}
protected static <T> T assertInstance(Object o, Class<T> clazz, Class... cs) {
assertNotNull("Expected object of " + clazz.getName() + " but got a null value", o);
assertTrue("Expected "+clazz.getName()+" but got "+o.getClass().getName(), clazz.isInstance(o));
for (Class c : cs) {
assertNotNull("Expected object of " + c.getName() + " but got a null value", o);
assertTrue("Expected " + c.getName() + " but got " + o.getClass().getName(), c.isInstance(o));
}
return clazz.cast(o);
}
protected static void assertField(IBinding binding, String fieldName, String ownerName) {
assertInstance(binding, IField.class);
assertEquals(fieldName, binding.getName());

View file

@ -337,4 +337,16 @@ public class BaseTestCase extends TestCase {
public static void waitUntilFileIsIndexed(IIndex index, IFile file) throws Exception {
TestSourceReader.waitUntilFileIsIndexed(index, file, INDEXER_TIMEOUT_SEC * 1000);
}
// Assertion helpers
protected static <T> T assertInstance(Object o, Class<T> clazz, Class... cs) {
assertNotNull("Expected object of " + clazz.getName() + " but got a null value", o);
assertTrue("Expected "+clazz.getName()+" but got "+o.getClass().getName(), clazz.isInstance(o));
for (Class c : cs) {
assertNotNull("Expected object of " + c.getName() + " but got a null value", o);
assertTrue("Expected " + c.getName() + " but got " + o.getClass().getName(), c.isInstance(o));
}
return clazz.cast(o);
}
}