mardi 25 juillet 2017

Junit test function which returns a string

I have a function inside a class :

public String covertToLowerCase(String sliceName) {
        sliceName = sliceName.trim().toLowerCase();
        sliceName = sliceName.replaceAll("\\.txt$|\\.dat$", "");
        return sliceName;
    }

I want to test this using Junit. I have created a separate test file which has the following:

  public class MyControllerTest {

  private MyController myController;
  private static final String SLICE_NAME = "Hello World";

  @Test
  public void shouldReturnSanitizedString() throws Exception {
  String expected = myController.covertToLowerCase(SLICE_NAME);
  // assert that actual and expected are same
  }

I am not able to understand how to test this and all the other examples are specific to their functions. I just want the function to return a sanitized string? How can I go about this?

Aucun commentaire:

Enregistrer un commentaire