Results 1 to 6 of 6
- 07-25-2013, 09:08 PM #1
Member
- Join Date
- Jul 2013
- Posts
- 12
- Rep Power
- 0
Problems with JUnit test in a program
Hi guys! I'm new here and I already have a question to ask to you :)
So, my java program is about flight management and one of the methods I have to implement is about delays of flights.
It just asks me to check if the delay of the flight is bigger than 15 minutes and if that's the case, to add the flight code into a list.
Java Code:private List<String> flightsDelayed = new LinkedList<String>(); public void flightDeparted(String cod, int delay) throws InvalidCode { if (flights.containsKey(cod)){ if (delay>15) flightsDelayed.add(cod); } throw new InvalidCode(); public List<String> departureDelays() { Collections.sort(flightsDelayed); return flightsDelayed; } }
Now.. I have some JUnit tests that I can run on my program and one of them is actually adding two flights with delays bigger than 15, but when it checks the size of the list is not giving to it the right size of the list and I really don't understand what I'm doing wrong!
You guys have any idea?
Thanks in advance
- 07-25-2013, 09:36 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
Re: Problems with JUnit test in a program
Your flightDeparted( ... ) method always throws an InvalidCode exception; was that your intention?
kind regards,
JosBuild a wall around Donald Trump; I'll pay for it.
- 07-25-2013, 09:39 PM #3
Member
- Join Date
- Jul 2013
- Posts
- 12
- Rep Power
- 0
Re: Problems with JUnit test in a program
Oh i forgot to say that I have all the flights listed in a Map so I check if che code of the flight (key of the map) is present in the map and if that's the case I go further in checking the delay.
And yes, there is a " } " after the exception is thrown
- 07-25-2013, 09:41 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
Re: Problems with JUnit test in a program
But that method always throws that exception, no matter what; was that your intention?
kind regards,
JosBuild a wall around Donald Trump; I'll pay for it.
- 07-25-2013, 09:47 PM #5
Member
- Join Date
- Jul 2013
- Posts
- 12
- Rep Power
- 0
Re: Problems with JUnit test in a program
oh god, you're so right!
why so? How can I do that the method will throw that exception only when a code that is not contained in the map is passed as parameter?
- 07-25-2013, 09:50 PM #6
Member
- Join Date
- Jul 2013
- Posts
- 12
- Rep Power
- 0
Similar Threads
-
JUnit test and ArrayIndexOutOfBoundsException
By Hazza in forum New To JavaReplies: 17Last Post: 02-22-2013, 03:21 PM -
JUnit test - comparison problems.
By prabhdsun in forum New To JavaReplies: 5Last Post: 12-12-2012, 11:15 AM -
JUnit Test??? What is it all about????? Please help!!
By nikosa in forum New To JavaReplies: 1Last Post: 08-03-2009, 06:31 PM -
JUnit Test Help!
By pharo in forum New To JavaReplies: 0Last Post: 04-10-2009, 06:15 PM -
Junit test
By alice in forum New To JavaReplies: 1Last Post: 06-14-2008, 02:24 AM
Bookmarks