Fixed expectations syntax for latest JMockit. Make testDelete() independent

This commit is contained in:
Tim Donohue
2014-08-08 16:03:53 -05:00
parent 0ac682cc4d
commit 0b28592a1b

View File

@@ -88,7 +88,7 @@ public class BitstreamTest extends AbstractDSpaceObjectTest
@Test @Test
public void testBSFind() throws SQLException public void testBSFind() throws SQLException
{ {
int id = 1; int id = this.bs.getID();
Bitstream found = Bitstream.find(context, id); Bitstream found = Bitstream.find(context, id);
assertThat("testBSFind 0", found, notNullValue()); assertThat("testBSFind 0", found, notNullValue());
//the item created by default has no name nor type set //the item created by default has no name nor type set
@@ -291,7 +291,7 @@ public class BitstreamTest extends AbstractDSpaceObjectTest
@Test @Test
public void testGetSize() public void testGetSize()
{ {
long size = 238413; long size = 238413; // yuck, hardcoded!
assertThat("testGetSize 0", bs.getSize(), equalTo(size)); assertThat("testGetSize 0", bs.getSize(), equalTo(size));
} }
@@ -367,15 +367,13 @@ public class BitstreamTest extends AbstractDSpaceObjectTest
@Test(expected=AuthorizeException.class) @Test(expected=AuthorizeException.class)
public void testUpdateNotAdmin() throws SQLException, AuthorizeException public void testUpdateNotAdmin() throws SQLException, AuthorizeException
{ {
new NonStrictExpectations(AuthorizeManager.class)
{{
// Disallow Bitstream WRITE perms
AuthorizeManager.authorizeAction((Context) any, (Bitstream) any,
Constants.WRITE); result = new AuthorizeException();
new NonStrictExpectations() }};
{
AuthorizeManager authManager;
{
AuthorizeManager.authorizeAction((Context) any, (Bitstream) any,
Constants.WRITE); result = new AuthorizeException();
}
};
//TODO: we need to verify the update, how? //TODO: we need to verify the update, how?
bs.update(); bs.update();
} }
@@ -386,15 +384,14 @@ public class BitstreamTest extends AbstractDSpaceObjectTest
@Test @Test
public void testUpdateAdmin() throws SQLException, AuthorizeException public void testUpdateAdmin() throws SQLException, AuthorizeException
{ {
new NonStrictExpectations(AuthorizeManager.class)
{{
// Allow Bitstream WRITE perms
AuthorizeManager.authorizeAction((Context) any, (Bitstream) any,
Constants.WRITE); result = null;
new NonStrictExpectations() }};
{
AuthorizeManager authManager;
{
AuthorizeManager.authorizeAction((Context) any, (Bitstream) any,
Constants.WRITE); result = null;
}
};
//TODO: we need to verify the update, how? //TODO: we need to verify the update, how?
bs.update(); bs.update();
} }
@@ -403,24 +400,18 @@ public class BitstreamTest extends AbstractDSpaceObjectTest
* Test of delete method, of class Bitstream. * Test of delete method, of class Bitstream.
*/ */
@Test @Test
public void testDelete() throws SQLException, AuthorizeException public void testDelete() throws IOException, SQLException
{ {
bs.delete(); // Create a new bitstream, which we can delete. As ordering of these
assertTrue("testDelete 0", bs.isDeleted()); // tests is unpredictable we don't want to delete the global bitstream
File f = new File(testProps.get("test.bitstream").toString());
Bitstream delBS = Bitstream.create(context, new FileInputStream(f));
assertFalse("testIsDeleted 0", delBS.isDeleted());
delBS.delete();
assertTrue("testDelete 0", delBS.isDeleted());
} }
/**
* Test of isDeleted method, of class Bitstream.
*/
@Test
public void testIsDeleted() throws SQLException, AuthorizeException
{
assertFalse("testIsDeleted 0", bs.isDeleted());
bs.delete();
assertTrue("testIsDeleted 1", bs.isDeleted());
}
/** /**
* Test of retrieve method, of class Bitstream. * Test of retrieve method, of class Bitstream.
*/ */
@@ -428,14 +419,12 @@ public class BitstreamTest extends AbstractDSpaceObjectTest
public void testRetrieveCanRead() throws IOException, SQLException, public void testRetrieveCanRead() throws IOException, SQLException,
AuthorizeException AuthorizeException
{ {
new NonStrictExpectations() new NonStrictExpectations(AuthorizeManager.class)
{ {{
AuthorizeManager authManager; // Allow Bitstream READ perms
{ AuthorizeManager.authorizeAction((Context) any, (Bitstream) any,
AuthorizeManager.authorizeAction((Context) any, (Bitstream) any, Constants.READ); result = null;
Constants.READ); result = null; }};
}
};
assertThat("testRetrieveCanRead 0", bs.retrieve(), notNullValue()); assertThat("testRetrieveCanRead 0", bs.retrieve(), notNullValue());
} }
@@ -447,14 +436,12 @@ public class BitstreamTest extends AbstractDSpaceObjectTest
public void testRetrieveNoRead() throws IOException, SQLException, public void testRetrieveNoRead() throws IOException, SQLException,
AuthorizeException AuthorizeException
{ {
new NonStrictExpectations() new NonStrictExpectations(AuthorizeManager.class)
{ {{
AuthorizeManager authManager; // Disallow Bitstream READ perms
{ AuthorizeManager.authorizeAction((Context) any, (Bitstream) any,
AuthorizeManager.authorizeAction((Context) any, (Bitstream) any, Constants.READ); result = new AuthorizeException();
Constants.READ); result = new AuthorizeException(); }};
}
};
assertThat("testRetrieveNoRead 0", bs.retrieve(), notNullValue()); assertThat("testRetrieveNoRead 0", bs.retrieve(), notNullValue());
} }