PreDeployMojo extends AbstractDeployMojo { static int getNthIndexFromBack(String string, String searchString, int countFromBack) { if (countFromBack <= 0) return -1; int idx = string.length(); for (int i = 0; i < countFromBack; i++) { idx = string.substring(0, idx).lastIndexOf(searchString); if (idx <= 0) return idx; } return idx; }  @Override void execute();  }
@Test public void testGetNthIndexFromBack_OtaHtm() { assertEquals(29, getNthIndexFromBack( "MyApp-1.0.0-20120821.132955-1-Release-iphoneos-ota.htm", "-", 3)); }
@Test public void testGetNthIndexFromBack_MultiCharSearch() { assertEquals(4, getNthIndexFromBack("A:-B:-C:-D", ":-", 2)); }
@Test(expected = NullPointerException.class) public void testGetNthIndexFromBack_Null() { getNthIndexFromBack(null, "-", 1); }
@Test public void testGetNthIndexFromBack_Empty() { assertEquals(-1, getNthIndexFromBack("", "-", 1)); }
@Test public void testGetNthIndexFromBack_nEquals0() { assertEquals(-1, getNthIndexFromBack("a-b-c", "-", 0)); }