lundi 22 juillet 2019

How to test a constructor will throw an illegal state exception?

I have a utility class with a private constructor that throws an Illegal state exception and I want to test that it does this.

I've tried a test where I implement the constructor, but since the constructor is private it can't be accessed outside of the class. So is it just pointless to test the constructor?

from the class

 private UtilityClass(){
        throw new IllegalStateException("Utility Class");
    }

from the test class

private UtilityClass = utilityClass;
    @Test(expected = IllegalStateException.class)
    public void constructorTest(){
        utilityClass = new UtilityClass();
    }

Aucun commentaire:

Enregistrer un commentaire