Permalink
Please sign in to comment.
Showing
with
530 additions
and 8 deletions.
- +44 −0 CODE_COVERAGE.md
- +15 −0 gradle/jacoco-non-android.gradle
- +5 −1 storio-common-annotations-processor/build.gradle
- +40 −0 .../src/test/java/com/pushtorefresh/storio/common/annotations/processor/ProcessingExceptionTest.java
- +110 −0 ...t/java/com/pushtorefresh/storio/common/annotations/processor/StorIOAnnotationsProcessorDummy.java
- +96 −0 .../com/pushtorefresh/storio/common/annotations/processor/StorIOAnnotationsProcessorProcessTest.java
- +51 −0 ...st/java/com/pushtorefresh/storio/common/annotations/processor/StorIOAnnotationsProcessorTest.java
- +38 −7 ...c/test/java/com/pushtorefresh/storio/common/annotations/processor/introspection/JavaTypeTest.java
- +71 −0 ...ava/com/pushtorefresh/storio/common/annotations/processor/introspection/StorIOColumnMetaTest.java
- +60 −0 .../java/com/pushtorefresh/storio/common/annotations/processor/introspection/StorIOTypeMetaTest.java
44
CODE_COVERAGE.md
@@ -0,0 +1,44 @@ | ||
+# Code Coverage Report generation | ||
+ | ||
+# For Android Modules | ||
+ | ||
+Here are some of the andriod modules: | ||
+* storio-common | ||
+* storio-content-resolver | ||
+* storio-sample-app | ||
+* storio-sqlite | ||
+* storio-test-common | ||
+* storio-test-without-rxjava | ||
+ | ||
+To generate the code coverage report for android modules, execute the following command: | ||
+ | ||
+> Windows: ci.sh | ||
+> Linux/Unix/ OSX: ./ci.sh | ||
+ | ||
+This will generate code coverage report in each of the modules. In order to view the same, open the following file in your browser. | ||
+> ROOT/MODULE_NAME/build/reports/jacoco | ||
+ | ||
+Please note that the above folder is created under each of the modules. For example: | ||
+* pushtorefresh-storio/storio-common/build/reports/jacoco/testReleaseUnitTestCoverage/html/index.html | ||
+* pushtorefresh-storio/storio-content-resolver/build/reports/jacoco/testReleaseUnitTestCoverage/html/index.html | ||
+ | ||
+# For Non-Android Modules | ||
+ | ||
+Here are some of the non-andriod modules: | ||
+* storio-common-annotations-processor | ||
+* storio-content-resolver-annotations | ||
+* storio-content-resolver-annotations-processor | ||
+* storio-sqlite-annotations | ||
+* storio-sqlite-annotations-processor | ||
+ | ||
+To generate the coverage report for non-android modules, execute the following commands at the module's root directory: | ||
+ | ||
+> Windows: gradle jacocoTestReport | ||
+> Linux/Unix/ OSX: ./gradle jacocoTestReport | ||
+ | ||
+This will generate code coverage report in each of the modules. In order to view the same, open the following file in your browser. | ||
+> ROOT/MODULE_NAME/build/reports/jacoco | ||
+ | ||
+Please note that the above folder is created under each of the modules. For example: | ||
+* pushtorefresh-storio/storio-common-annotations-processor/build/reports/jacoco/test/index.html | ||
+* pushtorefresh-storio/storio-content-resolver-annotations/build/reports/jacoco/testReleaseUnitTestCoverage/html/index.html |
15
gradle/jacoco-non-android.gradle
@@ -0,0 +1,15 @@ | ||
+apply plugin: 'jacoco' | ||
+ | ||
+jacoco { | ||
+ // See https://github.com/jacoco/jacoco/releases | ||
+ toolVersion = '0.7.5.201505241946' | ||
+ reportsDir = file("$buildDir/customJacocoReportDir") | ||
+} | ||
+ | ||
+jacocoTestReport { | ||
+ reports { | ||
+ xml.enabled true | ||
+ csv.enabled true | ||
+ html.destination "${buildDir}/reports/jacoco/test" | ||
+ } | ||
+} |
6
storio-common-annotations-processor/build.gradle
40
...t/java/com/pushtorefresh/storio/common/annotations/processor/ProcessingExceptionTest.java
@@ -0,0 +1,40 @@ | ||
+package com.pushtorefresh.storio.common.annotations.processor; | ||
+ | ||
+import static org.assertj.core.api.Assertions.assertThat; | ||
+import static org.powermock.api.mockito.PowerMockito.mock; | ||
+import static org.powermock.reflect.Whitebox.getInternalState; | ||
+ | ||
+import javax.lang.model.element.Element; | ||
+ | ||
+import org.junit.Before; | ||
+import org.junit.Test; | ||
+ | ||
+public class ProcessingExceptionTest { | ||
+ | ||
+ private Element elementMock; | ||
+ | ||
+ @Before | ||
+ public void setUp() throws Exception { | ||
+ elementMock = mock(Element.class); | ||
+ } | ||
+ | ||
+ @Test | ||
+ public final void processingException() { | ||
+ // when | ||
+ ProcessingException processingException = new ProcessingException(elementMock, "TEST"); | ||
+ | ||
+ // then | ||
+ assertThat("TEST").as("Constructor must be set detailMessage field.").isEqualTo(getInternalState(processingException, "detailMessage")); | ||
+ assertThat(elementMock).as("Constructor must be set element field.").isEqualTo(getInternalState(processingException, "element")); | ||
+ } | ||
+ | ||
+ @Test | ||
+ public final void element() { | ||
+ // when | ||
+ ProcessingException processingException = new ProcessingException(elementMock, "TEST"); | ||
+ | ||
+ // then | ||
+ assertThat(elementMock).as("Constructor must be set element field.").isEqualTo(processingException.element()); | ||
+ } | ||
+ | ||
+} |
110
...om/pushtorefresh/storio/common/annotations/processor/StorIOAnnotationsProcessorDummy.java
@@ -0,0 +1,110 @@ | ||
+package com.pushtorefresh.storio.common.annotations.processor; | ||
+ | ||
+import java.lang.annotation.Annotation; | ||
+import java.util.Map; | ||
+ | ||
+import javax.annotation.processing.RoundEnvironment; | ||
+import javax.lang.model.element.Element; | ||
+import javax.lang.model.element.TypeElement; | ||
+import javax.lang.model.util.Elements; | ||
+ | ||
+import com.pushtorefresh.storio.common.annotations.processor.generate.Generator; | ||
+import com.pushtorefresh.storio.common.annotations.processor.introspection.StorIOColumnMeta; | ||
+import com.pushtorefresh.storio.common.annotations.processor.introspection.StorIOTypeMeta; | ||
+import com.squareup.javapoet.JavaFile; | ||
+import com.squareup.javapoet.TypeSpec; | ||
+ | ||
+@SuppressWarnings("rawtypes") | ||
+public final class StorIOAnnotationsProcessorDummy | ||
+ extends StorIOAnnotationsProcessor<StorIOTypeMeta, StorIOColumnMeta> { | ||
+ | ||
+ @Override | ||
+ protected StorIOTypeMeta processAnnotatedClass(TypeElement classElement, Elements elementUtils) { | ||
+ return null; | ||
+ } | ||
+ | ||
+ @Override | ||
+ protected void processAnnotatedFields(RoundEnvironment roundEnvironment, | ||
+ Map<TypeElement, StorIOTypeMeta> annotatedClasses) { | ||
+ } | ||
+ | ||
+ @Override | ||
+ protected StorIOColumnMeta processAnnotatedField(Element annotatedField) { | ||
+ return null; | ||
+ } | ||
+ | ||
+ @Override | ||
+ protected void validateAnnotatedClassesAndColumns(Map<TypeElement, StorIOTypeMeta> annotatedClasses) { | ||
+ } | ||
+ | ||
+ @Override | ||
+ protected Class<? extends Annotation> getTypeAnnotationClass() { | ||
+ return Annotation.class; | ||
+ } | ||
+ | ||
+ @Override | ||
+ protected Class<? extends Annotation> getColumnAnnotationClass() { | ||
+ return null; | ||
+ } | ||
+ | ||
+ @SuppressWarnings("unchecked") | ||
+ @Override | ||
+ protected Generator<StorIOTypeMeta> createPutResolver() { | ||
+ Generator resolver = new Generator<StorIOTypeMeta>() { | ||
+ | ||
+ @Override | ||
+ public JavaFile generateJavaFile(StorIOTypeMeta storIOContentResolverTypeMeta) { | ||
+ final TypeSpec putResolver = TypeSpec.classBuilder("TEST").build(); | ||
+ | ||
+ return JavaFile.builder("TEST", putResolver).build(); | ||
+ } | ||
+ }; | ||
+ return resolver; | ||
+ } | ||
+ | ||
+ @SuppressWarnings("unchecked") | ||
+ @Override | ||
+ protected Generator<StorIOTypeMeta> createGetResolver() { | ||
+ Generator resolver = new Generator<StorIOTypeMeta>() { | ||
+ | ||
+ @Override | ||
+ public JavaFile generateJavaFile(StorIOTypeMeta storIOContentResolverTypeMeta) { | ||
+ final TypeSpec getResolver = TypeSpec.classBuilder("TEST").build(); | ||
+ | ||
+ return JavaFile.builder("TEST", getResolver).build(); | ||
+ } | ||
+ }; | ||
+ return resolver; | ||
+ } | ||
+ | ||
+ @SuppressWarnings("unchecked") | ||
+ @Override | ||
+ protected Generator<StorIOTypeMeta> createDeleteResolver() { | ||
+ Generator resolver = new Generator<StorIOTypeMeta>() { | ||
+ | ||
+ @Override | ||
+ public JavaFile generateJavaFile(StorIOTypeMeta storIOContentResolverTypeMeta) { | ||
+ final TypeSpec deleteResolver = TypeSpec.classBuilder("TEST").build(); | ||
+ | ||
+ return JavaFile.builder("TEST", deleteResolver).build(); | ||
+ } | ||
+ }; | ||
+ return resolver; | ||
+ } | ||
+ | ||
+ @SuppressWarnings("unchecked") | ||
+ @Override | ||
+ protected Generator<StorIOTypeMeta> createMapping() { | ||
+ Generator mapping = new Generator<StorIOTypeMeta>() { | ||
+ | ||
+ @Override | ||
+ public JavaFile generateJavaFile(StorIOTypeMeta storIOContentResolverTypeMeta) { | ||
+ final TypeSpec mappingResolver = TypeSpec.classBuilder("TEST").build(); | ||
+ | ||
+ return JavaFile.builder("TEST", mappingResolver).build(); | ||
+ } | ||
+ }; | ||
+ return mapping; | ||
+ } | ||
+ | ||
+} |
96
...htorefresh/storio/common/annotations/processor/StorIOAnnotationsProcessorProcessTest.java
@@ -0,0 +1,96 @@ | ||
+package com.pushtorefresh.storio.common.annotations.processor; | ||
+ | ||
+import static javax.tools.Diagnostic.Kind.ERROR; | ||
+import static org.mockito.Matchers.anyString; | ||
+import static org.mockito.Mockito.verify; | ||
+import static org.assertj.core.api.Assertions.assertThat; | ||
+import static org.powermock.api.mockito.PowerMockito.doReturn; | ||
+import static org.powermock.api.mockito.PowerMockito.mock; | ||
+import static org.powermock.api.mockito.PowerMockito.when; | ||
+ | ||
+import java.io.Writer; | ||
+import java.lang.annotation.Annotation; | ||
+import java.util.Arrays; | ||
+import java.util.HashSet; | ||
+import java.util.Set; | ||
+ | ||
+import javax.annotation.processing.Filer; | ||
+import javax.annotation.processing.Messager; | ||
+import javax.annotation.processing.ProcessingEnvironment; | ||
+import javax.annotation.processing.RoundEnvironment; | ||
+import javax.lang.model.element.Element; | ||
+import javax.lang.model.element.TypeElement; | ||
+import javax.lang.model.util.Elements; | ||
+import javax.tools.JavaFileObject; | ||
+ | ||
+import org.junit.Before; | ||
+import org.junit.Test; | ||
+import org.junit.runner.RunWith; | ||
+import org.powermock.core.classloader.annotations.PrepareForTest; | ||
+import org.powermock.modules.junit4.PowerMockRunner; | ||
+ | ||
+import com.squareup.javapoet.JavaFile; | ||
+ | ||
+@RunWith(PowerMockRunner.class) | ||
+@PrepareForTest({ JavaFile.class, JavaFileObject.class }) | ||
+public class StorIOAnnotationsProcessorProcessTest { | ||
+ | ||
+ private StorIOAnnotationsProcessorDummy storioAnnotationsProcessor; | ||
+ private RoundEnvironment roundEnvironmentMock; | ||
+ private TypeElement typeElementMock; | ||
+ private ProcessingEnvironment processingEnvironment; | ||
+ private Set<Element> elementsAnnotatedWithStorIOType; | ||
+ | ||
+ @Before | ||
+ public void setUp() throws Exception { | ||
+ storioAnnotationsProcessor = new StorIOAnnotationsProcessorDummy(); | ||
+ roundEnvironmentMock = mock(RoundEnvironment.class); | ||
+ typeElementMock = mock(TypeElement.class); | ||
+ processingEnvironment = mock(ProcessingEnvironment.class); | ||
+ elementsAnnotatedWithStorIOType = new HashSet<Element>(Arrays.asList(typeElementMock)); | ||
+ doReturn(elementsAnnotatedWithStorIOType).when(roundEnvironmentMock).getElementsAnnotatedWith(Annotation.class); | ||
+ } | ||
+ | ||
+ @Test | ||
+ public final void processTrue() throws Exception { | ||
+ // given | ||
+ Elements elementUtilsMock = mock(Elements.class); | ||
+ when(processingEnvironment.getElementUtils()).thenReturn(elementUtilsMock); | ||
+ | ||
+ Filer filerMock = mock(Filer.class); | ||
+ when(processingEnvironment.getFiler()).thenReturn(filerMock); | ||
+ | ||
+ JavaFileObject javaFileObject = mock(JavaFileObject.class); | ||
+ when(filerMock.createSourceFile(anyString())).thenReturn(javaFileObject); | ||
+ | ||
+ Writer writerMock = mock(Writer.class); | ||
+ when(javaFileObject.openWriter()).thenReturn(writerMock); | ||
+ | ||
+ storioAnnotationsProcessor.init(processingEnvironment); | ||
+ | ||
+ // when | ||
+ boolean result = storioAnnotationsProcessor.process(null, roundEnvironmentMock); | ||
+ | ||
+ // then | ||
+ assertThat(result).isTrue(); | ||
+ } | ||
+ | ||
+ @Test | ||
+ public final void processExceptionExpected() throws Exception { | ||
+ // given | ||
+ Messager messager = mock(Messager.class); | ||
+ when(processingEnvironment.getMessager()).thenReturn(messager); | ||
+ | ||
+ when(processingEnvironment.getFiler()).thenReturn(null); | ||
+ | ||
+ storioAnnotationsProcessor.init(processingEnvironment); | ||
+ | ||
+ // when | ||
+ storioAnnotationsProcessor.process(null, roundEnvironmentMock); | ||
+ | ||
+ // then | ||
+ // Filer value set to null, filerSourceFile can't be generated and | ||
+ // problem occures. | ||
+ verify(messager).printMessage(ERROR, "Problem occurred with StorIOProcessor: null"); | ||
+ } | ||
+} |
51
...com/pushtorefresh/storio/common/annotations/processor/StorIOAnnotationsProcessorTest.java
@@ -0,0 +1,51 @@ | ||
+package com.pushtorefresh.storio.common.annotations.processor; | ||
+ | ||
+import static org.assertj.core.api.Assertions.assertThat; | ||
+import static org.powermock.api.mockito.PowerMockito.mock; | ||
+import static org.powermock.reflect.Whitebox.getInternalState; | ||
+ | ||
+import javax.annotation.processing.ProcessingEnvironment; | ||
+import javax.lang.model.SourceVersion; | ||
+import javax.tools.JavaFileObject; | ||
+ | ||
+import org.junit.Before; | ||
+import org.junit.Test; | ||
+import org.junit.runner.RunWith; | ||
+import org.powermock.core.classloader.annotations.PrepareForTest; | ||
+import org.powermock.modules.junit4.PowerMockRunner; | ||
+ | ||
+import com.squareup.javapoet.JavaFile; | ||
+ | ||
+@RunWith(PowerMockRunner.class) | ||
+@PrepareForTest({ JavaFile.class, JavaFileObject.class }) | ||
+public class StorIOAnnotationsProcessorTest { | ||
+ | ||
+ private StorIOAnnotationsProcessorDummy storioAnnotationsProcessor; | ||
+ private ProcessingEnvironment processingEnvironment; | ||
+ | ||
+ @Before | ||
+ public void setUp() throws Exception { | ||
+ storioAnnotationsProcessor = new StorIOAnnotationsProcessorDummy(); | ||
+ processingEnvironment = mock(ProcessingEnvironment.class); | ||
+ } | ||
+ | ||
+ @Test | ||
+ public final void initProcessingEnvironment() { | ||
+ // when | ||
+ storioAnnotationsProcessor.init(processingEnvironment); | ||
+ | ||
+ // then | ||
+ assertThat(processingEnvironment.getFiler()).as("init must be set filer field.").isEqualTo(getInternalState(storioAnnotationsProcessor, "filer")); | ||
+ assertThat(processingEnvironment.getElementUtils()).as("init must be set elementUtils field.").isEqualTo(getInternalState(storioAnnotationsProcessor, "elementUtils")); | ||
+ assertThat(processingEnvironment.getMessager()).as("init must be set messager field.").isEqualTo(getInternalState(storioAnnotationsProcessor, "messager")); | ||
+ } | ||
+ | ||
+ @Test | ||
+ public final void getSupportedSourceVersion() { | ||
+ // given | ||
+ SourceVersion result = storioAnnotationsProcessor.getSupportedSourceVersion(); | ||
+ | ||
+ // then | ||
+ assertThat(SourceVersion.latestSupported()).as("Function must return same result with SourceVersion.latestSupported() function.").isEqualTo(result); | ||
+ } | ||
+} |
45
...ava/com/pushtorefresh/storio/common/annotations/processor/introspection/JavaTypeTest.java
71
...pushtorefresh/storio/common/annotations/processor/introspection/StorIOColumnMetaTest.java
@@ -0,0 +1,71 @@ | ||
+package com.pushtorefresh.storio.common.annotations.processor.introspection; | ||
+ | ||
+import static org.assertj.core.api.Assertions.assertThat; | ||
+import static org.powermock.api.mockito.PowerMockito.mock; | ||
+import static org.powermock.reflect.Whitebox.getInternalState; | ||
+ | ||
+import java.lang.annotation.Annotation; | ||
+ | ||
+import javax.lang.model.element.Element; | ||
+ | ||
+import org.junit.Before; | ||
+import org.junit.Test; | ||
+ | ||
+import nl.jqno.equalsverifier.EqualsVerifier; | ||
+import nl.jqno.equalsverifier.Warning; | ||
+ | ||
+public class StorIOColumnMetaTest { | ||
+ | ||
+ private Annotation annotationMock; | ||
+ private Element elementMock; | ||
+ private JavaType javaType; | ||
+ | ||
+ @Before | ||
+ public void setUp() throws Exception { | ||
+ annotationMock = mock(Annotation.class); | ||
+ elementMock = mock(Element.class); | ||
+ javaType = JavaType.BOOLEAN; | ||
+ } | ||
+ | ||
+ @SuppressWarnings({ "unchecked", "rawtypes" }) | ||
+ @Test | ||
+ public final void constructor() { | ||
+ // when | ||
+ StorIOColumnMeta storioColumnMeta = new StorIOColumnMeta(elementMock, elementMock, "TEST", javaType, | ||
+ annotationMock); | ||
+ | ||
+ // then | ||
+ assertThat(elementMock).as("Constructor must be set enclosingElement field.") | ||
+ .isEqualTo(getInternalState(storioColumnMeta, "enclosingElement")); | ||
+ assertThat(elementMock).as("Constructor must be set element field.") | ||
+ .isEqualTo(getInternalState(storioColumnMeta, "element")); | ||
+ assertThat("TEST").as("Constructor must be set fieldName field.") | ||
+ .isEqualTo(getInternalState(storioColumnMeta, "fieldName")); | ||
+ assertThat(javaType).as("Constructor must be set javaType field.") | ||
+ .isEqualTo(getInternalState(storioColumnMeta, "javaType")); | ||
+ assertThat(annotationMock).as("Constructor must be set storIOColumn field.") | ||
+ .isEqualTo(getInternalState(storioColumnMeta, "storIOColumn")); | ||
+ } | ||
+ | ||
+ @Test | ||
+ public final void equalsAndHashCode() { | ||
+ EqualsVerifier.forClass(StorIOColumnMeta.class).suppress(Warning.REFERENCE_EQUALITY).usingGetClass().verify(); | ||
+ } | ||
+ | ||
+ @SuppressWarnings({ "unchecked", "rawtypes" }) | ||
+ @Test | ||
+ public final void toStringValidation() { | ||
+ // given | ||
+ StorIOColumnMeta storioColumnMeta = new StorIOColumnMeta(elementMock, elementMock, "TEST", javaType, | ||
+ annotationMock); | ||
+ String expectedString = "StorIOColumnMeta{enclosingElement=" + elementMock + ", element=" + elementMock | ||
+ + ", fieldName='TEST" + '\'' + ", javaType=" + javaType + ", storIOColumn=" + annotationMock + '}'; | ||
+ | ||
+ // when | ||
+ String toString = storioColumnMeta.toString(); | ||
+ | ||
+ // then | ||
+ assertThat(expectedString).as("toString method should be equal with expectedString.").isEqualTo(toString); | ||
+ } | ||
+ | ||
+} |
60
...m/pushtorefresh/storio/common/annotations/processor/introspection/StorIOTypeMetaTest.java
@@ -0,0 +1,60 @@ | ||
+package com.pushtorefresh.storio.common.annotations.processor.introspection; | ||
+ | ||
+import static org.assertj.core.api.Assertions.assertThat; | ||
+import static org.powermock.api.mockito.PowerMockito.mock; | ||
+import static org.powermock.reflect.Whitebox.getInternalState; | ||
+ | ||
+import java.lang.annotation.Annotation; | ||
+ | ||
+import org.junit.Before; | ||
+import org.junit.Test; | ||
+ | ||
+import nl.jqno.equalsverifier.EqualsVerifier; | ||
+import nl.jqno.equalsverifier.Warning; | ||
+ | ||
+public class StorIOTypeMetaTest { | ||
+ | ||
+ private Annotation annotationMock; | ||
+ | ||
+ @Before | ||
+ public void setUp() throws Exception { | ||
+ annotationMock = mock(Annotation.class); | ||
+ } | ||
+ | ||
+ @SuppressWarnings({ "unchecked", "rawtypes" }) | ||
+ @Test | ||
+ public final void constructor() { | ||
+ // when | ||
+ StorIOTypeMeta storioTypeMeta = new StorIOTypeMeta("TEST", "TEST", annotationMock); | ||
+ | ||
+ // then | ||
+ assertThat("TEST").as("Constructor must be set simpleName field.").isEqualTo(getInternalState(storioTypeMeta, "simpleName")); | ||
+ assertThat("TEST").as("Constructor must be set packageName field.").isEqualTo(getInternalState(storioTypeMeta, "packageName")); | ||
+ assertThat(annotationMock).as("Constructor must be set storIOType field.").isEqualTo(getInternalState(storioTypeMeta, "storIOType")); | ||
+ } | ||
+ | ||
+ @Test | ||
+ public final void equalsAndHashCode() { | ||
+ EqualsVerifier.forClass(StorIOTypeMeta.class).suppress(Warning.REFERENCE_EQUALITY).usingGetClass().verify(); | ||
+ } | ||
+ | ||
+ @SuppressWarnings({ "unchecked", "rawtypes" }) | ||
+ @Test | ||
+ public final void toStringValitadion() { | ||
+ // given | ||
+ StorIOTypeMeta storioTypeMeta = new StorIOTypeMeta("TEST", "TEST", annotationMock); | ||
+ String expectedString = "StorIOTypeMeta{" + | ||
+ "simpleName='TEST" + '\'' + | ||
+ ", packageName='TEST" + '\'' + | ||
+ ", storIOType=" + annotationMock + | ||
+ ", columns=" + getInternalState(storioTypeMeta, "columns") + | ||
+ '}'; | ||
+ | ||
+ // when | ||
+ String toString = storioTypeMeta.toString(); | ||
+ | ||
+ // then | ||
+ assertThat(expectedString).as("toString method should be equal with expectedString.").isEqualTo(toString); | ||
+ } | ||
+ | ||
+} |
0 comments on commit
a2a4f47