Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @InjectMocks
- //@Mock
- private Bicycle bicycle;
- @Mock
- private BicycleDB db;
- @Test
- public void testDBTest() {
- System.out.println("DB test");
- MockitoAnnotations.initMocks(this);
- Bicycle.setBdb(db);
- bicycle.setType(2);
- bicycle.setAvailable("y");
- bicycle.setWeigth(10.5);
- bicycle.setEmail("[email protected]");
- boolean exception = false;
- try {
- exception = false;
- bicycle.saveBicycle();
- fail("There should have been an exception");
- } catch (IndexOutOfBoundsException ex) {
- exception = true;
- }
- assertTrue(exception);
- System.out.println("Test savve-add");
- Mockito.doThrow(new IllegalArgumentException()).when(db).updateBicycle(bicycle);
- //ensure method add is called
- Mockito.doThrow(new IndexOutOfBoundsException("test")).when(db).addBicycle(bicycle);
- try {
- exception = false;
- bicycle.saveBicycle();
- fail("There should have been an exception");
- } catch (IndexOutOfBoundsException ex) {
- exception = true;
- }
- assertTrue(exception);
- Mockito.doNothing().when(db).addBicycle(bicycle);
- bicycle.saveBicycle();
- assertTrue(true);
- when(db.getBicycle(1)).thenReturn(bicycle);
- assertTrue(Bicycle.getBicycle(1).equals(bicycle));
- System.out.println("Test remove");
- Mockito.doThrow(new IllegalArgumentException()).when(db).removeBicycle(1);
- //ensure method call
- try {
- Bicycle.removeBicycle(1);
- fail("There should have been an exception");
- } catch (Exception ex) {
- exception = true;
- }
- assertTrue(exception);
- Mockito.doNothing().when(db).removeBicycle(1);
- Bicycle.removeBicycle(1);
- assertTrue(true);
- System.out.println("Test save");
- System.out.println("Test save-update");
- Mockito.doThrow(new IndexOutOfBoundsException("test"))
- .when(db).updateBicycle(bicycle);
- }
Advertisement
Add Comment
Please, Sign In to add comment