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
Skeleton PathAssert, plus tests -- NOT FOR INCLUSION. Yet. #303
Conversation
|
||
private ShouldBeAbsolutePath(final Path actual) | ||
{ | ||
super("\nExpecting:\n <%s>\nto be an absolute path", actual); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extract the message as a constant to avoid duplication.
I have one for eclipse and I know there is an eclipse plugin for Idea, I have given it a try in Idea 13 but it was not fully compatible with eclipse formatter preferences. Use it, this the best option we have here. Yes, one error message = one class, although I'm ok to reuse some like you did for Another missing thing that I really care about : javadoc with code example(s) for every assertion API. Otherwise, the code seems fine so thanks for the work 👍 |
@fge do you plan to continue working on this issue in a near future ? |
Sorry for the delay, but yes I do. I am working on some stuff for myself at the moment, if you wish that this be done rapidly then I can dedicate my time to it! Note about tests (meh, always strange to be talking about tests for a test framework): in order to verify the accuracy of assertions I write, I'd like to rely on memoryfs since it works relatively well, would that be an option? |
I'm planning the 2.0 release in few weeks and Path assertions need definitely to be in 2.0, it would be nice if you could finish this within 2/3 weeks but if you don't that's ok, I'll finish the work, no problem. I'm not against using memoryfs if it allows to to test things that would be really difficult with a real file system but I'm a little bit worried that some tests would pass with memoryfs and fail with a real file system. My opinion is then using the real file system as first option and memoryfs in second. |
Well, memoryfs allows to test things like, for instance, Among other things this would also allow to test the results of whether a given OK, resuming work on it. First things first, expect an amended commit, rebased on Note: given the variety of filesystem implementations, some tests are going to be difficult to write at all; for instance, check that two Well, I am probably getting ahead of myself at the moment. For now --> code. |
OK, updated with at least javadoc. However:
Where? In the In the meantime, I'll continue writing assertions... |
|
||
/** | ||
* Assert that a given path is absolute | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add code example
Thanks for taking the time to work on this. I have added notes where javadoc code examples were missing. If you have time (don't worry if you don't, I'll do it) I would like to see these assertions:
|
I will add code examples as requested. As to assertions, the ones you mention are planned already; but there are a lot more I plan to add. Before that however: do you agree with the added dependency? Also, do you agree about the base test code? Note that I am a TestNG user, so my JUnit code may turn out to be lacking. And yeah, code style... I'd rather fix it in one go once everything is written, if you don't mind? |
|
||
@SuppressWarnings("AutoBoxing") | ||
public class Paths_assertIsAbsolute_Test | ||
extends PathsBaseTest_NoFileSystem |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would just get rid of PathsBaseTest_NoFileSystem
, override setup
calling PathsBaseTest#setup
and initialising mock. Having a class PathsBaseTest_NoFileSystem
with a initPath
feels wrong to me.
IMO, if you need a base class for test that uses a mock path, its name should reflect that, maybe something like WithMockPathsBaseTest
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that for some assertions I'll need more than one path (example: test that two paths share the same filesystem; test that the target of a symlink is a given path; etc etc).
For tests that only use paths, I really want to avoid having to initialize a FileSystem. What is more, and that is a real problem to me, JUnit's @{Before,After}Class
methods are static (unlike TestNG's), which means that I have to initialize/destroy a FileSystem after each test; that is expensive.
I'm not sure about how to tackle this problem, really. I do want to avoid having to create a FileSystem
for each and every test, especially for classes which do not need to have one in the first place; and ideally I'd like to have the filesystem created and closed per test class not per test, and have the test class initialize it with the contents needed, not the base class.
This is a piece of cake with TestNG, not so with JUnit :(
I agree adding a test dependency. for the code style, don't worry too much, I'll rebase your commits and take of format discrepancies. more assertions ? like it ! :) |
I completely rebased the commits so that they look cleaner. Note about reallyExists() vs exists(): I have chosen this naming even though another solution would have been to have a boolean argument telling whether to follow symlinks or not. Is that OK? |
I find Small change needed in javadoc comments (which are nice btw), you need to enclose code with |
OK, will do.
Nice addition! I should look at that for my own javadoc... Will do. |
Uh, pom is currently failing because of a missing mockito-core version dependency. Parent pom needs fixing? |
raah, I have forgotten to push maven parent pom modifications ! :( sorry for the mess ! |
It should be fixed now as parent pom 1.3.2 is available. |
Confirmed, it fixes it! By the way, mockito 1.10.17 is out. About javadoc: should I heavily comment Paths as well as AbstractPathAssert? |
Ah, yeah, also, what is the preferred format for error messages? Sometimes I see that there are messages preceded by a newline before "expected", sometimes not... |
OK, can you please carefully review the last assertion? It is the first assertion which can throw an IOException; as such I modeled the tests etc on an equivalent I have also noted that there are files which use tabs for indentation; most of them use spaces... Meanwhile, writing other assertions! (yeah, also, you may have seen that I use a |
OK, another one to review carefully is |
Don't waste your time on Error messages are not consistent, I have started migrated them to start with a new line, use 2 spaces before displaying a value on a new line, a good example is ShouldBeEqualWithinOffset:
I will update mockito in a future commit, I don't have specific reasons to use the latest version but it's always good to be up to date. What is exactly the "last" assertion you want me to review carefully ? |
OK, will do that.
OK, will do that.
Uh yeah, I've rebased a lot so the track has been lost. I'm talking about In a similar vein, I'm writing the assertion for Is that what you want? |
My first thoughts would be that we should stick to the JDK behaviour to avoid confusing users, is it possible not to do any kind of normalization and/or resolution ? |
Well, it is possible, but then this is not what the equivalently named assertion in |
OK, I have transformed It may have surprising results though since with this modification, |
* | ||
* @see Files#exists(Path, LinkOption...) | ||
*/ | ||
public S existsNoFollow() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to existNoFollowLinks
@fge any update on this issue ? Do you want me to finish it ? |
Yes, please do. Unfortunately, I've been very busy with other stuff lately... Sorry :( Note however that the first commit is a proposed fix for issue #318 and that the code currently depends on this fix. |
No problem, thanks for your work ! |
finally done, thanks @fge for the work ! |
First of all, I am sorry for not having had the time to complete my branch to your expectations... And, uh, next question, in which version will those tests show up? ;) |
2.0, planned in a few weeks. |
Skeleton based on existing code. I modeled it on FileAssert. In fact I saw nothing related to anything java.nio.file in the code, so I created it from scratch...
Preview only. I know the coding style does not fit; knowing that I use IDEA, do you happen to have a style file available?
Also, about error messages: there seem to be a lot of factories; FileAssert seems to basically use one per message! Is that on purpose? Can I create a single factory for Path-specific operations (including exists, non exists and absolute)?
Please comment! I'll add more test when the base is good enough for you.