vendredi 13 avril 2018

Java - How to test the non-abstract methods of an abstract class?

I have an abstract class that features no abstract methods... How would one go about testing this? Can I simply import it into a test class and go about business as usual?

Example:

public abstract class SomeAbstractClass implements SomeOtherClass {

    // Some variables defined here
    private static final String dbUrl = System.getProperty("db.url");

    // Some public methods
    public String doSomethingToUrl(String url) {
        url = url + "/takeMeSomewhereNice";
    }

}

Say I pass in an arg for db.url of localhost:8080, and I wanted to test that the doSomethingToUrl method did output the new string... Would it still be in this format?

public class TestUrl {

    SomeAbstractClass sac = new SomeAbstractClass();

    @Test
    public void testUrlChange() throws Exception {

        String testUrl = "localhost:8080";

        assertThat("localhost:8080/takeMeSomewhereNice", 
            sac.doSomethingToUrl(testUrl));
    }
}

Aucun commentaire:

Enregistrer un commentaire