-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Added tests for DatabaseFileLookup #11108
Conversation
Added tests for DatabaseFileLookup
Please first fix tests to enable easier reviewing. You see the failing tests at the red crosses of the page of this PR. @arfazhxss |
I think, AuthirListTest should not be part of the PR |
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.
This test is a good start. It misses testing of different configurated file directies. Please re-iterate in the documentation.
In numbers: 20% of the issue solved.
src/test/java/org/jabref/logic/importer/DatabaseFileLookupTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/jabref/logic/importer/DatabaseFileLookupTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/jabref/logic/importer/DatabaseFileLookupTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/jabref/logic/importer/DatabaseFileLookupTest.java
Outdated
Show resolved
Hide resolved
@arfazhxss in future, do NOT use the main branch for cide changes. Create a separate branch for each issue solved! |
Thank you for the advice:) I am working on fixing the errors from the tests. |
Please read the devdocs and set up your code style https://devdocs.jabref.org/getting-into-the-code/guidelines-for-setting-up-a-local-workspace/intellij-13-code-style.html |
@Siedlerchr I have one failing checks for the checkStyle for now:
I think I might need a bit help on this one. |
In Intellij menu -> Code Reformat code and optimize imports |
src/test/java/org/jabref/logic/importer/DatabaseFileLookupTest.java
Outdated
Show resolved
Hide resolved
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.
Thank you for working on this
It does not fulfill the aims of the issue. JabRef has four places to store PDFs: Next to the bib file, in the general file directory, database file directory, the user-specific file directory. I don't see tests for all these cases.
src/test/java/org/jabref/logic/importer/DatabaseFileLookupTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/jabref/logic/importer/DatabaseFileLookupTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/jabref/logic/importer/DatabaseFileLookupTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/jabref/logic/importer/DatabaseFileLookupTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/jabref/logic/importer/DatabaseFileLookupTest.java
Outdated
Show resolved
Hide resolved
I will keep working on this pull request throughout next couple of weeks |
In my latest changes, I fixed the following requested changes:
@koppor Please let me know how I can improve the test cases if needed. |
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 am so sorry that my "hints" section at JabRef#678 made the impression that the task list was complete.
The intention of the task was that students think of test cases.
Here some hints:
- JabRef has 3 different file directories
- global one
- library-specific
- user-specific
Thus, file can be placed in
- global one
- library-specific
- user-specific
- directory of other user
File can exist in multiple directories.
The work should cover all cases derived from that.
E.g.,
- file in user-specific directory and global directory. Found in user-specific dir.
- file in user-specific directory and library-specific directory. Found in user-specific dir.
- file in user-specific directory and library-specific directory and global directory. Found in user-specific dir.
- file in user-specific directory of other user and library-specific directory and global directory. Found in library-specific dir.
- file in user-specific directory of other user and global directory. Found in global dir.
- file in library-specific directory and global directory. Found in library-specific dir.
- File in global-directory only. Found there.
- File in user-specific directory. Found there.
- File in library-specific directory. Found there.
This what I meant that 20% of the work have been done.
src/test/java/org/jabref/logic/importer/DatabaseFileLookupTest.java
Outdated
Show resolved
Hide resolved
@koppor thanks for clarifying! I want to get some more clarification on my test cases (and how I can improve them). My current test cases makes an x.txt and passes it through the metadata and databaseContext, and then uses DatabaseFileLookup to test whether the file is correctly detected in the database. It also checks if that file exists in the general file directory, database file directory, the user-specific file directory and bib/library file directory. Does it mean that my current test cases covers the following marked-cases only for now?
This is just to clarify if I am on the right track. |
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.
Your whole tests need to be reorganized. Sorry for this.
One test for case.
Example test names and content:
librarySpecificDirectoryOnly
. Places the file in library-specific directory. Checks that this file is found.userSpecificDirectoryAndLibrarySpecificDirectory
. Pleases the file in both user-specific and library-specific directory. Asserts that the file is found in the user-specific directory.
Note that the file is stored as filename without path.
Thus txtFileDirPath = txtFileDir.toAbsolutePath()
is absolutely wrong!!
The part of the BibEntry is file = {:test.pdf}
. And JabRef searches for that file.
(If you use absolute paths, it is boring, because JabRef can also ignore the directories, because the path is absolute. It is about resolving)
assertEquals(2, entries.size()); | ||
assertNotNull(entry1); | ||
assertNotNull(entry2); |
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.
A test case should focus on one thing. Not testing that constructors of data classes work. Remove all three assertions.
*/ | ||
@Test | ||
void fileShouldBeFound() { | ||
assertTrue(fileLookup.lookupDatabase(txtFileDir)); |
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.
This assertion is OK.
@Test | ||
void fileShouldBeFound() { | ||
assertTrue(fileLookup.lookupDatabase(txtFileDir)); | ||
assertNotNull(fileLookup.getPathOfDatabase()); |
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.
Remove this. Tests other aspects.
/** | ||
* x.txt should be found in the user-specific directory | ||
*/ | ||
@Test | ||
void userSpecificDirectory() { | ||
assertEquals(metaData.getUserFileDirectory(filePreferences.getUserAndHost()), Optional.of(txtFileDirPath)); | ||
} |
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.
description does not match assertion (does it)?
@arfazhxss I refined the issue to be more clear. Look at "User-facing thing" at JabRef#678. Hope, that helps to understand the issue. |
As far as I understand, you put an absolute path. Then, nothing of JabRef's lookup functionality is triggered. Story |
@arfazhxss I did not see any activity the last weeks. We need to keep our number of opened pull requests low to enable maintaining the project. If you continue on this, feel free to open a new pull request. |
Closes JabRef#678
I have added new test cases directoryPathTests to the DatabaseFileLookupTest class. These test cases verifies the functionality of the DatabaseFileLookup class in handling file paths and directories. It creates a temporary directory and file, sets up a BibDatabaseContext with two entries (one with a valid file path and one with an empty file path), and configures the FilePreferences to use the temporary directory as the default file directory. Then, it creates an instance of DatabaseFileLookup and asserts that the file in the temporary directory is found, while a non-existent file is not found. The test case checks if the FilePreferences are correctly set up with the temporary directory as the main file directory, and if the getPathOfDatabase() method of DatabaseFileLookup returns an empty path.
Mandatory checks
CHANGELOG.md
described in a way that is understandable for the average user (if applicable)