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

Adding default constructor to MockSerializationResult. #598

Closed

Conversation

renanigt
Copy link
Contributor

Just adding a default constructor to make easier to use it in unit tests.

Now we need use some like: new MockSerializationResult(new JavassistProxifier(), cleanInstance(), new GsonBuilderWrapper(new MockInstanceImpl<>(jsonSerializers), new MockInstanceImpl<>(jsonDeserializers)));
With this default constructor, we just use some like: new MockSerializationResult();

What do you think ?

@renanigt
Copy link
Contributor Author

I don't know why the tests didn't pass on Travis CI, when I run mvn test, they'll pass with success.

@renanigt
Copy link
Contributor Author

When the Travis CI build, it doesn't know the class XStreamBuilderFactory, so the class exists as you know.
What I don't understand, why when I run mvn test on my machine, the tests pass with success.

@renanigt
Copy link
Contributor Author

Sorry for some problem...
You can close this issue. 😞

But if you get fix this problem, I think it's better to work with unit tests.

@garcia-jj
Copy link
Member

This error occurs to me too. Have you pushed all classes in your commit?

[ERROR] /home/otavio/eclipsew2/vraptor4/vraptor-core/src/main/java/br/com/caelum/vraptor/util/test/MockSerializationResult.java:[39,51] cannot find symbol
[ERROR] symbol:   class XStreamBuilderFactory
[ERROR] location: package br.com.caelum.vraptor.serialization.xstream
[ERROR] /home/otavio/eclipsew2/vraptor4/vraptor-core/src/main/java/br/com/caelum/vraptor/util/test/MockSerializationResult.java:[73,48] cannot find symbol
[ERROR] symbol:   variable XStreamBuilderFactory
[ERROR] location: class br.com.caelum.vraptor.util.test.MockSerializationResult

@renanigt
Copy link
Contributor Author

@garcia-jj
Copy link
Member

I have downloaded your code, and I got the same error that Travis reported. I think that you miss to commit anything.

Can you check this?

@renanigt
Copy link
Contributor Author

I'll check this.
But I didn't create any classes, just the default constructor.

@renanigt
Copy link
Contributor Author

I checked this and I have commited all.

I don't created anything, just the default constructor.

May you make a test for me, creating this default constructor and run mvn test ?

@renanigt
Copy link
Contributor Author

Or you can close this issue and I try create with another branch.

@renanigt
Copy link
Contributor Author

The problem is on the Symbol XStreamBuilderFactory.
This class exists on VRaptor, I don't know why this error.

@renanigt
Copy link
Contributor Author

@garcia-jj May you run the test directly from Eclipse and after run mvn test ?
I got simulate the problem and after I ran with mvn test the problem was solved, I don't know why.

@renanigt
Copy link
Contributor Author

Or just rebuild this branch for a test...
When occur the first time and I rebuild, the problem is solved.

I don't understand why.

@garcia-jj
Copy link
Member

May be a missed import.
On Jun 15, 2014 6:28 PM, "Renan Montenegro" notifications@github.com
wrote:

The problem is on the Symbol XStreamBuilderFactory.
This class exists on VRaptor, I don't know why this error.


Reply to this email directly or view it on GitHub
#598 (comment).

@renanigt
Copy link
Contributor Author

The import is there.
May run the teste from eclipse, just to make a test for me ?

@renanigt
Copy link
Contributor Author

+import br.com.caelum.vraptor.serialization.xstream.XStreamBuilderFactory;

@garcia-jj
Copy link
Member

Because XStreamBuilderFactory is located at test folder, you can't use in main folder, because when we create the vraptor jar, test folder is discarted.

@renanigt
Copy link
Contributor Author

Oh Really... Sorry.

So, it's better closes this issue or fix it ?

@garcia-jj
Copy link
Member

I don't know if it's a good idea to move a class that was designed to use in tests, to main folder. This default constructor is really necessary? Or we can live without?

@renanigt
Copy link
Contributor Author

I think we can live without it, even if is easier using the dafault constructor.

So, we can after explain about on doc.

@renanigt
Copy link
Contributor Author

But still I think it's so importante make the developer's life easier.

@renanigt
Copy link
Contributor Author

Sorry for the english errors, I'm on cellphone. :-)

@garcia-jj
Copy link
Member

Yeah, we love to make the developer's life easier. But in this case, test classes must located under test directory, and not in the main directory. And... are only 4 lines 👍

@renanigt
Copy link
Contributor Author

I understand you.
I'll finish the controller's tests of vraptor-musicjungle and may be used as an example.

We can write something about MockSerializationResult on doc.

@renanigt
Copy link
Contributor Author

I was reading the new book about VRaptor 4, is cited the use of MockSerializationResult as MockSerializationResult result = new MockSerializationResult();.

Also on VRaptor 3 we needed just the default constructor.

So it's very important think about this, because may cause confusion on developers and turn more difficult their life.

I think that move the class XStreamBuilderFactory to main folder may be a good idea and still make developer's life easier.

