Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compile testing for StorIOSQLiteAnnotationsProcessor #760

Merged
merged 11 commits into from
Feb 13, 2017
Merged

Compile testing for StorIOSQLiteAnnotationsProcessor #760

merged 11 commits into from
Feb 13, 2017

Conversation

geralt-encore
Copy link
Collaborator

While I was working on annotation processor I realised how lacking of proper tests for it made any changes painful to introduce. I set up Compile Testings which works like a charm for purpose of testing of annotation processors. I tried to cover every case that we have atm (both error and regular). Also, I removed some of the previous tests since they have become redundant and it doesn't make sense to maintain them.
Feel free to ask me any questions about it!
I am planning to implement tests in the same fashion for content resolver annotations processor later.

@artem-zinnatullin
Copy link
Member

artem-zinnatullin commented Feb 5, 2017 via email

@geralt-encore
Copy link
Collaborator Author

It's mostly just resources for assertions. Tests itself are quite small. Also, I've done a couple of changes based on results of tests.
I am not sure what's wrong with CI tho. It runs fine locally and I know for sure that it can be run on CI environment without any issues.

Copy link
Collaborator

@nikitin-da nikitin-da left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

@nikitin-da nikitin-da left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work, @geralt-encore !
Tests look so straightforward without that terrible amount of mocks!

@@ -86,10 +88,19 @@ private TypeElement validateAnnotatedClass(@NotNull final Element annotatedEleme
// We expect here that annotatedElement is Class, annotation requires that via @Target.
final TypeElement annotatedTypeElement = (TypeElement) annotatedElement;

if (annotatedTypeElement.getModifiers().contains(PRIVATE)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

throw new SkipNotAnnotatedClassWithAnnotatedParentException("Fields of classes not annotated with" + getTypeAnnotationClass().getSimpleName() +
"which have parents annotated with" + getTypeAnnotationClass().getSimpleName() + "will be skipped (e.g. AutoValue case)");
throw new SkipNotAnnotatedClassWithAnnotatedParentException("Fields of classes not annotated with"
+ getTypeAnnotationClass().getSimpleName()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missed spaces around name

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Luckily it's just a warning message, but I'll fix it anyway. Thanks!

throw new ProcessingException(
classElement,
"Table name of " + classElement.getQualifiedName() + " annotated with " + StorIOSQLiteType.class.getSimpleName() + " is null or empty"
if (tableName.length() == 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@geralt-encore
Copy link
Collaborator Author

@nikitin-da but how it can be related to SonarQube? We are not using it, right?
Epoxy has the same setup with Travis and everything is working for them. Am I missing something?

@nikitin-da
Copy link
Collaborator

@geralt-encore
Copy link
Collaborator Author

At least tests are running now 😐

@geralt-encore
Copy link
Collaborator Author

geralt-encore commented Feb 6, 2017

Also, weird thing - after switching to using this workaround java.lang imports appear in generated code. Can't get what is the connection between this two tho. And still don't have any ideas why resources folder isn't picked up by CI

Copy link
Member

@artem-zinnatullin artem-zinnatullin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few small things, otherwise looks great!

@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file seems unneeded

<application android:allowBackup="true"
android:label="@string/app_name"
android:supportsRtl="false"
>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/>?

@StorIOSQLiteType(table = "table")
public class BoxedTypesFields {

@StorIOSQLiteColumn(name = "booleanField")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to make field and column names different so it would not looks like they have to be the same for other contributors/readers of the code!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And in same places

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fieldN would be ok?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or just use underscores _ instead of camelCase?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean boolean_field? But what the difference?

import com.pushtorefresh.storio.sqlite.SQLiteTypeMapping;

/**
* Generated mapping with collection of resolvers
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

. :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And below

contentValues.put("doubleField", object.getDoubleField());
}
if (object.isBooleanField() != null) {
contentValues.put("booleanField", object.isBooleanField());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huh, IDE tricked you here with method name 😸

@geralt-encore
Copy link
Collaborator Author

@artem-zinnatullin @nikitin-da I would really appreciate some help in fixing tests in CI. I ran out of ideas for now 😔

@artem-zinnatullin
Copy link
Member

Interesting, so what I've found so far is that if I run precise task on my laptop :storio-sqlite-annotations-processor-test:testDebugUnitTest tests will pass, if I run the task we run on ci sh ci.sh — I'll have same fails as on Travis.

Moreover, if I run ./gradlew clean :storio-sqlite-annotations-processor-test:testDebugUnitTest — tests will fail, so it definitely depends on some task execution order.

Moremoremoreover, if I run ./gradlew clean && ./gradlew :storio-sqlite-annotations-processor-test:testDebugUnitTest (notice separate gradle invocation), this will pass!

So I think it's a bug either in Android Gradle Plugin or in Gradle itself.

What we can do for now is manually specify how to build it in ci.sh, just run these tests after all others as a separate gradle invocation!

@geralt-encore
Copy link
Collaborator Author

Nice finding! 👍 I'll fix all the comments tomorrow then and then we will be able to merge it.

@artem-zinnatullin
Copy link
Member

artem-zinnatullin commented Feb 7, 2017 via email

@geralt-encore
Copy link
Collaborator Author

@artem-zinnatullin any updates on this one?

@artem-zinnatullin
Copy link
Member

Waiting for CI fix from you :)

@geralt-encore
Copy link
Collaborator Author

Sorry, totally forgot about it =(
I got the idea, but then we need to exclude this task somehow from the main building process?

@codecov-io
Copy link

codecov-io commented Feb 12, 2017

Codecov Report

Merging #760 into master will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master     #760   +/-   ##
=======================================
  Coverage   96.05%   96.05%           
=======================================
  Files          87       87           
  Lines        2460     2460           
  Branches      267      267           
=======================================
  Hits         2363     2363           
  Misses         68       68           
  Partials       29       29

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b9523f4...83f4693. Read the comment docs.

@geralt-encore
Copy link
Collaborator Author

🎉

ci.sh Outdated
@@ -1,3 +1,3 @@
#!/bin/bash
# Please run it from root project directory
./gradlew clean build checkstyle -PdisablePreDex
./gradlew clean build checkstyle -PdisablePreDex -x :storio-sqlite-annotations-processor-test:test && ./gradlew :storio-sqlite-annotations-processor-test:testDebugUnitTest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a comment explaining why is this needed :D

@artem-zinnatullin artem-zinnatullin merged commit 554d14b into pushtorefresh:master Feb 13, 2017
@geralt-encore geralt-encore deleted the compile-testing branch February 16, 2017 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants