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 { ...@@ -25,7 +25,7 @@ public class FileHandlingBudget {
* @param fileTitle the name of the file you want to check * @param fileTitle the name of the file you want to check
* @throws IOException if an input or output exception occurred. * @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))) { try (BufferedWriter bw = new BufferedWriter(new FileWriter(filePath + fileTitle + fileType))) {
bw.write(generalBudget.toString()); bw.write(generalBudget.toString());
} catch (IOException ex) { } catch (IOException ex) {
...@@ -40,7 +40,7 @@ public class FileHandlingBudget { ...@@ -40,7 +40,7 @@ public class FileHandlingBudget {
* @return true or false depending on if file is empty. * @return true or false depending on if file is empty.
* @throws IOException if an input or output exception occurred. * @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))) { try (BufferedReader br = new BufferedReader(new FileReader(filePath + fileTitle + fileType))) {
return br.readLine() == null; return br.readLine() == null;
} }
...@@ -53,7 +53,7 @@ public class FileHandlingBudget { ...@@ -53,7 +53,7 @@ public class FileHandlingBudget {
* @return the GeneralBudget from the file. * @return the GeneralBudget from the file.
* @throws IOException if an input or output exception occurred. * @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; GeneralBudget generalBudget = null;
double maxAmount = 0; double maxAmount = 0;
double budgetAmount = 0; double budgetAmount = 0;
......
budgetPeriod=12
maxAmount=1200.0 maxAmount=1200.0
budgetAmount=500.0 budgetAmount=500.0
......
budgetPeriod=12
maxAmount=1200.0 maxAmount=1200.0
budgetAmount=500.0 budgetAmount=500.0
......
...@@ -20,8 +20,6 @@ class FileHandlingBudgetTest { ...@@ -20,8 +20,6 @@ class FileHandlingBudgetTest {
BudgetItem foodItem; BudgetItem foodItem;
BudgetItem bookItem; BudgetItem bookItem;
BudgetItem clothesItem; BudgetItem clothesItem;
FileHandlingBudget fileHandlingBudget = new FileHandlingBudget();
@Nested @Nested
@DisplayName("FileHandling budget with one BudgetItem does not throw exception") @DisplayName("FileHandling budget with one BudgetItem does not throw exception")
...@@ -37,13 +35,13 @@ class FileHandlingBudgetTest { ...@@ -37,13 +35,13 @@ class FileHandlingBudgetTest {
@Test @Test
@DisplayName("Writing to file does not throw exception") @DisplayName("Writing to file does not throw exception")
void writeGeneralBudgetToFileDoesNotThrowException() throws IOException { void writeGeneralBudgetToFileDoesNotThrowException() throws IOException {
assertDoesNotThrow(() -> fileHandlingBudget.writeGeneralBudgetToFile(fileTitle,generalBudget)); assertDoesNotThrow(() -> FileHandlingBudget.writeGeneralBudgetToFile(fileTitle,generalBudget));
} }
@Test @Test
@DisplayName("Reading from file gives correct budget back") @DisplayName("Reading from file gives correct budget back")
void readingGeneralBudgetFromFileDoesNotThrowException()throws IOException{ void readingGeneralBudgetFromFileDoesNotThrowException()throws IOException{
assertEquals(generalBudget,fileHandlingBudget.readGeneralBudgetFromFile(fileTitle)); assertEquals(generalBudget,FileHandlingBudget.readGeneralBudgetFromFile(fileTitle));
} }
} }
...@@ -64,13 +62,13 @@ class FileHandlingBudgetTest { ...@@ -64,13 +62,13 @@ class FileHandlingBudgetTest {
@Test @Test
@DisplayName("Writing to file does not throw exception") @DisplayName("Writing to file does not throw exception")
void writeGeneralBudgetToFileDoesNotThrowException() throws IOException { void writeGeneralBudgetToFileDoesNotThrowException() throws IOException {
assertDoesNotThrow(()->fileHandlingBudget.writeGeneralBudgetToFile(fileTitle,generalBudget)); assertDoesNotThrow(()->FileHandlingBudget.writeGeneralBudgetToFile(fileTitle,generalBudget));
} }
@Test @Test
@DisplayName("Reading from file gives correct budget back") @DisplayName("Reading from file gives correct budget back")
void readingGeneralBudgetFromFileDoesNotThrowException()throws IOException{ 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