Skip to content

Commit

Permalink
[#18] Enhanced some unit tests for Operands
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasstamann committed Apr 3, 2018
1 parent 59b4a76 commit 2874365
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,27 @@ public class DynamicOperand extends ParsedOperand<Object> {
private Object value;

public DynamicOperand(String expressionString) {
super( expressionString);
super(expressionString);

}

@Override
public Class<Object> getOperandsJavaType() {

ModelPathResolver.ResolvedModelPathResult result = ModelPathResolver.resolveModelPath(ModelPathResolver.modelMapThreadLocal.get(), getExpressionString());
return result != null ? result.getType() : null;

// result cannot be null
return result.getType();

}

@Override
public Object value() {

ModelPathResolver.ResolvedModelPathResult result = ModelPathResolver.resolveModelPath(ModelPathResolver.modelMapThreadLocal.get(), getExpressionString());
return result != null ? result.getValue() : null;

// result cannot be null
return result.getValue();

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package io.toolisticon.annotationprocessortoolkit.templating.expressions.operands;

import io.toolisticon.annotationprocessortoolkit.templating.expressions.operations.OperationType;
import io.toolisticon.annotationprocessortoolkit.templating.expressions.operations.OperationTypeMode;

/**
* Created by tobiasstamann on 26.10.17.
* A wrapper for unary operations.
*/
public class UnaryOperationWrapperOperand extends Operand<Object> {

Expand All @@ -15,6 +16,13 @@ public class UnaryOperationWrapperOperand extends Operand<Object> {
public UnaryOperationWrapperOperand(Operand operand, OperationType unaryOperationType) {
super();

if (unaryOperationType == null) {
throw new IllegalArgumentException("unaryOperationType must not be null");
}
if (unaryOperationType.getOperationTypeMode() != OperationTypeMode.UNARY) {
throw new IllegalArgumentException("unaryOperationType must be a unary operation type");
}

this.operand = operand;
this.unaryOperationType = unaryOperationType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,16 @@ public void testStringWithEscapedQuotes() {

}

@Test
public void testNonMatchingStringPattern() {

// This is more or less a theoretical case
MatcherAssert.assertThat(new StringOperand("'ABC").value(), Matchers.nullValue());
MatcherAssert.assertThat(new StringOperand("ABC'").value(), Matchers.nullValue());
MatcherAssert.assertThat(new StringOperand("ABC").value(), Matchers.nullValue());

}

@Test
@Ignore
public void testStringWithEscapedEscapeChars() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package io.toolisticon.annotationprocessortoolkit.templating.expressions.operands;

import io.toolisticon.annotationprocessortoolkit.templating.expressions.operations.OperationType;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;

/**
* Unit test for {@link UnaryOperationWrapperOperand}.
*/
public class UnaryOperationWrapperOperandTest {

@Test(expected = IllegalArgumentException.class)
public void test_nullValuedOperationType_mustThrowException() {

new UnaryOperationWrapperOperand(new BooleanOperand("true"), null);

}

@Test(expected = IllegalArgumentException.class)
public void test_binaryOperationType_mustThrowException() {

new UnaryOperationWrapperOperand(new BooleanOperand("true"), OperationType.DIVISION);

}

@Test
public void test_unaryOperationType_mustNotThrowException() {

new UnaryOperationWrapperOperand(new BooleanOperand("true"), OperationType.NEGATE);

}

@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("false"), OperationType.NEGATE);
MatcherAssert.assertThat((Boolean) unit.value(), Matchers.is(true));


}

@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));



}

@Test(expected = IllegalArgumentException.class)
public void test_nullValuedOperand_mustThrowException() {

UnaryOperationWrapperOperand unit = new UnaryOperationWrapperOperand(null, OperationType.NEGATE);
MatcherAssert.assertThat(unit.value(), Matchers.nullValue());


}

}

0 comments on commit 2874365

Please sign in to comment.