@Test
public void testMatch() throws TalismaneException {

  final String separators = "[\\s\\p{Punct}]";
  final List<TokenPatternMatch> matches3 = new ArrayList<TokenPatternMatch>();
  final List<TokenPatternMatch> matches4 = new ArrayList<TokenPatternMatch>();
  final List<TokenPatternMatch> matches5 = new ArrayList<TokenPatternMatch>();
  final List<TokenPatternMatch> matches6 = new ArrayList<TokenPatternMatch>();
  final List<TokenPatternMatch> matches7 = new ArrayList<TokenPatternMatch>();
  final TokenSequence tokenSequence = mock(TokenSequence.class);
  final Token token0 = mock(Token.class);
  final Token token1 = mock(Token.class);
  final Token token2 = mock(Token.class);
  final Token token3 = mock(Token.class);
  final Token token4 = mock(Token.class);
  final Token token5 = mock(Token.class);
  final Token token6 = mock(Token.class);
  final Token token7 = mock(Token.class);
  
  final List<Token> listWithWhiteSpaces = Arrays.asList(token0, token1, token2, token3, token4, token5, token6, token7);
  
  when (tokenSequence.listWithWhiteSpace()).thenReturn(listWithWhiteSpaces);
 
  when (token0.getAnalyisText()).thenReturn("Moi");
  when (token0.isSeparator()).thenReturn(false);
  when (token0.getIndex()).thenReturn(0);
  when (token1.getAnalyisText()).thenReturn(",");
  when (token1.isSeparator()).thenReturn(true);
  when (token1.getIndex()).thenReturn(1);
  when (token2.getAnalyisText()).thenReturn(" ");
  when (token2.isSeparator()).thenReturn(true);
  when (token2.getIndex()).thenReturn(2);
  when (token3.getAnalyisText()).thenReturn("j");
  when (token3.isSeparator()).thenReturn(false);
  when (token3.getIndex()).thenReturn(3);
  when (token3.getMatches()).thenReturn(matches3);
  when (token4.getAnalyisText()).thenReturn("'");
  when (token4.isSeparator()).thenReturn(true);
  when (token4.getIndex()).thenReturn(4);
  when (token4.getMatches()).thenReturn(matches4);
  
  when (token5.getAnalyisText()).thenReturn("aim");
  when (token5.isSeparator()).thenReturn(false);
  when (token5.getIndex()).thenReturn(5);
  when (token5.getMatches()).thenReturn(matches5);
  
  when (token6.getAnalyisText()).thenReturn("'");
  when (token6.isSeparator()).thenReturn(true);
  when (token6.getIndex()).thenReturn(6);
  when (token6.getMatches()).thenReturn(matches6);
  
  when (token7.getAnalyisText()).thenReturn("rais");
  when (token7.isSeparator()).thenReturn(false);
  when (token7.getIndex()).thenReturn(7);
  when (token7.getMatches()).thenReturn(matches7);
  Pattern separatorPattern = Pattern.compile(separators, Pattern.UNICODE_CHARACTER_CLASS);
  TokenPattern tokeniserPatternImpl = new TokenPattern(".+'.+", separatorPattern);
  List<TokenPatternMatchSequence> patternMatches = tokeniserPatternImpl.match(tokenSequence);
  assertEquals(2, patternMatches.size());
  List<Token> patternMatch = patternMatches.get(0).getTokenSequence();
  assertEquals(3, patternMatch.size());
  for (int i = 0; i < 3; i++) {
    Token token = patternMatch.get(i);
    if (i == 0) {
      assertEquals(3, token.getIndex());
      assertEquals("j", token.getAnalyisText());
      assertEquals(1, token.getMatches().size());
      assertEquals(0, token.getMatches().get(0).getIndex());
    }
    if (i == 1) {
      assertEquals(4, token.getIndex());
      assertEquals("'", token.getAnalyisText());
      assertEquals(1, token.getMatches().size());
      assertEquals(1, token.getMatches().get(0).getIndex());
    }
    if (i == 2) {
      assertEquals(5, token.getIndex());
      assertEquals("aim", token.getAnalyisText());
      assertEquals(2, token.getMatches().size());
      assertEquals(2, token.getMatches().get(0).getIndex());
    }
  }
  patternMatch = patternMatches.get(1).getTokenSequence();
  assertEquals(3, patternMatch.size());
  for (int i = 0; i < 3; i++) {
    Token token = patternMatch.get(i);
    if (i == 0) {
      assertEquals(5, token.getIndex());
      assertEquals("aim", token.getAnalyisText());
      assertEquals(2, token.getMatches().size());
      assertEquals(0, token.getMatches().get(1).getIndex());
    }
    if (i == 1) {
      assertEquals(6, token.getIndex());
      assertEquals("'", token.getAnalyisText());
      assertEquals(1, token.getMatches().size());
      assertEquals(1, token.getMatches().get(0).getIndex());
    }
    if (i == 2) {
      assertEquals(7, token.getIndex());
      assertEquals("rais", token.getAnalyisText());
      assertEquals(1, token.getMatches().size());
      assertEquals(2, token.getMatches().get(0).getIndex());
    }
  }
}