Results 1 to 4 of 4
  1. #1
    EpyonCustom is offline Member
    Join Date
    Mar 2011
    Posts
    23
    Rep Power
    0

    Default JUNIT Error | Please Help

    Hello again Java Forums,

    I'm currently working on a JUNIT tester for my program, and while I feel I've done everything right, there's an error. Here's the JUNIT code:

    Java Code:
    package com.mybanking;
    
    import java.text.SimpleDateFormat;
    import org.junit.Before;
    import org.junit.Test;
    import static org.junit.Assert.*;
    
    
    public class HomeMortgageAccountTest {
    
        private HomeMortgageAccount hma;
    
    
        @Before
        public void setUp() throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
        hma = new HomeMortgageAccount(12392123, "Home Mortgage Account", 2000,
                                      1800.0, sdf.parse("04/28/2011"), 0.0032);
        }
    
    
        @Test
        public void paymentTest1() {
            System.out.println("$100 Payment");
            double expResult = 2000.0;
            hma.payment(100);
            assertTrue(hma.getBalance() == expResult);
        }
    
        
        @Test
        public void paymentTest2() {
            System.out.println("$80 Payment");
            double expResult = 2000.0;
            hma.payment(80);
            assertTrue(hma.getBalance() == expResult);
        }
    
        
    }

    The error is with this part:

    Java Code:
    hma = new HomeMortgageAccount(12392123, "Home Mortgage Account", 2000,
                                      1800.0, sdf.parse("04/28/2011"), 0.0032);

    The errors are:

    paymentTest1:
    java.lang.ExceptionInInitializerError
    at com.mybanking.HomeMortgageAccountTest.setUp(HomeMo rtgageAccountTest.java:17))

    paymentTest2:
    at com.mybanking.HomeMortgageAccountTest.setUp(HomeMo rtgageAccountTest.java:17))

    It also says: "Caused by: java.lang.RuntimeException: Uncompilable source code - com.mybanking.HomeMortgageAccount is not abstract and does not override abstract method payment(double) in com.mybanking.MortgageAccount"




    So that's my problem. Let me know if you need to see any of the classes from the program. I have to submit this assignment in a few hours, so any help would be much appreciated.
    Last edited by EpyonCustom; 04-28-2011 at 08:41 PM.

  2. #2
    f1gh is offline Member
    Join Date
    Nov 2010
    Posts
    46
    Rep Power
    0

    Default

    well basically from your error what i can deduce is that the class is extending an abstract class but does not implement the abstract method payment in the class MortgageAccount. If you don't want to implement this method in the class HomeMortgageAccount than declare that class as abstract.

  3. #3
    Maximus-EVG is offline Member
    Join Date
    Apr 2011
    Location
    Canada!
    Posts
    30
    Rep Power
    0

    Default

    Quote Originally Posted by EpyonCustom View Post

    @Test
    public void paymentTest1() {
    System.out.println("$100 Payment");
    double expResult = 2000.0;
    hma.payment(100);
    assertTrue(hma.getBalance() == expResult);
    }
    Hard to say anything about your errors without seeing/being able to run the program myself, but you got another error above.

    Doubles and floats are NOT compared using == because of their inherent inaccuracy.
    They are compared using double1.equals(double2).
    Or in JUnit you test them as follows:
    assertEquals(double expected, double actual, double delta)
    Asserts that two doubles are equal concerning a delta.

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

    Default

    @acmohan: please don't hijack someone else's thread; I noticed that you've started your own thread also, please stick to that one.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. JUnit
    By cka in forum Eclipse
    Replies: 3
    Last Post: 07-27-2010, 04:14 PM
  2. Error - "The import org.junit cannot be resolved"
    By Jessaurum in forum New To Java
    Replies: 7
    Last Post: 11-03-2009, 03:20 AM
  3. Replies: 0
    Last Post: 06-26-2009, 07:40 AM
  4. Junit
    By Azndaddy in forum New To Java
    Replies: 6
    Last Post: 06-15-2008, 06:47 AM
  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
  •