@renanigt
Copy link
Contributor Author

I extracted the class to main folder, now the tests are passing.

So, if you think it's a good idea... 😃

@renanigt
Copy link
Contributor Author

Before, the method cleanInstace was in XStreamBuilderImpl, so I moved to it and removed the XStreamBuilderFactory.

@Turini
Copy link
Member

Turini commented Jun 16, 2014

I don't think we should add this kind of class for vraptor-core main src.
If it is really so important, we can think about extract test utils for an plugin.

@renanigt
Copy link
Contributor Author

I think It's important, but just a suggestion.

May be a good idea about a plugin.

@Turini
Copy link
Member

Turini commented Jun 16, 2014

What about wait some user ask for it? If (or when) that happens,
we can reopen the PR or extract for a plugin. What do you think?

@renanigt
Copy link
Contributor Author

May be, I just think the book's example is a problem, but is a good idea.

Also we can write doc about MockSerializationResult.

@Turini Turini closed this Jun 16, 2014
@lucascs lucascs reopened this Jun 17, 2014
@lucascs
Copy link
Member

lucascs commented Jun 17, 2014

VRaptor has to be testable, and the package br.com.caelum.vraptor.util.test stands for helping the testability of controllers, interceptors, etc...

we cannot force the user to use a constructor that complicated to be able to test serialization. The no-args constructor is the best tool to help the user.

What do you think @Turini ?

/**
* A Simple builder factory for XStreamBuilder tests
*/
public class XStreamBuilderFactory {
Copy link
Member

Choose a reason for hiding this comment

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

Rollback this change. VRaptor is released, we cannot simply remove a class without bumping the major release version.

@Turini
Copy link
Member

Turini commented Jun 17, 2014

What do you think @Turini ?

for now I think we can add the defaut constructor...
maybe if test package grows we can extract to a test plugin.

But @renanigt, can you send a new PR only with this change?

@renanigt
Copy link
Contributor Author

I made changes on test classes that used cleanInstance from XStreamBuilderFactory and now using from XStreamBuilderImpl, I rollback these changes too ?

@renanigt
Copy link
Contributor Author

Oh, do you want a new PR ?
Sorry for this commit.

I'll send the new PR.

@Turini
Copy link
Member

Turini commented Jun 17, 2014

can you send a new PR only adding the constructor?

@renanigt
Copy link
Contributor Author

Ok @Turini.
I'll do this. 😃

@Turini
Copy link
Member

Turini commented Jun 17, 2014

thanks! so closing here

@Turini Turini closed this Jun 17, 2014
@lucascs
Copy link
Member

lucascs commented Jun 17, 2014

I think testing is core for any application/library, not meant to be a plugin.

@renanigt
Copy link
Contributor Author

Make sense testing is core for any application.

@garcia-jj
Copy link
Member

@lucascs You didn't invite me, but I will join discution nevertheless. I agree, but not fully. If you watch the code, this constructor is too specific.

As I wrote in mailing list, this pull request uses a JavassistProxifier. But if I need to use another proxifier implementation?

In this pull request, no converters are used. But if I my application have a converter?

So, this pull request may help users, but only in too specific cases. So I don't know if is too valuable to move to core.

@renanigt
Copy link
Contributor Author

I have no knowledge as you ( @garcia-jj @Turini @lucascs ) and I'm learning a lot with you, but I'll left my opinion.

If you need use another constructor, in this case just need call the other constructor and not the default.
I think that in most cases the users will use just the default constructor, most of them don't know how to call the other because the dependecies.

@garcia-jj
Copy link
Member

This is my point: this change is too specific to move to core.

@renanigt
Copy link
Contributor Author

Seeing the class XStreamBuilderImpl, before, the method cleanInstance was there and after the method was extracted to XStreamBuilderFactory, so was moved from core to test folder.

I don't see as a problem.
With this, we make developer's life easier.
For me one of the great point of VRaptor is the testability, and for me we can't lost this.

@renanigt renanigt deleted the improveMockSerializationResult branch June 17, 2014 16:49
@lucascs
Copy link
Member

lucascs commented Jun 17, 2014

@garcia-jj I disagree, the change is not too specific. What if I have no converters, but I still want to know how my class is being serialized?

this needs to be easy.

@rponte
Copy link
Contributor

rponte commented Jun 17, 2014

I think it's a valuable change. It'll work very well for most of the cases.
If someone needs to register any converter or use a different proxy
implementation he just have to use another constructor and pass all
dependencies.

On Tuesday, June 17, 2014, Lucas Cavalcanti notifications@github.com
wrote:

@garcia-jj https://github.com/garcia-jj I disagree, the change is not
too specific. What if I have no converters, but I still want to know how my
class is being serialized?

this needs to be easy.


Reply to this email directly or view it on GitHub
#598 (comment).

Rafael Ponte
TriadWorks | Formação Java
http://cursos.triadworks.com.br

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.

None yet

5 participants