Results 1 to 6 of 6

Thread: Using date and Junit

  1. #1
    Join Date
    Dec 2009
    Posts
    296

    Using date and Junit

    Hello,
    I know it must be a subject vessel, but I do not go out with the date in my JUnit Component. Here is the part of the code
    Code:
    assertEquals(contrat1.getDateConclusion(), Contrat2.getDateConclusion());
    And when compiling it returns an error to me. I try to remedy this by using SimpleDateFormat etc etc but Always the same error. Does any one have an idea of how to sort this problem.

  2. #2
    Join Date
    Nov 2009
    Posts
    583

    Re: Using date and Junit

    Hello,
    It seems that "contrat.getDateConclusion ()" returns a String you rather than date, or in your case the String 2 are representations in different formats, convert each String to Date in each using a different SimpleDateFormat (or so transform method "contrat.getDateConclusion ()" what you refer to a date rather than a String). I hope you are getting me, that is what I am trying to ask you. If you understand that then please correct your code likewise.

  3. #3
    Join Date
    Dec 2009
    Posts
    211

    Re: Using date and Junit

    Hello,
    Even I have a similar kind of a problem and I am working on it , but not sorted yet. This is what I have tried till now
    Code:
     
    Public class Contract{
            import java.util.Date;
     
            (...) 
     
    	Public Date gdtcl() {
    		return dtcon;
    	}
     
            (...)
    }
    If you have any idea of how to do this, then please do post back. And an example code will be appreciated.

  4. #4
    Join Date
    Dec 2009
    Posts
    296

    Re: Using date and Junit

    Hey
    This is my updated code, just check it and if you find any queries then please guide me
    Code:
    import org.hibernate.Session;
    import org.hibernate.SessionFactory;
    import java.text.DateFormat;
    import java.text.ParseException;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.List;
    (...)
     
    Public class ContratDaoImpl implements ContratDao{
    (...)
    	Public Contract getContratById(long i) {
    		CheckTool.CheckId(i);
        Session ses = HibernateUtil.getSessionFactory().getCurrentSession();
        Contract cont = (Contract) ses.load(Contract.class, Id);
    
    DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH: mm: SS.S");
    		try {
    		        cont.setDateConclusion((fmt.parse(cont.getDateConclusion().function toString() {
        [native code]
    }())));   
    		} catch (ParseException e) {
    			e.printStackTrace();
    		}
    		
        	        return cont;
    	}
    (...)
    }

  5. #5
    Join Date
    Nov 2009
    Posts
    347

    Re: Using date and Junit

    Hello,
    I have modified you code, just check whether it works for you. For me it works well , but needs may be different
    Code:
    Public Contract getContratById(long i) {
    		CheckTool.CheckId(i);
    Session se = HibernateUtil.getSessionFactory().getCurrentSession();
    Contract c = (Contract) se.load(Contract.class, Id);
    
    System.out.System.out.println("before" + Contract.getDateConclusion().
     
    		DateFormat f = new SimpleDateFormat("yyyy-MM-dd HH: mm: SS.S");
    		try {
    								c.setDateConclusion((f.parse(c.getDateConclusion().function toString() {
        [native code]
    }())));
    		} catch (ParseException e) {
    			e.printStackTrace();
    		}
    		
    		System.out.System.out.println("after" + Contract.getDateConclusion().getTime());
    		
    		return c;
    	}

  6. #6
    Join Date
    Nov 2009
    Posts
    446

    Re: Using date and Junit

    Hello,
    I think you should add the following in your code. Please include it and the see how the program runs.
    Code:
    long amil = new Date().getTime();
    
    long smil = ( amil / 1000 ) * 1000;
    Hope this will work for you.

Similar Threads

  1. Replies: 2
    Last Post: 29-11-2011, 09:29 AM
  2. Baseline Column Date automatically updates Finish Date
    By Adam 1980 in forum Microsoft Project
    Replies: 3
    Last Post: 18-05-2011, 06:08 PM
  3. Junit - mock static method
    By Parvati in forum Software Development
    Replies: 5
    Last Post: 11-08-2010, 05:06 PM
  4. BigDecimal and Date
    By Miles Runner in forum Software Development
    Replies: 5
    Last Post: 07-02-2010, 02:21 AM
  5. Changing start date and creating formula for finish date
    By stringse in forum Microsoft Project
    Replies: 1
    Last Post: 11-09-2006, 01:13 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,986,611.67425 seconds with 17 queries