MockBox - Mocking an exception of type database

Hi group,

I’m trying to simulate the occurance of a database error in one of my tests and to do this I’ve setup a mocked service like this :

StudentService.$(method=‘save’,throwException=true,throwType=‘Database’);

When I run the test though I get the following error:-

Attribute validation error for tag CFTHROW.

The value of the attribute type, which is currently Database, is invalid.

The error reports I’m basing my testing on are showing that the errors were of type database so I’m at a bit of a lose on how to approach this one. Any ideas?

Cheers,
James

P.S. Here’s a sample of the code I’m trying to test…

Ok so “Database” is a reserved word in ColdFusion so this is maybe the wrong approach to this problem.

Rethink - I’m maybe better putting a real service in here and using something like MXUnit’s injectMethod() to swap the save() for one that has a broken query in it ( maybe call a table that doesn’t exist perhaps! )

It means I’m relying on real database interaction here but it would give me the results I need.

Any other thoughts are appreciated.

Cheers,
James

Ok so got it … seems that’s the solution.

I’ve used injectMethod like so

local.StudentService = getColdBox().getPlugin(‘ioc’).getBean(‘StudentService’);
injectMethod(local.StudentService,this,‘testBrokenSave’,‘save’);

and replaced it with this method

select someNonExistantColum from someNonExistantTable

The fact I’m calling a non-existant datasource means I’m avoiding that dependancy I mention as well… which is good enough for me :slight_smile:

James