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

18 save to file unit tests #130

Merged
merged 32 commits into from
Feb 16, 2023
Merged

Conversation

kappsegla
Copy link
Contributor

Tried writing some tests for save to file that @xCandyFun has made a PR for, using TempDir from junit5 and changing user.home path while running tests. Achieved over 95% test coverage this way, without having to make the code under test more test friendly.
Also included a version bump of AssertJ so we can use Assertions.linesOf with Path to verify file content in a test.

This is just an example of how it is possible to verify file manipulation and saving in an easy way using AssertJ library.
Feel free to include this code in the project by merging it into the haze/18-save-to-file branch before accepting #117 or updating that PR with commits directly.

xCandyFun and others added 17 commits February 15, 2023 22:14
For writing tests against filecontent with assertJ the method
Assertions.linesOf(Path) is needed to avoid using File from java.io.
Not available before 3.23.0.
To be able to specify a path to a test folder during test running
a new method will be added called setDir(Path). Default folder will
still be used in user home folder if not specifying a Path with setDir.

Also removes \n from writeString call that otherwise creates an empty
line at the end.
Adds two test one for a successful save and one for trying to save
to an invalid folder so no file can be created.
Adds new test that changes user.home property to run more code.
Rewritten testmethods that can test saving to file by
changing 'user.home' property.
# Conflicts:
#	src/main/java/org/fungover/haze/Main.java
#	src/main/java/org/fungover/haze/SaveFile.java
#	src/test/java/org/fungover/haze/SaveFileTest.java
Remove \\ from path. Works in windows but not on linux file systems.
…-file-unit-tests

# Conflicts:
#	src/main/java/org/fungover/haze/SaveFile.java
#	src/test/java/org/fungover/haze/SaveFileTest.java
Copy link
Contributor

@cchriss123 cchriss123 left a comment

Choose a reason for hiding this comment

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

Great job. Code works and looks great.

@sonarcloud
Copy link

sonarcloud bot commented Feb 16, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

94.1% 94.1% Coverage
0.0% 0.0% Duplication

@jLereback jLereback merged commit 37286c8 into 18-save-to-file Feb 16, 2023
@jLereback jLereback deleted the 18-save-to-file-unit-tests branch February 16, 2023 08:46
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.

5 participants