Skip to content

Instantly share code, notes, and snippets.

@khannedy
Created September 2, 2013 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khannedy/6412381 to your computer and use it in GitHub Desktop.
Save khannedy/6412381 to your computer and use it in GitHub Desktop.
UNIT TEST getLastName Helper
package com.wordpress.eecchhoo.javaholic.helper;
import org.junit.Assert;
import org.junit.Test;
/**
* @author Eko Khannedy
*/
public class NameHelperTest {
@Test
public void testGetLastNameValid() throws Exception {
// test data valid
String fullName = "Eko Khannedy";
String lastName = NameHelper.getLastName(fullName);
// last name harus Khannedy
Assert.assertEquals("Khannedy", lastName);
}
@Test
public void testGetLastNameOnlyOneWord() throws Exception {
// test satu kata
String fullName = "Eko";
String lastName = NameHelper.getLastName(fullName);
// last name harus NULL
Assert.assertNull(lastName);
}
@Test
public void testGetLastNameNull() throws Exception {
// test NULL
String fullName = null;
String lastName = NameHelper.getLastName(fullName);
// last name harus null
Assert.assertNull(lastName);
}
@Test
public void testGetLastNameMoreThan2Words() throws Exception {
// test satu kata
String fullName = "Eko Kurniawan Khannedy";
String lastName = NameHelper.getLastName(fullName);
// last name harus Khannedy
Assert.assertEquals("Khannedy", lastName);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment