Skip to content
Snippets Groups Projects
Commit 446f48a0 authored by Andreas's avatar Andreas
Browse files

Made FileHandlingBudget methods static

parent cea45c80
No related branches found
No related tags found
2 merge requests!43Merging frontend-testing into master,!39GeneralBudget set BudgetPeriod to be days left of month, and made FileHandling methods static.
......@@ -25,7 +25,7 @@ public class FileHandlingBudget {
* @param fileTitle the name of the file you want to check
* @throws IOException if an input or output exception occurred.
*/
public void writeGeneralBudgetToFile(String fileTitle, GeneralBudget generalBudget) throws IOException {
public static void writeGeneralBudgetToFile(String fileTitle, GeneralBudget generalBudget) throws IOException {
try (BufferedWriter bw = new BufferedWriter(new FileWriter(filePath + fileTitle + fileType))) {
bw.write(generalBudget.toString());
} catch (IOException ex) {
......@@ -40,7 +40,7 @@ public class FileHandlingBudget {
* @return true or false depending on if file is empty.
* @throws IOException if an input or output exception occurred.
*/
public boolean isEmpty(String fileTitle) throws IOException {
public static boolean isEmpty(String fileTitle) throws IOException {
try (BufferedReader br = new BufferedReader(new FileReader(filePath + fileTitle + fileType))) {
return br.readLine() == null;
}
......@@ -53,7 +53,7 @@ public class FileHandlingBudget {
* @return the GeneralBudget from the file.
* @throws IOException if an input or output exception occurred.
*/
public GeneralBudget readGeneralBudgetFromFile(String fileTitle) throws IOException {
public static GeneralBudget readGeneralBudgetFromFile(String fileTitle) throws IOException {
GeneralBudget generalBudget = null;
double maxAmount = 0;
double budgetAmount = 0;
......
budgetPeriod=12
maxAmount=1200.0
budgetAmount=500.0
......
budgetPeriod=12
maxAmount=1200.0
budgetAmount=500.0
......
......@@ -20,8 +20,6 @@ class FileHandlingBudgetTest {
BudgetItem foodItem;
BudgetItem bookItem;
BudgetItem clothesItem;
FileHandlingBudget fileHandlingBudget = new FileHandlingBudget();
@Nested
@DisplayName("FileHandling budget with one BudgetItem does not throw exception")
......@@ -37,13 +35,13 @@ class FileHandlingBudgetTest {
@Test
@DisplayName("Writing to file does not throw exception")
void writeGeneralBudgetToFileDoesNotThrowException() throws IOException {
assertDoesNotThrow(() -> fileHandlingBudget.writeGeneralBudgetToFile(fileTitle,generalBudget));
assertDoesNotThrow(() -> FileHandlingBudget.writeGeneralBudgetToFile(fileTitle,generalBudget));
}
@Test
@DisplayName("Reading from file gives correct budget back")
void readingGeneralBudgetFromFileDoesNotThrowException()throws IOException{
assertEquals(generalBudget,fileHandlingBudget.readGeneralBudgetFromFile(fileTitle));
assertEquals(generalBudget,FileHandlingBudget.readGeneralBudgetFromFile(fileTitle));
}
}
......@@ -64,13 +62,13 @@ class FileHandlingBudgetTest {
@Test
@DisplayName("Writing to file does not throw exception")
void writeGeneralBudgetToFileDoesNotThrowException() throws IOException {
assertDoesNotThrow(()->fileHandlingBudget.writeGeneralBudgetToFile(fileTitle,generalBudget));
assertDoesNotThrow(()->FileHandlingBudget.writeGeneralBudgetToFile(fileTitle,generalBudget));
}
@Test
@DisplayName("Reading from file gives correct budget back")
void readingGeneralBudgetFromFileDoesNotThrowException()throws IOException{
assertEquals(generalBudget,fileHandlingBudget.readGeneralBudgetFromFile(fileTitle));
assertEquals(generalBudget,FileHandlingBudget.readGeneralBudgetFromFile(fileTitle));
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment