Results 1 to 6 of 6
  1. #1
    pokadean is offline Member
    Join Date
    Jul 2013
    Posts
    12
    Rep Power
    0

    Default 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;
    	}	
    
    	}
    So I'm kinda thinking I did it right.. I removed other parts that were concerning other classes and other methods but this is what i came up with.
    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

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,309
    Blog Entries
    7
    Rep Power
    20

    Default Re: Problems with JUnit test in a program

    Your flightDeparted( ... ) method always throws an InvalidCode exception; was that your intention?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    pokadean is offline Member
    Join Date
    Jul 2013
    Posts
    12
    Rep Power
    0

    Default 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

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,309
    Blog Entries
    7
    Rep Power
    20

    Default Re: Problems with JUnit test in a program

    But that method always throws that exception, no matter what; was that your intention?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    pokadean is offline Member
    Join Date
    Jul 2013
    Posts
    12
    Rep Power
    0

    Default 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?

  6. #6
    pokadean is offline Member
    Join Date
    Jul 2013
    Posts
    12
    Rep Power
    0

    Default Re: Problems with JUnit test in a program

    Ok! I got it! I put an else before the throw exception!

Similar Threads

  1. JUnit test and ArrayIndexOutOfBoundsException
    By Hazza in forum New To Java
    Replies: 17
    Last Post: 02-22-2013, 02:21 PM
  2. JUnit test - comparison problems.
    By prabhdsun in forum New To Java
    Replies: 5
    Last Post: 12-12-2012, 10:15 AM
  3. Replies: 1
    Last Post: 08-03-2009, 05:31 PM
  4. JUnit Test Help!
    By pharo in forum New To Java
    Replies: 0
    Last Post: 04-10-2009, 05:15 PM
  5. Junit test
    By alice in forum New To Java
    Replies: 1
    Last Post: 06-14-2008, 01:24 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •