lots of exercises in java... from https://github.com/exercism/java

RobotTest.java 1015B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import org.junit.Test;
  2. import org.junit.Ignore;
  3. import static org.hamcrest.CoreMatchers.equalTo;
  4. import static org.hamcrest.core.Is.is;
  5. import static org.hamcrest.core.IsNot.not;
  6. import static org.junit.Assert.assertThat;
  7. public class RobotTest {
  8. private static final String EXPECTED_ROBOT_NAME_PATTERN = "[A-Z]{2}\\d{3}";
  9. private final Robot robot = new Robot();
  10. @Test
  11. public void hasName() {
  12. assertIsValidName(robot.getName());
  13. }
  14. @Ignore
  15. @Test
  16. public void differentRobotsHaveDifferentNames() {
  17. assertThat(robot.getName(), not(equalTo(new Robot().getName())));
  18. }
  19. @Ignore
  20. @Test
  21. public void resetName() {
  22. final String name = robot.getName();
  23. robot.reset();
  24. final String name2 = robot.getName();
  25. assertThat(name, not(equalTo(name2)));
  26. assertIsValidName(name2);
  27. }
  28. private static void assertIsValidName(String name) {
  29. assertThat(name.matches(EXPECTED_ROBOT_NAME_PATTERN), is(true));
  30. }
  31. }