samedi 10 septembre 2016

passing null to a method not working [duplicate]

This question already has an answer here:

I am trying to pass a null to a method hoping it would throw IllegalArgumentException error but instead method is taking that null as String. What am I doing wrong?

Below is the Test Method:

@Test
    public void verifyExceptionForNameIsNull(){
        Greeting myGreeting = new GreetingImpl();
        myGreeting.greeting(null);

Out put of the method is "Hello null".

Below is the class where method is defined:

public class GreetingImpl implements Greeting {

    @Override
    public String greeting(String name) {

        return "Hello "+name;
    }

}

Aucun commentaire:

Enregistrer un commentaire