-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add data upgrade flag, tests, and Javadoc comments
Refactored the data upgrade mechanism to run conditionally based on a command-line argument "RunUpgrade". Added unit tests for FlamesServer and FlamesDataManager. Enhanced existing classes with comprehensive Javadoc comments.
- Loading branch information
1 parent
ff03ba0
commit 2be10d3
Showing
16 changed files
with
236 additions
and
17 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/test/java/com/severalcircles/flames/data/FlamesDataManagerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright (c) 2024 Several Circles. | ||
*/ | ||
|
||
package com.severalcircles.flames.data; | ||
|
||
import com.severalcircles.flames.data.user.FlamesUser; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.Random; | ||
import java.util.logging.Logger; | ||
|
||
public class FlamesDataManagerTest { | ||
|
||
@Test | ||
public void getUser_WhenUserDoesNotExists_ShouldCreateAndReturnNewUser() throws IOException, ConsentException { | ||
FlamesDataManager.prepare(); | ||
String id = new Random().nextInt(10000) + ""; | ||
File expectedUserFile = new File(FlamesDataManager.USER_DIRECTORY.getAbsolutePath() + "/" + id + ".yml"); | ||
|
||
if (expectedUserFile.exists()) { | ||
Assertions.fail("Test precondition failed. A user with the id already exists."); | ||
} else { | ||
FlamesUser user = FlamesDataManager.getUser(id, true); | ||
Assertions.assertTrue(expectedUserFile.exists()); | ||
Assertions.assertNotNull(user); | ||
Assertions.assertEquals(id, user.getId()); | ||
} | ||
if (FlamesDataManager.FLAMES_DIRECTORY.delete()) Logger.getGlobal().info("Deleted Flames directory"); | ||
|
||
} | ||
|
||
@Test | ||
public void getUser_WhenUserExists_ShouldReturnExistingUser() throws IOException, ConsentException { | ||
FlamesDataManager.prepare(); | ||
String id = "existingUserId"; | ||
|
||
FlamesUser expectedUser = createAndSaveUserWithId(id); | ||
|
||
FlamesUser actualUser = FlamesDataManager.getUser(id); | ||
Assertions.assertEquals(expectedUser.getId(), actualUser.getId()); | ||
if (FlamesDataManager.FLAMES_DIRECTORY.delete()) Logger.getGlobal().info("Deleted Flames directory"); | ||
} | ||
|
||
private FlamesUser createAndSaveUserWithId(String id) { | ||
FlamesDataManager.prepare(); | ||
FlamesUser user = new FlamesUser(id); | ||
user.setConsent(1); | ||
try { | ||
FlamesDataManager.saveUser(user); | ||
} catch (IOException e) { | ||
Assertions.fail("Error creating Flames User for test.", e); | ||
} | ||
if (FlamesDataManager.FLAMES_DIRECTORY.delete()) Logger.getGlobal().info("Deleted Flames directory"); | ||
return user; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/test/java/com/severalcircles/flames/data/FlamesServerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright (c) 2024 Several Circles. | ||
*/ | ||
|
||
package com.severalcircles.flames.data; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class FlamesServerTest { | ||
|
||
/** | ||
* This class tests the setId method of FlamesServer class. | ||
* The setId method is used to set the value of "id" of a FlamesServer object. | ||
*/ | ||
|
||
@Test | ||
public void testSetId() { | ||
FlamesServer server = new FlamesServer(); | ||
server.setId("12345"); | ||
assertEquals("12345", server.getId()); | ||
} | ||
} |