I am doing a Junit test and in one of the tests I have problems but I don't understand why.
You do not have to allow more objects to be added to the list at any given time, that the size of the list is greater than 5, in short, if I add the sixth object to the list, the exception must be skipped, but I do not understand the reason why It does not work, I leave the code of what I am doing.
Code:
@Test
void testAddTank() throws KeeperException, TankException {
List<Tank> NumTanques = new ArrayList<Tank>();
Tank tank1 = new Tank("TANQUE1","pedro1","hola",3.0,2.0,1.0,"/image",17.0,7);
Tank tank2 = new Tank("TANQUE2","pedro2","hola",3.0,2.0,1.0,"/image",17.0,7);
Tank tank3 = new Tank("TANQUE3","pedro3","hola",3.0,2.0,1.0,"/image",17.0,7);
Tank tank4 = new Tank("TANQUE4","pedro4","hola",3.0,2.0,1.0,"/image",17.0,7);
Tank tank5 = new Tank("TANQUE5","pedro5","hola",3.0,2.0,1.0,"/image",17.0,7);
Tank tank6 = new Tank("TANQUE6","pedro6","hola",3.0,2.0,1.0,"/image",17.0,7);
Tank tank7 = new Tank("TANQUE7","pedro6","hola",3.0,2.0,1.0,"/image",17.0,7);
NumTanques.add(tank1);
NumTanques.add(tank2);
NumTanques.add(tank3);
NumTanques.add(tank4);
NumTanques.add(tank5);
assertEquals(5, NumTanques.size());
KeeperException excepcionTanques = assertThrows(KeeperException.class,()->NumTanques.add(tank6));
assertEquals("[ERROR] A keeper cannot care of more than 5
thanks!!",excepcionTanques.MSG_ERR_MAX_TANKS);
}
As you can see, I create the list of type tank and create some tank objects, which I add to the list. Then with the assert what I tell you is that 5 has to be the size of the list so that it returns true ...
Then in the exception that I create I add a new tank to the list and the exception should jump, but it does not, it exits and gives an error on the line:
KeeperException excepcionTanques = assertThrows(KeeperException.class,()->NumTanques.add(tank6));
I do not see clearly what is happening.