Skip to content

Commit

Permalink
[#2] Added additional unit test to test hasOf method of Validators
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasstamann committed Jun 30, 2017
1 parent dac2014 commit a0fcda8
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public void testHasSynchronizedModifier() {


@Test
public void testHasNtiveModifier() {
public void testHasNativeModifier() {

Element e = Mockito.mock(Element.class);
Mockito.when(e.getModifiers()).thenReturn(Utilities.convertVarargsToSet(Modifier.NATIVE));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
package de.holisticon.annotationprocessortoolkit.tools.characteristicsvalidator;

import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.mockito.Mockito;

import javax.lang.model.element.Element;
import javax.lang.model.element.Modifier;

/**
* Unit test of {@link GenericElementCharacteristicValidator}.
*/
public class GenericElementCharacteristicMatcherTest {


@Test
public void testHasOf_OneOf() {

GenericElementCharacteristicValidator<Modifier> spy = Mockito.spy((GenericElementCharacteristicValidator<Modifier>) Validator.getModifierValidator());

Element element = Mockito.mock(Element.class);
spy.hasOf(ValidatorKind.ONE_OF, element, Modifier.ABSTRACT);

Mockito.verify(spy).hasOneOf(element, Modifier.ABSTRACT);

}

@Test
public void testHasOf_AtLeastOneOf() {

GenericElementCharacteristicValidator<Modifier> spy = Mockito.spy((GenericElementCharacteristicValidator<Modifier>) Validator.getModifierValidator());

Element element = Mockito.mock(Element.class);
spy.hasOf(ValidatorKind.AT_LEAST_ONE_OF, element, Modifier.ABSTRACT);

Mockito.verify(spy).hasAtLeastOneOf(element, Modifier.ABSTRACT);

}

@Test
public void testHasOf_AllOf() {

GenericElementCharacteristicValidator<Modifier> spy = Mockito.spy((GenericElementCharacteristicValidator<Modifier>) Validator.getModifierValidator());

Element element = Mockito.mock(Element.class);
spy.hasOf(ValidatorKind.ALL_OF, element, Modifier.ABSTRACT);

Mockito.verify(spy).hasAllOf(element, Modifier.ABSTRACT);

}

@Test
public void testHasOf_NoneOf() {

GenericElementCharacteristicValidator<Modifier> spy = Mockito.spy((GenericElementCharacteristicValidator<Modifier>) Validator.getModifierValidator());

Element element = Mockito.mock(Element.class);
spy.hasOf(ValidatorKind.NONE_OF, element, Modifier.ABSTRACT);

Mockito.verify(spy).hasNoneOf(element, Modifier.ABSTRACT);

}

@Test
public void testHasOf_nullValuedKind() {

GenericElementCharacteristicValidator<Modifier> spy = Mockito.spy((GenericElementCharacteristicValidator<Modifier>) Validator.getModifierValidator());

Element element = Mockito.mock(Element.class);
MatcherAssert.assertThat(spy.hasOf(null, element, Modifier.ABSTRACT), Matchers.is(false));

Mockito.verify(spy, Mockito.never()).hasNoneOf(element, Modifier.ABSTRACT);
Mockito.verify(spy, Mockito.never()).hasOneOf(element, Modifier.ABSTRACT);
Mockito.verify(spy, Mockito.never()).hasAtLeastOneOf(element, Modifier.ABSTRACT);
Mockito.verify(spy, Mockito.never()).hasAllOf(element, Modifier.ABSTRACT);


}

@Test
public void testHasOf_oneOf_nullValuedElement() {

GenericElementCharacteristicValidator<Modifier> spy = Mockito.spy((GenericElementCharacteristicValidator<Modifier>) Validator.getModifierValidator());

MatcherAssert.assertThat(spy.hasOf(ValidatorKind.ONE_OF, null, Modifier.ABSTRACT), Matchers.is(false));

Mockito.verify(spy).hasOneOf(null, Modifier.ABSTRACT);


}

@Test
public void testHasOf_atLeastOneOf_nullValuedElement() {

GenericElementCharacteristicValidator<Modifier> spy = Mockito.spy((GenericElementCharacteristicValidator<Modifier>) Validator.getModifierValidator());

MatcherAssert.assertThat(spy.hasOf(ValidatorKind.AT_LEAST_ONE_OF, null, Modifier.ABSTRACT), Matchers.is(false));

Mockito.verify(spy).hasAtLeastOneOf(null, Modifier.ABSTRACT);


}

@Test
public void testHasOf_allOf_nullValuedElement() {

GenericElementCharacteristicValidator<Modifier> spy = Mockito.spy((GenericElementCharacteristicValidator<Modifier>) Validator.getModifierValidator());

MatcherAssert.assertThat(spy.hasOf(ValidatorKind.ALL_OF, null, Modifier.ABSTRACT), Matchers.is(false));

Mockito.verify(spy).hasAllOf(null, Modifier.ABSTRACT);


}

@Test
public void testHasOf_noneOf_nullValuedElement() {

GenericElementCharacteristicValidator<Modifier> spy = Mockito.spy((GenericElementCharacteristicValidator<Modifier>) Validator.getModifierValidator());

MatcherAssert.assertThat(spy.hasOf(ValidatorKind.NONE_OF, null, Modifier.ABSTRACT), Matchers.is(false));

Mockito.verify(spy).hasNoneOf(null, Modifier.ABSTRACT);


}


}

0 comments on commit a0fcda8

Please sign in to comment.