src_fm_fc_ms_ff
stringlengths
43
86.8k
target
stringlengths
20
276k
ByElementKindMatcher implements CriteriaMatcher<Element, ElementKind> { @Override public boolean checkForMatchingCharacteristic(Element element, ElementKind toCheckFor) { return (element != null && toCheckFor != null) && element.getKind().equals(toCheckFor); } @Override boolean checkForMatchingCharacteristic(Element e...
@Test public void test_checkForMatchingCharacteristic_match() { Element element = Mockito.mock(Element.class); Mockito.when(element.getKind()).thenReturn(ElementKind.CLASS); MatcherAssert.assertThat("Should find match correctly", unit.checkForMatchingCharacteristic(element, ElementKind.CLASS)); } @Test public void test...
HasPublicNoargConstructorMatcher implements ImplicitMatcher<Element> { @Override public boolean check(Element element) { if (element == null) { return false; } TypeElement typeElement = TypeUtils.TypeRetrieval.getTypeElement(element.asType()); if (typeElement == null) { return false; } FluentElementFilter<ExecutableEle...
@Test public void checkDefaultConstructor() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { TypeElement typeElement = TypeUtils.TypeRetrieval.getTypeElement(DefaultNoargConstructor.class); MatcherAssert.assertThat("Must return true...
ByReturnTypeFqnMatcher implements CriteriaMatcher<ExecutableElement, String> { @Override public boolean checkForMatchingCharacteristic(ExecutableElement element, String toCheckFor) { if (element == null || toCheckFor == null) { return false; } return TypeUtils.TypeComparison.isTypeEqual(element.getReturnType(), TypeUti...
@Test public void byReturnTypeMirrorMatcher_match() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { List<? extends Element> result = ElementUtils.AccessEnclosedElements.getEnclosedElementsByName(element, "methodWithReturnTypeAndPar...
ByReturnTypeFqnMatcher implements CriteriaMatcher<ExecutableElement, String> { @Override public String getStringRepresentationOfPassedCharacteristic(String toGetStringRepresentationFor) { return toGetStringRepresentationFor != null ? toGetStringRepresentationFor : ""; } ByReturnTypeFqnMatcher(); @Override boolean check...
@Test public void getStringRepresentationOfPassedCharacteristic_nullValue() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { MatcherAssert.assertThat("Should not have found matching parameters", CoreMatchers.BY_RETURN_TYPE_FQN.getMa...
ByQualifiedNameMatcher implements CriteriaMatcher<Element, String> { @Override public String getStringRepresentationOfPassedCharacteristic(String toGetStringRepresentationFor) { return toGetStringRepresentationFor; } @Override boolean checkForMatchingCharacteristic(Element element, String toCheckFor); @Override String...
@Test public void test_getStringRepresentationOfPassedCharacteristic_happyPath() { MatcherAssert.assertThat("Should return enum name", unit.getStringRepresentationOfPassedCharacteristic(NAME).equals(NAME)); } @Test public void test_getStringRepresentationOfPassedCharacteristic_passedNullValue() { MatcherAssert.assertTh...
ByQualifiedNameMatcher implements CriteriaMatcher<Element, String> { @Override public boolean checkForMatchingCharacteristic(Element element, String toCheckFor) { if (element == null || toCheckFor == null) { return false; } switch (element.getKind()) { case ENUM: case INTERFACE: case ANNOTATION_TYPE: case CLASS: { Type...
@Test public void test_checkForMatchingCharacteristic_match_class() { TypeElement element = Mockito.mock(TypeElement.class); Name nameOfElement = Mockito.mock(Name.class); Mockito.when(nameOfElement.toString()).thenReturn(NAME); Mockito.when(element.getKind()).thenReturn(ElementKind.CLASS); Mockito.when(element.getQual...
SimpleResourceReader { public String readAsString() throws IOException { char[] buffer = new char[10000]; CharArrayWriter writer = new CharArrayWriter(); int line = 0; while ((line = foReader.read(buffer)) != -1) { writer.write(buffer, 0, line); } foReader.close(); writer.flush(); writer.close(); return writer.toString...
@Test public void testReadAsString() throws IOException { final String RESOURCE_STRING = "abc\ndef\nhij"; FileObject fileObject = Mockito.mock(FileObject.class); StringReader stringReader = Mockito.spy(new StringReader(RESOURCE_STRING)); Mockito.when(fileObject.openReader(Mockito.anyBoolean())).thenReturn(stringReader)...
IsConstructorMatcher implements ImplicitMatcher<ELEMENT> { @Override public boolean check(ELEMENT element) { return ElementUtils.CheckKindOfElement.isConstructor(element); } @Override boolean check(ELEMENT element); }
@Test public void checkMatchingConstructor() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { TypeElement typeElement = TypeUtils.TypeRetrieval.getTypeElement(IsConstructorMatcherTest.class); List<? extends Element> constructors = E...
IsAssignableToMatcher implements CriteriaMatcher<Element, Class> { @Override public boolean checkForMatchingCharacteristic(Element element, Class toCheckFor) { return element != null && toCheckFor != null && TypeUtils.getTypes() .isAssignable( element.asType(), TypeUtils.TypeRetrieval.getTypeMirror(toCheckFor.getCanoni...
@Test public void checkMatchingAssignableToCase() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { MatcherAssert.assertThat("Should return true for matching assignable to case : ", CoreMatchers.IS_ASSIGNABLE_TO.getMatcher().checkFor...
SimpleResourceReader { public List<String> readAsLines() throws IOException { return readAsLines(false); } SimpleResourceReader(FileObject fileObject); String readLine(); String readAsString(); List<String> readAsLines(); List<String> readAsLines(boolean trimLines); Properties readAsProperties(); void close(); }
@Test public void testReadAsLines() throws IOException { final String RESOURCE_STRING = "abc\ndef\nhij"; FileObject fileObject = Mockito.mock(FileObject.class); StringReader stringReader = Mockito.spy(new StringReader(RESOURCE_STRING)); Mockito.when(fileObject.openReader(Mockito.anyBoolean())).thenReturn(stringReader);...
IsAssignableToMatcher implements CriteriaMatcher<Element, Class> { @Override public String getStringRepresentationOfPassedCharacteristic(Class toGetStringRepresentationFor) { return toGetStringRepresentationFor != null ? toGetStringRepresentationFor.getCanonicalName() : null; } @Override String getStringRepresentation...
@Test public void getStringRepresentationOfPassedCharacteristic_nullValue() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { MatcherAssert.assertThat("Should not have found matching parameters", CoreMatchers.IS_ASSIGNABLE_TO.getMatc...
HasNoThrownTypesMatcher implements ImplicitMatcher<ExecutableElement> { @Override public boolean check(ExecutableElement element) { return element != null && element.getThrownTypes().size() == 0; } @Override boolean check(ExecutableElement element); }
@Test public void test_check_withNullValue() { MatcherAssert.assertThat(CoreMatchers.HAS_NO_THROWN_TYPES.getMatcher().check(null), Matchers.is(false)); } @Test public void test_check_withoutThrownTypes() { ExecutableElement element = Mockito.mock(ExecutableElement.class); TypeMirror typeMirror = Mockito.mock(TypeMirror...
IsAttributeFieldMatcher implements ImplicitMatcher<VariableElement> { @Override public boolean check(VariableElement element) { if (element == null || element.getKind() != ElementKind.FIELD) { return false; } return BeanUtils.isAttribute(element); } @Override boolean check(VariableElement element); }
@Test public void test_isAttributeField_match__shouldReturnTrue() { CompileTestBuilder .unitTest() .useSource(JavaFileObjectUtils.readFromResource("/AnnotationProcessorUnitTestClassInternal.java")) .useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { Ma...
SimpleResourceReader { public Properties readAsProperties() throws IOException { Properties properties = new Properties(); try { properties.load(foReader); } finally { foReader.close(); } return properties; } SimpleResourceReader(FileObject fileObject); String readLine(); String readAsString(); List<String> readAsLines...
@Test public void testReadAsProperties() throws IOException { final String RESOURCE_STRING = "a=1\nb=2\nc=3"; FileObject fileObject = Mockito.mock(FileObject.class); StringReader stringReader = Mockito.spy(new StringReader(RESOURCE_STRING)); Mockito.when(fileObject.openReader(Mockito.anyBoolean())).thenReturn(stringRea...
HasVoidReturnTypeMatcher implements ImplicitMatcher<ExecutableElement> { @Override public boolean check(ExecutableElement element) { return element != null && TypeUtils.CheckTypeKind.isVoid(element.getReturnType()); } @Override boolean check(ExecutableElement element); }
@Test public void test_check_withNullValue() { MatcherAssert.assertThat(CoreMatchers.HAS_VOID_RETURN_TYPE.getMatcher().check(null), Matchers.is(false)); } @Test public void test_check_withVoidReturnType() { ExecutableElement element = Mockito.mock(ExecutableElement.class); TypeMirror typeMirror = Mockito.mock(TypeMirro...
ByNameRegexMatcher implements CriteriaMatcher<Element, String> { @Override public String getStringRepresentationOfPassedCharacteristic(String toGetStringRepresentationFor) { return toGetStringRepresentationFor; } @Override boolean checkForMatchingCharacteristic(Element element, String toCheckFor); @Override String get...
@Test public void test_getStringRepresentationOfPassedCharacteristic_happyPath() { MatcherAssert.assertThat("Should return enum name", unit.getStringRepresentationOfPassedCharacteristic(NAME).equals(NAME)); } @Test public void test_getStringRepresentationOfPassedCharacteristic_passedNullValue() { MatcherAssert.assertTh...
ByNameRegexMatcher implements CriteriaMatcher<Element, String> { @Override public boolean checkForMatchingCharacteristic(Element element, String toCheckFor) { if (element != null && toCheckFor != null) { Pattern pattern = Pattern.compile(toCheckFor); return pattern.matcher(element.getSimpleName().toString()).matches();...
@Test public void test_checkForMatchingCharacteristic_match() { Element element = Mockito.mock(Element.class); Name nameOfElement = Mockito.mock(Name.class); Mockito.when(nameOfElement.toString()).thenReturn(NAME); Mockito.when(element.getSimpleName()).thenReturn(nameOfElement); MatcherAssert.assertThat("Should find ma...
ImplicitFilter { public List<ELEMENT> filter(List<ELEMENT> toFilter) { return filter(toFilter, false); } ImplicitFilter(VALIDATOR validator); List<ELEMENT> filter(List<ELEMENT> toFilter); List<ELEMENT> filter(List<ELEMENT> toFilter, boolean invertFilter); }
@Test public void testImplicitFilter_allMatching() { ImplicitFilter<Element, ImplicitValidator<Element, ImplicitMatcher<Element>>> unit = new ImplicitFilter<Element, ImplicitValidator<Element, ImplicitMatcher<Element>>>(TestCoreMatcherFactory.createElementBasedImplicitCoreMatcher("XXX", true).getValidator()); List<Elem...
ByNumberOfParametersMatcher implements CriteriaMatcher<ExecutableElement, Integer> { @Override public boolean checkForMatchingCharacteristic(ExecutableElement element, Integer toCheckFor) { return (element != null && toCheckFor != null) && element.getParameters().size() == toCheckFor; } @Override boolean checkForMatch...
@Test public void byNumberOfParametersMatcher_methodWith0Parameters() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { TypeElement typeElement = TypeUtils.TypeRetrieval.getTypeElement(ByNumberOfParametersMatcherTest.class); MatcherA...
ByNumberOfParametersMatcher implements CriteriaMatcher<ExecutableElement, Integer> { @Override public String getStringRepresentationOfPassedCharacteristic(Integer toGetStringRepresentationFor) { return toGetStringRepresentationFor != null ? toGetStringRepresentationFor.toString() : null; } @Override boolean checkForMa...
@Test public void getStringRepresentationOfPassedCharacteristic_nullValue() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { MatcherAssert.assertThat("Should not have found matching parameters", CoreMatchers.BY_NUMBER_OF_PARAMETERS....
ByNameMatcher implements CriteriaMatcher<Element, String> { @Override public String getStringRepresentationOfPassedCharacteristic(String toGetStringRepresentationFor) { return toGetStringRepresentationFor; } @Override boolean checkForMatchingCharacteristic(Element element, String toCheckFor); @Override String getStrin...
@Test public void test_getStringRepresentationOfPassedCharacteristic_happyPath() { MatcherAssert.assertThat("Should return enum name", unit.getStringRepresentationOfPassedCharacteristic(NAME).equals(NAME)); } @Test public void test_getStringRepresentationOfPassedCharacteristic_passedNullValue() { MatcherAssert.assertTh...
ByNameMatcher implements CriteriaMatcher<Element, String> { @Override public boolean checkForMatchingCharacteristic(Element element, String toCheckFor) { return (element != null && toCheckFor != null) && element.getSimpleName().toString().equals(toCheckFor); } @Override boolean checkForMatchingCharacteristic(Element e...
@Test public void test_checkForMatchingCharacteristic_match() { Element element = Mockito.mock(Element.class); Name nameOfElement = Mockito.mock(Name.class); Mockito.when(nameOfElement.toString()).thenReturn(NAME); Mockito.when(element.getSimpleName()).thenReturn(nameOfElement); MatcherAssert.assertThat("Should find ma...
IsVariableElementMatcher implements ImplicitMatcher<ELEMENT> { @Override public boolean check(ELEMENT element) { return ElementUtils.CastElement.isVariableElement(element); } @Override boolean check(ELEMENT element); }
@Test public void checkMatchingVariableElement_field() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { List<? extends Element> result = ElementUtils.AccessEnclosedElements.getEnclosedElementsOfKind(TypeUtils.TypeRetrieval.getTypeEl...
ByQualifiedNameRegexMatcher implements CriteriaMatcher<Element, String> { @Override public String getStringRepresentationOfPassedCharacteristic(String toGetStringRepresentationFor) { return toGetStringRepresentationFor; } @Override boolean checkForMatchingCharacteristic(Element element, String toCheckFor); @Override S...
@Test public void test_getStringRepresentationOfPassedCharacteristic_happyPath() { MatcherAssert.assertThat("Should return enum name", unit.getStringRepresentationOfPassedCharacteristic(NAME).equals(NAME)); } @Test public void test_getStringRepresentationOfPassedCharacteristic_passedNullValue() { MatcherAssert.assertTh...
ByQualifiedNameRegexMatcher implements CriteriaMatcher<Element, String> { @Override public boolean checkForMatchingCharacteristic(Element element, String toCheckFor) { if (element != null && toCheckFor != null) { String name = null; switch (element.getKind()) { case ENUM: case INTERFACE: case ANNOTATION_TYPE: case CLAS...
@Test public void test_checkForMatchingCharacteristic_match_class() { TypeElement element = Mockito.mock(TypeElement.class); Name nameOfElement = Mockito.mock(Name.class); Mockito.when(nameOfElement.toString()).thenReturn(NAME); Mockito.when(element.getKind()).thenReturn(ElementKind.CLASS); Mockito.when(element.getQual...
ByRawTypeMatcher implements CriteriaMatcher<Element, Class> { @Override public String getStringRepresentationOfPassedCharacteristic(Class toGetStringRepresentationFor) { return toGetStringRepresentationFor != null ? toGetStringRepresentationFor.getCanonicalName() : null; } ByRawTypeMatcher(); @Override boolean checkFor...
@Test public void getStringRepresentationOfPassedCharacteristic_happyPath() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { MatcherAssert.assertThat("Should return cannonical class name of annotation class", CoreMatchers.BY_RAW_TYP...
ByRawTypeMatcher implements CriteriaMatcher<Element, Class> { @Override public boolean checkForMatchingCharacteristic(Element element, Class toCheckFor) { if (element == null || toCheckFor == null) { return false; } return TypeUtils.TypeComparison.isErasedTypeEqual(element.asType(), TypeUtils.TypeRetrieval.getTypeMirro...
@Test public void checkForMatchingCharacteristic_match() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { TypeElement tmpElement = TypeUtils.TypeRetrieval.getTypeElement(ByRawTypeMatcherTest.class); MatcherAssert.assertThat("Should ...
ByModifierMatcher implements CriteriaMatcher<Element, Modifier> { @Override public String getStringRepresentationOfPassedCharacteristic(Modifier toGetStringRepresentationFor) { return toGetStringRepresentationFor != null ? toGetStringRepresentationFor.name() : null; } @Override boolean checkForMatchingCharacteristic(E...
@Test public void test_getStringRepresentationOfPassedCharacteristic_happyPath() { MatcherAssert.assertThat("Should return enum name", unit.getStringRepresentationOfPassedCharacteristic(Modifier.FINAL).equals(Modifier.FINAL.name())); } @Test public void test_getStringRepresentationOfPassedCharacteristic_passedNullValue...
ByModifierMatcher implements CriteriaMatcher<Element, Modifier> { @Override public boolean checkForMatchingCharacteristic(Element element, Modifier toCheckFor) { return (element != null && toCheckFor != null) && element.getModifiers().contains(toCheckFor); } @Override boolean checkForMatchingCharacteristic(Element ele...
@Test public void test_checkForMatchingCharacteristic_match() { Element element = Mockito.mock(Element.class); Set<Modifier> modifierSet = new HashSet<Modifier>(); modifierSet.add(Modifier.FINAL); Mockito.when(element.getModifiers()).thenReturn(modifierSet); MatcherAssert.assertThat("Should find match correctly", unit....
CriteriaElementValidatorImpl { @SafeVarargs public final <ELEMENT extends Element, CRITERIA, MATCHER extends CriteriaMatcher<ELEMENT, CRITERIA>> boolean validateByValidatorKind(ValidatorKind validatorKind, MATCHER matcher, ELEMENT element, CRITERIA... criteriaToCheck) { if (validatorKind == null) { return false; } swit...
@Test public void validateByValidatorKind_null_safety_test() { TestCriteriaMatcher matcherSpy = Mockito.spy(SUCCEEDING_MATCHER); MatcherAssert.assertThat("Should return false if validator kind is null", !unit.validateByValidatorKind(null, matcherSpy, element, "TEST")); Mockito.verify(matcherSpy, Mockito.never()).checkF...
MessagerUtils { public static Messager getMessager() { return ProcessingEnvironmentUtils.getMessager(); } private MessagerUtils(); static void setPrintMessageCodes(final boolean printMessageCodes); static void error(Element e, String message, Object... args); static void warning(Element e, String message, Object... ar...
@Test public void testGetMessaggerUtils() { MatcherAssert.assertThat(unit.getMessager(), Matchers.is(messager)); }
MessagerUtils { public static String createMessage(String message, Object... messageParameters) { String result = message; if (messageParameters != null) { for (int i = 0; i < messageParameters.length; i++) { result = result.replaceAll("\\$\\{" + i + "\\}", messageParameters[i] != null ? messageParameters[i].toString()...
@Test public void createMessage_exactNumberOfParameters() { MatcherAssert.assertThat(MessagerUtils.createMessage("TEST ${0}, ${2}, ${1}", 1, "YES", true), Matchers.is("TEST 1, true, YES")); } @Test public void createMessage_smallerNumberOfParameters() { MatcherAssert.assertThat(MessagerUtils.createMessage("TEST ${0}, $...
MessagerUtils { protected static String argToString(Object arg){ if(arg == null) { return "<NULL>"; } else if (arg.getClass().isArray()) { StringBuilder stringBuilder = new StringBuilder("["); boolean first = true; for (Object argument : (Object[])arg) { if(first) { first = false; } else { stringBuilder.append(", "); }...
@Test public void argToString_nullValue() { MatcherAssert.assertThat(MessagerUtils.argToString(null), Matchers.is("<NULL>")); } @Test public void argToString_arrayValue() { String[] array = {"A", "B", "C"}; MatcherAssert.assertThat(MessagerUtils.argToString(array), Matchers.is("[A, B, C]")); } @Test public void argToSt...
MessagerUtils { public static void printMessage(Element e, Diagnostic.Kind kind, String message, Object... args) { printMessage(e, kind, PlainValidationMessage.create(message), args); } private MessagerUtils(); static void setPrintMessageCodes(final boolean printMessageCodes); static void error(Element e, String messa...
@Test public void printMessage_testStringBasedMessage() { unit.printMessage(element, Diagnostic.Kind.ERROR, MESSSAGE, MESSAGE_ARG_1, MESSAGE_ARG_2); Mockito.verify(messager).printMessage(Diagnostic.Kind.ERROR, MESSSAGE_STR_WITH_REPLACED_ARGUMENTS, element); } @Test public void printMessage_testStringBasedMessageWithAnn...
TypeUtils { public static Types getTypes() { return ProcessingEnvironmentUtils.getTypes(); } private TypeUtils(); static Types getTypes(); }
@Test public void typeUtils_typeRetrieval_getTypes_getEncapsulatedTypesInstance() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { MatcherAssert.assertThat(TypeUtils.getTypes(), Matchers.notNullValue()); } }) .compilationShouldSucce...
AnnotationValueUtils { public static boolean isLong(AnnotationValue annotationValue) { return hasAnnotationValueOneOfPassedTypes(annotationValue, Long.class); } private AnnotationValueUtils(); static boolean isInteger(AnnotationValue annotationValue); static boolean isLong(AnnotationValue annotationValue); static bool...
@Test public void annotationValueUtils_test_isLong() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotation.class); MatcherAsse...
AnnotationValueUtils { public static boolean isInteger(AnnotationValue annotationValue) { return hasAnnotationValueOneOfPassedTypes(annotationValue, Integer.class); } private AnnotationValueUtils(); static boolean isInteger(AnnotationValue annotationValue); static boolean isLong(AnnotationValue annotationValue); stati...
@Test public void annotationValueUtils_test_isInteger() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotation.class); MatcherA...
AnnotationValueUtils { public static boolean isFloat(AnnotationValue annotationValue) { return hasAnnotationValueOneOfPassedTypes(annotationValue, Float.class); } private AnnotationValueUtils(); static boolean isInteger(AnnotationValue annotationValue); static boolean isLong(AnnotationValue annotationValue); static bo...
@Test public void annotationValueUtils_test_isFloat() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotation.class); MatcherAss...
AnnotationValueUtils { public static boolean isDouble(AnnotationValue annotationValue) { return hasAnnotationValueOneOfPassedTypes(annotationValue, Double.class); } private AnnotationValueUtils(); static boolean isInteger(AnnotationValue annotationValue); static boolean isLong(AnnotationValue annotationValue); static ...
@Test public void annotationValueUtils_test_isDouble() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotation.class); MatcherAs...
AnnotationValueUtils { public static boolean isBoolean(AnnotationValue annotationValue) { return hasAnnotationValueOneOfPassedTypes(annotationValue, Boolean.class); } private AnnotationValueUtils(); static boolean isInteger(AnnotationValue annotationValue); static boolean isLong(AnnotationValue annotationValue); stati...
@Test public void annotationValueUtils_test_isBoolean() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotation.class); MatcherA...
AnnotationValueUtils { public static boolean isString(AnnotationValue annotationValue) { return hasAnnotationValueOneOfPassedTypes(annotationValue, String.class); } private AnnotationValueUtils(); static boolean isInteger(AnnotationValue annotationValue); static boolean isLong(AnnotationValue annotationValue); static ...
@Test public void annotationValueUtils_test_isString() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotation.class); MatcherAs...
AnnotationValueUtils { public static boolean isChar(AnnotationValue annotationValue) { return hasAnnotationValueOneOfPassedTypes(annotationValue, Character.class); } private AnnotationValueUtils(); static boolean isInteger(AnnotationValue annotationValue); static boolean isLong(AnnotationValue annotationValue); static...
@Test public void annotationValueUtils_test_isChar() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotation.class); MatcherAsse...
AnnotationValueUtils { public static boolean isEnum(AnnotationValue annotationValue) { return hasAnnotationValueOneOfPassedTypes(annotationValue, VariableElement.class); } private AnnotationValueUtils(); static boolean isInteger(AnnotationValue annotationValue); static boolean isLong(AnnotationValue annotationValue); ...
@Test public void annotationValueUtils_test_isEnum() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotation.class); MatcherAsse...
AnnotationValueUtils { public static boolean isClass(AnnotationValue annotationValue) { return hasAnnotationValueOneOfPassedTypes(annotationValue, TypeMirror.class); } private AnnotationValueUtils(); static boolean isInteger(AnnotationValue annotationValue); static boolean isLong(AnnotationValue annotationValue); stat...
@Test public void annotationValueUtils_test_isClass() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotation.class); MatcherAss...
AnnotationValueUtils { public static boolean isAnnotation(AnnotationValue annotationValue) { return hasAnnotationValueOneOfPassedTypes(annotationValue, AnnotationMirror.class); } private AnnotationValueUtils(); static boolean isInteger(AnnotationValue annotationValue); static boolean isLong(AnnotationValue annotationV...
@Test public void annotationValueUtils_test_isAnnotation() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotation.class); Match...
AnnotationValueUtils { public static boolean isArray(AnnotationValue annotationValue) { return hasAnnotationValueOneOfPassedTypes(annotationValue, List.class); } private AnnotationValueUtils(); static boolean isInteger(AnnotationValue annotationValue); static boolean isLong(AnnotationValue annotationValue); static boo...
@Test public void annotationValueUtils_test_isArray() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotation.class); MatcherAss...
AnnotationValueUtils { public static Long getLongValue(AnnotationValue annotationValue) { return !isLong(annotationValue) ? null : (Long) annotationValue.getValue(); } private AnnotationValueUtils(); static boolean isInteger(AnnotationValue annotationValue); static boolean isLong(AnnotationValue annotationValue); stat...
@Test public void annotationValueUtils_test_getLongValue() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotation.class); Match...
AnnotationValueUtils { public static Integer getIntegerValue(AnnotationValue annotationValue) { return !isInteger(annotationValue) ? null : (Integer) annotationValue.getValue(); } private AnnotationValueUtils(); static boolean isInteger(AnnotationValue annotationValue); static boolean isLong(AnnotationValue annotation...
@Test public void annotationValueUtils_test_getIntegerValue() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotation.class); Ma...
AnnotationValueUtils { public static Float getFloatValue(AnnotationValue annotationValue) { return !isFloat(annotationValue) ? null : (Float) annotationValue.getValue(); } private AnnotationValueUtils(); static boolean isInteger(AnnotationValue annotationValue); static boolean isLong(AnnotationValue annotationValue); ...
@Test public void annotationValueUtils_test_getFloatValue() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotation.class); Matc...
InclusiveCriteriaElementFilter { @SafeVarargs public final <PARAM_ELEMENT extends ELEMENT> List<PARAM_ELEMENT> filterByAllOf(List<PARAM_ELEMENT> elements, CRITERIA... criteriaToCheck) { return filterByAllOf(elements, false, criteriaToCheck); } InclusiveCriteriaElementFilter(VALIDATOR validator); @SafeVarargs final List...
@Test public void findByAll_happyPath() { CompileTestBuilder .unitTest() .useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { List<Element> filteredList = CoreMatchers.BY_MODIFIER.getFilter().filterByAllOf((List<Element>) element.getEnclosedElements(), ...
AnnotationValueUtils { public static Double getDoubleValue(AnnotationValue annotationValue) { return !isDouble(annotationValue) ? null : (Double) annotationValue.getValue(); } private AnnotationValueUtils(); static boolean isInteger(AnnotationValue annotationValue); static boolean isLong(AnnotationValue annotationValu...
@Test public void annotationValueUtils_test_getDoubleValue() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotation.class); Mat...
AnnotationValueUtils { public static Boolean getBooleanValue(AnnotationValue annotationValue) { return !isBoolean(annotationValue) ? null : (Boolean) annotationValue.getValue(); } private AnnotationValueUtils(); static boolean isInteger(AnnotationValue annotationValue); static boolean isLong(AnnotationValue annotation...
@Test public void annotationValueUtils_test_getBooleanValue() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotation.class); Ma...
AnnotationValueUtils { public static String getStringValue(AnnotationValue annotationValue) { return !isString(annotationValue) ? null : (String) annotationValue.getValue(); } private AnnotationValueUtils(); static boolean isInteger(AnnotationValue annotationValue); static boolean isLong(AnnotationValue annotationValu...
@Test public void annotationValueUtils_test_getStringValue() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotation.class); Mat...
AnnotationValueUtils { public static Character getCharValue(AnnotationValue annotationValue) { return !isChar(annotationValue) ? null : (Character) annotationValue.getValue(); } private AnnotationValueUtils(); static boolean isInteger(AnnotationValue annotationValue); static boolean isLong(AnnotationValue annotationVa...
@Test public void annotationValueUtils_test_getCharValue() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotation.class); Match...
AnnotationValueUtils { public static VariableElement getEnumValue(AnnotationValue annotationValue) { return !isEnum(annotationValue) ? null : (VariableElement) annotationValue.getValue(); } private AnnotationValueUtils(); static boolean isInteger(AnnotationValue annotationValue); static boolean isLong(AnnotationValue ...
@Test public void annotationValueUtils_test_getEnumValue() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotation.class); Match...
AnnotationValueUtils { public static AnnotationMirror getAnnotationValue(AnnotationValue annotationValue) { return !isAnnotation(annotationValue) ? null : (AnnotationMirror) annotationValue.getValue(); } private AnnotationValueUtils(); static boolean isInteger(AnnotationValue annotationValue); static boolean isLong(An...
@Test public void annotationValueUtils_test_getAnnotationValueOfAttribute() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { AnnotationMirror annotationMirror = AnnotationUtils.getAnnotationMirror(element, AnnotationValueTestAnnotat...
Utilities { public static <T> Set<T> convertArrayToSet(T[] array) { if (array == null) { return null; } Set<T> set = new HashSet<>(array.length); for (T element : array) { if (element != null) { set.add(element); } } return set; } private Utilities(); static Set<T> convertArrayToSet(T[] array); @SafeVarargs static Set...
@Test public void convertArrayToSet_nullValue() { MatcherAssert.assertThat(Utilities.convertArrayToSet(null), Matchers.nullValue()); } @Test public void convertArrayToSet_nonNullValue() { String[] array = {"A","B","C"}; MatcherAssert.assertThat(Utilities.convertArrayToSet(array), Matchers.containsInAnyOrder("A","B","C"...
Utilities { @SafeVarargs public static <T> Set<T> convertVarargsToSet(T... varargs) { return varargs != null ? new HashSet<>(Arrays.asList(varargs)) : new HashSet<T>(); } private Utilities(); static Set<T> convertArrayToSet(T[] array); @SafeVarargs static Set<T> convertVarargsToSet(T... varargs); @SafeVarargs static L...
@Test public void convertVarargsToSet_noValues_shouldReturnEmptySet() { MatcherAssert.assertThat(Utilities.convertVarargsToSet(), Matchers.empty()); } @Test public void convertVarargsToSet_singleNullValue_shouldReturnEmptySet() { MatcherAssert.assertThat(Utilities.convertVarargsToSet(null), Matchers.empty()); } @Test p...
BeanUtils { public static String getPrefixedName(String prefix, String name) { return prefix + name.substring(0, 1).toUpperCase() + name.substring(1); } private BeanUtils(); static boolean hasDefaultNoargsConstructor(TypeElement typeElement); static boolean isDefaultNoargConstructor(ExecutableElement element); static ...
@Test public void getPossibleGetterOrSetterNames_getter() { unitTestBuilder.useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { MatcherAssert.assertThat(Arrays.asList(BeanUtils.getPrefixedName("get", "testField")), Matchers.contains("getTestField")); } ...
Utilities { @SafeVarargs public static <T> List<T> convertVarargsToList(T... varargs) { return varargs != null ? Arrays.asList(varargs) : new ArrayList<T>(); } private Utilities(); static Set<T> convertArrayToSet(T[] array); @SafeVarargs static Set<T> convertVarargsToSet(T... varargs); @SafeVarargs static List<T> conv...
@Test public void convertVarargsToList_noValues_shouldReturnEmptySet() { MatcherAssert.assertThat(Utilities.convertVarargsToList(), Matchers.empty()); } @Test public void convertVarargsToList_singleNullValue_shouldReturnEmptySet() { MatcherAssert.assertThat(Utilities.convertVarargsToList(null), Matchers.empty()); } @Te...
Utilities { @SafeVarargs public static <T> T[] convertVarargsToArray(T... varargs) { final Object[] e = {}; if (varargs == null) { return (T[]) e; } return varargs; } private Utilities(); static Set<T> convertArrayToSet(T[] array); @SafeVarargs static Set<T> convertVarargsToSet(T... varargs); @SafeVarargs static List<...
@Test public void convertVarargsToArray_noValues_shouldReturnEmptySet() { MatcherAssert.assertThat(Arrays.asList(Utilities.convertVarargsToArray()), Matchers.empty()); } @Test public void convertVarargsToArray_singleNullValue_shouldReturnEmptyArrayg() { MatcherAssert.assertThat(Arrays.asList(Utilities.convertVarargsToA...
AbstractAnnotationProcessor extends AbstractProcessor { @SafeVarargs protected static Set<String> createSupportedAnnotationSet(Class<? extends Annotation>... annotationTypes) { Set<String> result = new HashSet<>(); if (annotationTypes != null) { for (Class<? extends Annotation> annotationType : annotationTypes) { if (a...
@Test public void createSupportedAnnotationSet_withoutParameters() { MatcherAssert.assertThat(AbstractAnnotationProcessor.createSupportedAnnotationSet(), Matchers.<String>empty()); } @Test public void createSupportedAnnotationSet_withParameters() { MatcherAssert.assertThat(AbstractAnnotationProcessor.createSupportedAnn...
BeanUtils { public static boolean checkHasGetter(VariableElement field) { if (field == null || field.getKind() != ElementKind.FIELD || CoreMatchers.BY_MODIFIER.getMatcher().checkForMatchingCharacteristic(field, Modifier.STATIC)) { return false; } TypeElement typeElement = ElementUtils.AccessEnclosingElements.<TypeEleme...
@Test public void fieldWithImplementedGetterAndSetters_checkHasGetter() { unitTestBuilder.useSource(JavaFileObjectUtils.readFromResource("testcases.beanutils/FieldLevelTestcases.java")) .useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { VariableElemen...
AbstractAnnotationProcessor extends AbstractProcessor { @SafeVarargs public static <T> T[] wrapToArray(T... element) { return element; } @Override synchronized void init(ProcessingEnvironment processingEnv); @Override final boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv); abstract bo...
@Test public void wrapToArrayt_withNullParameter() { MatcherAssert.assertThat("Should return null", AbstractAnnotationProcessor.wrapToArray((String) null)[0] == null); Class[] resultArray = AbstractAnnotationProcessor.wrapToArray(Override.class, null, Ignore.class); MatcherAssert.assertThat(Arrays.asList(resultArray), ...
ToolingProvider { public static void setTooling(ProcessingEnvironment processingEnvironment) { tooling.set(new ToolingProvider(processingEnvironment)); } ToolingProvider(ProcessingEnvironment processingEnv); static ToolingProvider getTooling(); static void setTooling(ProcessingEnvironment processingEnvironment); static...
@Test(expected = IllegalArgumentException.class) public void testToolingProviderSetToolingWithNullValue() { ToolingProvider.setTooling(null); }
ToolingProvider { public static void clearTooling() { tooling.remove(); } ToolingProvider(ProcessingEnvironment processingEnv); static ToolingProvider getTooling(); static void setTooling(ProcessingEnvironment processingEnvironment); static void clearTooling(); Elements getElements(); Filer getFiler(); Messager getMess...
@Test public void testToolingProviderSetToolingWithValidProcessingEnvironmentWithClear() { testToolingProviderSetToolingWithValidProcessingEnvironment(); ToolingProvider.clearTooling(); testToolingProviderSetToolingWithValidProcessingEnvironment(); }
UnaryOperationWrapperOperand extends Operand<Object> { @Override public Object value() { if (resultOperand == null) { calculateResultOperand(); } return resultOperand.value(); } UnaryOperationWrapperOperand(Operand operand, OperationType unaryOperationType); @Override Class<Object> getOperandsJavaType(); @Override Obje...
@Test public void test_unaryOperationType_successfulPath_getValue() { UnaryOperationWrapperOperand unit = new UnaryOperationWrapperOperand(new BooleanOperand("true"), OperationType.NEGATE); MatcherAssert.assertThat((Boolean) unit.value(), Matchers.is(false)); unit = new UnaryOperationWrapperOperand(new BooleanOperand("...
UnaryOperationWrapperOperand extends Operand<Object> { @Override public Class<Object> getOperandsJavaType() { if (resultOperand == null) { calculateResultOperand(); } return resultOperand.getOperandsJavaType(); } UnaryOperationWrapperOperand(Operand operand, OperationType unaryOperationType); @Override Class<Object> ge...
@Test public void test_unaryOperationType_successfulPath_getOperandsJavaType() { UnaryOperationWrapperOperand unit = new UnaryOperationWrapperOperand(new BooleanOperand("true"), OperationType.NEGATE); MatcherAssert.assertThat( (Class)unit.getOperandsJavaType(), Matchers.equalTo((Class)Boolean.class)); }
LongOperand extends ParsedOperand<Long> { @Override public Long value() { return Long.valueOf(getExpressionString()); } LongOperand(String expressionString); @Override Class<Long> getOperandsJavaType(); @Override Long value(); @Override OperandType getOperandType(); }
@Test(expected = IllegalArgumentException.class) public void test_passedNullValue() { new LongOperand(null).value(); } @Test public void test_createLongOperand() { MatcherAssert.assertThat((Long) new LongOperand("6").value(), Matchers.is(6L)); MatcherAssert.assertThat((Long) new LongOperand("-6").value(), Matchers.is(-...
LongOperand extends ParsedOperand<Long> { @Override public Class<Long> getOperandsJavaType() { return Long.class; } LongOperand(String expressionString); @Override Class<Long> getOperandsJavaType(); @Override Long value(); @Override OperandType getOperandType(); }
@Test public void test_getOperandsJavaType() { MatcherAssert.assertThat(new LongOperand("6").getOperandsJavaType(), Matchers.equalTo((Class) Long.class)); }
BeanUtils { public static boolean checkHasSetter(VariableElement field) { if (field == null || field.getKind() != ElementKind.FIELD) { return false; } TypeElement typeElement = ElementUtils.AccessEnclosingElements.<TypeElement>getFirstEnclosingElementOfKind(field, ElementKind.CLASS); return checkLombokDataAnnotation(ty...
@Test public void fieldWithImplementedGetterAndSetters_checkHasSetter() { unitTestBuilder.useSource(JavaFileObjectUtils.readFromResource("testcases.beanutils/FieldLevelTestcases.java")) .useProcessor(new AbstractUnitTestAnnotationProcessorClass() { @Override protected void testCase(TypeElement element) { VariableElemen...
OperandFactory { public static Operand createOperand(OperandType operandType, String expressionString, OperationType[] unaryOperationsToBeApplied, Expression expression) { if ((operandType == null) || (expressionString == null)) { throw new IllegalArgumentException("operandType and expressionString must not be null"); ...
@Test(expected = IllegalArgumentException.class) public void createOperand_nullValued_operandType() { OperandFactory.createOperand(null, "ABC", new OperationType[0], null); } @Test(expected = IllegalArgumentException.class) public void createOperand_nullValued_expressionString() { OperandFactory.createOperand(OperandTy...
Operand { public abstract OperandType getOperandType(); Operand(); abstract OperandType getOperandType(); abstract Class<? extends T> getOperandsJavaType(); abstract T value(); static String getStringRepresentationOfOperandsJavaTypes(Operand[] operandsArray); }
@Test(expected = IllegalArgumentException.class) public void OperandType_getOperand_testNullValue() { OperandType.getOperandType(null); } @Test public void OperandType_getOperand_testLong() { MatcherAssert.assertThat(OperandType.getOperandType("1234"), Matchers.is(OperandType.LONG)); } @Test public void OperandType_get...
NullValueOperand extends ParsedOperand<Object> { @Override public Object value() { return null; } NullValueOperand(String expressionString); @Override Class<Object> getOperandsJavaType(); @Override Object value(); @Override OperandType getOperandType(); }
@Test(expected = IllegalArgumentException.class) public void test_passedNullValue() { new BooleanOperand(null).value(); } @Test public void test_getValue() { MatcherAssert.assertThat(new NullValueOperand("null").value(), Matchers.nullValue()); }
NullValueOperand extends ParsedOperand<Object> { @Override public Class<Object> getOperandsJavaType() { return null; } NullValueOperand(String expressionString); @Override Class<Object> getOperandsJavaType(); @Override Object value(); @Override OperandType getOperandType(); }
@Test public void test_getOperandsJavaType() { MatcherAssert.assertThat(new NullValueOperand("null").getOperandsJavaType(), Matchers.nullValue()); }
BooleanOperand extends ParsedOperand<Boolean> { @Override public Boolean value() { return Boolean.valueOf(getExpressionString()); } BooleanOperand(String expressionString); @Override Class<Boolean> getOperandsJavaType(); @Override Boolean value(); @Override OperandType getOperandType(); }
@Test(expected = IllegalArgumentException.class) public void test_passedNullValue() { new BooleanOperand(null).value(); } @Test public void test_createBooleanOperand() { MatcherAssert.assertThat((Boolean) new BooleanOperand("true").value(), Matchers.is(true)); MatcherAssert.assertThat((Boolean) new BooleanOperand("fals...
BooleanOperand extends ParsedOperand<Boolean> { @Override public Class<Boolean> getOperandsJavaType() { return Boolean.class; } BooleanOperand(String expressionString); @Override Class<Boolean> getOperandsJavaType(); @Override Boolean value(); @Override OperandType getOperandType(); }
@Test public void test_getOperandsJavaType() { MatcherAssert.assertThat(new BooleanOperand("true").getOperandsJavaType(), Matchers.equalTo((Class) Boolean.class)); }
StringOperand extends ParsedOperand<String> { @Override public Class<String> getOperandsJavaType() { return String.class; } StringOperand(String expressionString); @Override Class<String> getOperandsJavaType(); @Override String value(); @Override OperandType getOperandType(); }
@Test public void test_getOperandsJavaType() { MatcherAssert.assertThat(new StringOperand("'test'").getOperandsJavaType(), Matchers.equalTo((Class) String.class)); }
StringOperand extends ParsedOperand<String> { @Override public String value() { return internalValue; } StringOperand(String expressionString); @Override Class<String> getOperandsJavaType(); @Override String value(); @Override OperandType getOperandType(); }
@Test public void testStringWithoutEscapes() { MatcherAssert.assertThat(new StringOperand("'ABC DEF'").value(), Matchers.is("ABC DEF")); MatcherAssert.assertThat(new StringOperand("' MatcherAssert.assertThat(new StringOperand("'A%§GS34234|||F'").value(), Matchers.is("A%§GS34234|||F")); } @Test public void testStringWit...
DynamicOperand extends ParsedOperand<Object> { @Override public Object value() { ModelPathResolver.ResolvedModelPathResult result = ModelPathResolver.resolveModelPath(ModelPathResolver.modelMapThreadLocal.get(), getExpressionString()); return result.getValue(); } DynamicOperand(String expressionString); @Override Class...
@Test(expected = IllegalArgumentException.class) public void test_passedNullValue() { new DynamicOperand(null).value(); } @Test public void testResolveModelValue() { Map<String, Object> model = new HashMap<String, Object>(); model.put("longKey", 5L); model.put("integerKey", 5); model.put("doubleKey", 5.0); model.put("f...
DoubleOperand extends ParsedOperand<Double> { @Override public Double value() { return Double.valueOf(getExpressionString()); } DoubleOperand( String expressionString); @Override Class<Double> getOperandsJavaType(); @Override Double value(); @Override OperandType getOperandType(); }
@Test(expected = IllegalArgumentException.class) public void test_passedNullValue() { new DoubleOperand(null).value(); } @Test public void test_createDoubleOperand() { MatcherAssert.assertThat((Double) new DoubleOperand("6.0").value(), Matchers.is(6.0)); MatcherAssert.assertThat((Double) new DoubleOperand("-6.0").value...
DoubleOperand extends ParsedOperand<Double> { @Override public Class<Double> getOperandsJavaType() { return Double.class; } DoubleOperand( String expressionString); @Override Class<Double> getOperandsJavaType(); @Override Double value(); @Override OperandType getOperandType(); }
@Test public void test_getOperandsJavaType() { MatcherAssert.assertThat(new DoubleOperand("6.0").getOperandsJavaType(), Matchers.equalTo((Class) Double.class)); }
ExpressionParser { public static OperationTypeSearchResult getOperationType(String expressionString, int index) { for (OperationType operationType : OperationType.getOperationsByOperationTypeMode(OperationTypeMode.BINARY)) { Matcher matcher = operationType.getOperationPattern().matcher(expressionString); if (matcher.fi...
@Test(expected = IllegalArgumentException.class) public void getOperationType_operationTypeNotFound() { ExpressionParser.getOperationType(" == sdsadasda", 12); } @Test public void getOperationType_getEquals() { assertOperationTypeSearchResult(ExpressionParser.getOperationType(" == sdsadasda", 0), 0, 8, OperationType.EQ...
ExpressionParser { public static Expression parseExpression(String expressionString, Map<String, Object> model) { ModelPathResolver.modelMapThreadLocal.set(model); return parseExpression(expressionString); } static Expression parseExpression(String expressionString, Map<String, Object> model); static ExpressionParseRe...
@Test public void parseExpression_parseNegation_negatedTrue_Test() { Expression expression = ExpressionParser.parseExpression("!true"); MatcherAssert.assertThat(expression.getOperands().length, Matchers.is(1)); MatcherAssert.assertThat(expression.getOperationTypes().length, Matchers.is(0)); MatcherAssert.assertThat((Bo...
ParseUtilities { public static String readResourceToString(String resourcefileName) throws IOException { InputStream inputStream = ParseUtilities.class.getResourceAsStream(resourcefileName); if (inputStream != null) { return readFromInputStream(inputStream); } else { throw new IllegalArgumentException("Can't open resou...
@Test public void readResourceToStringTest() throws Exception { final String EXPECTED_RESULT = "ABC" + System.lineSeparator() + "DEF" + System.lineSeparator() + "HIJ"; MatcherAssert.assertThat(ParseUtilities.readResourceToString("/ReadResourceToStringTest.txt"), Matchers.is(EXPECTED_RESULT)); }
ParseUtilities { public static String trimContentString(String content) { String tmpContentString = content; tmpContentString = tmpContentString.replaceFirst("^[ ]*?\n", ""); tmpContentString = tmpContentString.replaceAll("[ ]+$", ""); return tmpContentString; } static TemplateBlockBinder parseString(String templateSt...
@Test public void trimContentString_trimContentString_Test() { MatcherAssert.assertThat(ParseUtilities.trimContentString(" \nabc"), Matchers.is("abc")); MatcherAssert.assertThat(ParseUtilities.trimContentString(" \n abc"), Matchers.is(" abc")); MatcherAssert.assertThat(ParseUtilities.trimContentString(" \n \nabc"), Mat...
ParseUtilities { public static Map<String, String> parseNamedAttributes(String attributeString) { Map<String, String> attributeMap = new HashMap<>(); final String attributePatternString = "\\s*(\\w+)\\s*:\\s*'(.*?)'\\s*"; Pattern attributePattern = Pattern.compile("(" + attributePatternString + ")(?:,(\" + attributePat...
@Test public void parseNamedAttributes_parseAttributes() { String stringToParse = " abc : '/val1' , def : 'v.a.l2',hij:'val 3' "; Map<String, String> map = ParseUtilities.parseNamedAttributes(stringToParse); MatcherAssert.assertThat(map.get("abc"), Matchers.is("/val1")); MatcherAssert.assertThat(map.get("def"), Matcher...
ParseUtilities { public static Map<String, Object> extractModelFromString(Map<String, Object> outerModel, String modelString) { if (outerModel == null) { throw new IllegalArgumentException("passed outerModel must not be null"); } if (modelString == null) { throw new IllegalArgumentException("passed modelString must not...
@Test public void extractModelFromString_correctUsage() { Map<String, Object> outerModel = new HashMap<>(); Map<String, Object> outerModelModel = new HashMap<>(); outerModel.put("model", outerModelModel); outerModelModel.put("value1", "value_1"); outerModelModel.put("value2", "value_2"); Map<String, Object> result = Pa...
ParseUtilities { static void addKeyValuePair(Map<String, Object> outerModel, Map<String, Object> modelToBuild, String key, String valueExpression) { String[] keyAccessPath = key.split("[.]"); String valueKey = keyAccessPath[keyAccessPath.length - 1]; Map<String, Object> targetMap = modelToBuild; for (int i = 0; i < key...
@Test public void addKeyValuePair_correctUsage() { Map<String, Object> outerModel = new HashMap<>(); Map<String, Object> outerModelModel = new HashMap<>(); outerModel.put("model", outerModelModel); outerModelModel.put("abc", "yes"); Map<String, Object> modelToFill = new HashMap<>(); ParseUtilities.addKeyValuePair(outer...
ForTemplateBlock implements TemplateBlock { @Override public TemplateBlockType getTemplateBlockType() { return TemplateBlockType.FOR; } ForTemplateBlock(String attributeString, String templateString); @Override TemplateBlockType getTemplateBlockType(); @Override String getContent(Map<String, Object> outerVariables); Te...
@Test public void test_getTemplateBlockType() { MatcherAssert.assertThat(new ForTemplateBlock("test:abc.def", "DEF").getTemplateBlockType(), Matchers.is(TemplateBlockType.FOR)); }
ForTemplateBlock implements TemplateBlock { @Override public String getContent(Map<String, Object> outerVariables) { Map<String, Object> variables = new HashMap<>(); variables.putAll(outerVariables); Object values = ModelPathResolver.resolveModelPath(outerVariables, accessPath).getValue(); StringBuilder stringBuilder =...
@Test(expected = InvalidPathException.class) public void test_getContent_invalidPath() { ForTemplateBlock unit = new ForTemplateBlock(" abc : def ", "${abc}"); Map<String, Object> model = new HashMap<String, Object>(); unit.getContent(model); } @Test(expected = InvalidPathException.class) public void test_getContent_in...
IfTemplateBlock implements TemplateBlock { @Override public TemplateBlockType getTemplateBlockType() { return TemplateBlockType.IF; } IfTemplateBlock(String attributeString, String templateString); @Override TemplateBlockType getTemplateBlockType(); @Override String getContent(Map<String, Object> outerVariables); Templ...
@Test public void test_getTemplateBlockType() { MatcherAssert.assertThat(new IfTemplateBlock("abc", "").getTemplateBlockType(), Matchers.is(TemplateBlockType.IF)); }
StaticTemplateBlock implements TemplateBlock { @Override public TemplateBlockType getTemplateBlockType() { return TemplateBlockType.STATIC; } StaticTemplateBlock(String content); @Override TemplateBlockType getTemplateBlockType(); @Override String getContent(Map<String, Object> variables); }
@Test public void test_getTemplateBlockType() { MatcherAssert.assertThat(new StaticTemplateBlock("").getTemplateBlockType(), Matchers.is(TemplateBlockType.STATIC)); }
PlainTextTemplateBlock implements TemplateBlock { @Override public TemplateBlockType getTemplateBlockType() { return TemplateBlockType.PLAIN_TEXT; } PlainTextTemplateBlock(String content); @Override TemplateBlockType getTemplateBlockType(); String getContent(Map<String, Object> variables); }
@Test public void test_getTemplateBlockType() { MatcherAssert.assertThat(new PlainTextTemplateBlock("").getTemplateBlockType(), Matchers.is(TemplateBlockType.PLAIN_TEXT)); }
VariableTextTemplateBlock implements TemplateBlock { @Override public TemplateBlockType getTemplateBlockType() { return TemplateBlockType.DYNAMIC_TEXT; } VariableTextTemplateBlock(String accessPath); @Override TemplateBlockType getTemplateBlockType(); @Override String getContent(Map<String, Object> variables); }
@Test public void test_getTemplateBlockType() { MatcherAssert.assertThat(new VariableTextTemplateBlock("abc").getTemplateBlockType(), Matchers.is(TemplateBlockType.DYNAMIC_TEXT)); }
VariableTextTemplateBlock implements TemplateBlock { protected String getAccessPath() { return this.accessPath; } VariableTextTemplateBlock(String accessPath); @Override TemplateBlockType getTemplateBlockType(); @Override String getContent(Map<String, Object> variables); }
@Test public void test_constructor_ValidAccessPath() { VariableTextTemplateBlock unit = new VariableTextTemplateBlock("abc"); MatcherAssert.assertThat(unit.getAccessPath(), Matchers.equalTo("abc")); }
VariableTextTemplateBlock implements TemplateBlock { @Override public String getContent(Map<String, Object> variables) { Expression expression = ExpressionParser.parseExpression(accessPath, variables); Operand result = expression.evaluateExpression(); return result.value() != null ? result.value().toString() : null; } ...
@Test(expected = InvalidPathException.class) public void test_getContent_invalidPath() { VariableTextTemplateBlock unit = new VariableTextTemplateBlock("abc"); Map<String,Object> model = new HashMap<String, Object>(); unit.getContent(model); } @Test public void test_getContent_nullValuedValue() { VariableTextTemplateBl...
TemplateBlockBinder implements TemplateBlock { @Override public TemplateBlockType getTemplateBlockType() { return TemplateBlockType.BINDER; } TemplateBlockBinder( String templateString); @Override TemplateBlockType getTemplateBlockType(); @Override String getContent(Map<String, Object> variables); void addTemplateBlock...
@Test public void test_getTemplateBlockType() { MatcherAssert.assertThat(new TemplateBlockBinder("").getTemplateBlockType(), Matchers.is(TemplateBlockType.BINDER)); }
IncludeTemplateBlock implements TemplateBlock { @Override public TemplateBlockType getTemplateBlockType() { return TemplateBlockType.INCLUDE; } IncludeTemplateBlock(String attributeString, String modelDefinitionString); @Override TemplateBlockType getTemplateBlockType(); @Override String getContent(Map<String, Object> ...
@Test public void test_getTemplateBlockType() { MatcherAssert.assertThat(new IncludeTemplateBlock("resource : '/IncludeTemplateBlockTest.tpl'", "").getTemplateBlockType(), Matchers.is(TemplateBlockType.INCLUDE)); }
IncludeTemplateBlock implements TemplateBlock { @Override public String getContent(Map<String, Object> variables) { Map<String, Object> model; if (this.modelAccessPath != null) { Object values = ModelPathResolver.resolveModelPath(variables, this.modelAccessPath).getValue(); model = new HashMap<>(); model.put("model", v...
@Test public void test_getContent_successfully() { IncludeTemplateBlock unit = new IncludeTemplateBlock("resource : '/IncludeTemplateBlockTest.tpl'",""); Map<String, Object> model = new HashMap<String, Object>(); Map<String, Object> subModel = new HashMap<String, Object>(); subModel.put("value", "test"); model.put("mod...