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