Command { public static String getCoordinates(String s) { if (!TextUtils.isEmpty(s)) { s = s.trim(); if (s.startsWith(Command.sCmdMove)) { s = s.substring(Command.sCmdMove.length()); if (Command.sCoordPattern.matcher(s).matches()) { return s; } } } return null; }  static String getCoordinates(String s); static final String sCmdMove; }
@Test public void testMoveCommand() throws Exception { HashMap<String, Boolean> testCases = new HashMap<String, Boolean>(); testCases.put("move 1", false); testCases.put("move 1,1", true); testCases.put("move 1,1", false); testCases.put("move 1,1,1", false); testCases.put("move 1,1,1,1", true); testCases.put("move 1,a,1,1", false); testCases.put(" move 1,1,1,1,1,1 ", true); testCases.put("", false); testCases.put(null, false); testCases.put("test", false); for (String key : testCases.keySet()) { boolean res = Command.getCoordinates(key) != null; assertThat(res).isEqualTo(testCases.get(key)); } }