0

Hi i'm new to programming and i started doing unit testing.I have problem with NullPointerException. I think something is broken in my InteliJ when i update it.My teachers type same code but their tests are passing.Here is what i should Test:

 @Before
public void SetUp() {
   this.motorcycle= new UnitMotorcycle("Nissan", 70, 120);
}

@Test(expected = NullPointerException.class)
public void testShouldThrowNullException() {
    UnitRider unitRider = new UnitRider(null, motorcycle);
}
@Test(expected = NullPointerException.class)
public void testNameShouldBeNull() {
    UnitRider unitRider = new UnitRider(null, motorcycle);
    assertNull(unitRider.getName());
}
@Test(expected = NullPointerException.class)
public void testNameAndMotorShouldBeNull() {
    UnitRider unitRider = new UnitRider("", null);
    assertEquals("",unitRider.getName());
}

Here is the method i am testing:

 public String addRider(UnitRider rider) {
    if (rider == null) {
        throw new NullPointerException(RIDER_INVALID);
    }

And my testing is failing and give me NullPointerException is expected. Like i did what my teacher.And I think it was from update and i preinstall with diffrent versions of inteliJ but still dont't working.I'm using Java 11, Junit 4.12 and Maven 11

  • 2
    I don't see a test that calls `addRider`. – Ted Hopp Aug 14 '20 at 21:44
  • 2
    Please read: [How to debug small programs](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/) --- I highly doubt that IntelliJj is the root cause. IntelliJ ist just an IDE. One could do everything without an IDE. – Turing85 Aug 14 '20 at 21:44
  • @Turing85 and Ted Hopp thank you so much!!!! After debugging 3 hours and with your help i figured out the problem. NullPointerException don't works with newly created object so i should modify it with method to be null.Sorry for don't know how to up your comments :( and again thank you very much. – Svetoslav Kostov Aug 14 '20 at 23:44
  • @TedHopp ////////////// – Svetoslav Kostov Aug 14 '20 at 23:45

0 Answers0