@Test public void shouldSayValidWhenRootHasCompoundP3sg() { final Root root = Mockito.mock(Root.class); final TurkishSequence rootSequence = new TurkishSequence("abc"); final Lexeme lexeme = mock(Lexeme.class); when(root.getSequence()).thenReturn(rootSequence); when(root.getLexeme()).thenReturn(lexeme); when(lexeme.getAttributes()).thenReturn(Sets.newHashSet(LexemeAttribute.CompoundP3sg)); { final TurkishSequence partialSurface = new TurkishSequence("abd"); assertThat(rootValidator.isValid(root, partialSurface), equalTo(true)); } { final TurkishSequence partialSurface = new TurkishSequence("abde"); assertThat(rootValidator.isValid(root, partialSurface), equalTo(true)); } { final TurkishSequence partialSurface = new TurkishSequence("Abd"); assertThat(rootValidator.isValid(root, partialSurface), equalTo(true)); } { final TurkishSequence partialSurface = new TurkishSequence("Abde"); assertThat(rootValidator.isValid(root, partialSurface), equalTo(true)); } }
public boolean isValid(Root root, TurkishSequence partialSurface) { Validate.notNull(root, "Root to validate cannot be null."); Validate.notNull(partialSurface, "Partial surface for the root cannot be null"); final TurkishSequence rootSequence = root.getSequence(); if (rootSequence.length() > partialSurface.length()) return false; if (root.getLexeme().getAttributes().contains(LexemeAttribute.CompoundP3sg)) return true; return partialSurface.startsWith(rootSequence) || partialSurface.getUnderlyingString().toLowerCase(Constants.TURKISH_LOCALE).startsWith(rootSequence.getUnderlyingString().toLowerCase(Constants.TURKISH_LOCALE)); }
RootValidator { public boolean isValid(Root root, TurkishSequence partialSurface) { Validate.notNull(root, "Root to validate cannot be null."); Validate.notNull(partialSurface, "Partial surface for the root cannot be null"); final TurkishSequence rootSequence = root.getSequence(); if (rootSequence.length() > partialSurface.length()) return false; if (root.getLexeme().getAttributes().contains(LexemeAttribute.CompoundP3sg)) return true; return partialSurface.startsWith(rootSequence) || partialSurface.getUnderlyingString().toLowerCase(Constants.TURKISH_LOCALE).startsWith(rootSequence.getUnderlyingString().toLowerCase(Constants.TURKISH_LOCALE)); } }
RootValidator { public boolean isValid(Root root, TurkishSequence partialSurface) { Validate.notNull(root, "Root to validate cannot be null."); Validate.notNull(partialSurface, "Partial surface for the root cannot be null"); final TurkishSequence rootSequence = root.getSequence(); if (rootSequence.length() > partialSurface.length()) return false; if (root.getLexeme().getAttributes().contains(LexemeAttribute.CompoundP3sg)) return true; return partialSurface.startsWith(rootSequence) || partialSurface.getUnderlyingString().toLowerCase(Constants.TURKISH_LOCALE).startsWith(rootSequence.getUnderlyingString().toLowerCase(Constants.TURKISH_LOCALE)); }  }
RootValidator { public boolean isValid(Root root, TurkishSequence partialSurface) { Validate.notNull(root, "Root to validate cannot be null."); Validate.notNull(partialSurface, "Partial surface for the root cannot be null"); final TurkishSequence rootSequence = root.getSequence(); if (rootSequence.length() > partialSurface.length()) return false; if (root.getLexeme().getAttributes().contains(LexemeAttribute.CompoundP3sg)) return true; return partialSurface.startsWith(rootSequence) || partialSurface.getUnderlyingString().toLowerCase(Constants.TURKISH_LOCALE).startsWith(rootSequence.getUnderlyingString().toLowerCase(Constants.TURKISH_LOCALE)); }  boolean isValid(Root root, TurkishSequence partialSurface); }
RootValidator { public boolean isValid(Root root, TurkishSequence partialSurface) { Validate.notNull(root, "Root to validate cannot be null."); Validate.notNull(partialSurface, "Partial surface for the root cannot be null"); final TurkishSequence rootSequence = root.getSequence(); if (rootSequence.length() > partialSurface.length()) return false; if (root.getLexeme().getAttributes().contains(LexemeAttribute.CompoundP3sg)) return true; return partialSurface.startsWith(rootSequence) || partialSurface.getUnderlyingString().toLowerCase(Constants.TURKISH_LOCALE).startsWith(rootSequence.getUnderlyingString().toLowerCase(Constants.TURKISH_LOCALE)); }  boolean isValid(Root root, TurkishSequence partialSurface);  }