From 591306e6fc6ebd3194f42a0f770f9e1172900271 Mon Sep 17 00:00:00 2001 From: ZanDev32 <52073144+ZanDev32@users.noreply.github.com> Date: Fri, 22 Aug 2025 03:45:00 +0700 Subject: [PATCH 1/9] Refactor: Update class visibility and improve code readability - Changed public class declarations to package-private for test classes. - Introduced constants for repeated string literals (e.g., admin username). - Simplified XML file loading logic in PostDataRepository. - Added helper methods in NutritionParserTest to reduce assertion count and improve readability. - Updated FXML test cases to use text blocks for better formatting. - Ensured consistent method visibility across test classes. --- .../repository/LocalUserDataRepository.java | 12 +- .../repository/PostDataRepository.java | 57 ++++-- .../com/starlight/util/FXMLVerificator.java | 3 + .../java/com/starlight/util/ImageUtils.java | 8 +- .../com/starlight/util/NutritionParser.java | 8 +- .../com/starlight/api/ChatbotAPITest.java | 108 ++++++----- .../com/starlight/api/UserApiServerTest.java | 2 +- .../AuthorizationControllerTest.java | 2 +- .../controller/ConsultControllerTest.java | 6 +- .../controller/LoadingControllerTest.java | 2 +- .../controller/SettingControllerTest.java | 10 +- .../model/PostDataRepositoryTest.java | 2 +- .../starlight/model/PostLikedStateTest.java | 2 +- .../java/com/starlight/model/PostTest.java | 2 +- .../model/UserDataRepositoryTest.java | 2 +- .../java/com/starlight/model/UserTest.java | 2 +- .../util/DataRepositoryIntegrationTest.java | 2 +- .../com/starlight/util/FXMLLoadingTest.java | 2 +- .../starlight/util/FXMLVerificatorTest.java | 176 +++++++++-------- .../starlight/util/FileSystemAccessTest.java | 2 +- .../starlight/util/NutritionParserTest.java | 183 ++++++++++-------- .../java/com/starlight/util/SessionTest.java | 2 +- 22 files changed, 333 insertions(+), 262 deletions(-) diff --git a/src/main/java/com/starlight/repository/LocalUserDataRepository.java b/src/main/java/com/starlight/repository/LocalUserDataRepository.java index bd95ce4..d29f67c 100644 --- a/src/main/java/com/starlight/repository/LocalUserDataRepository.java +++ b/src/main/java/com/starlight/repository/LocalUserDataRepository.java @@ -20,6 +20,8 @@ public class LocalUserDataRepository { private static final Logger logger = Logger.getLogger(LocalUserDataRepository.class.getName()); private static final String LOCAL_XML_PATH = "src/main/java/com/starlight/data/LocalUserData.xml"; + // Reused default admin username literal + private static final String ADMIN_USERNAME = "admin"; private final XStream xstream; private List cachedUsers; @@ -84,9 +86,9 @@ public List loadUsers() { private List createDefaultUsers() { List defaultUsers = new ArrayList<>(); - // Create admin user - User admin = new User(); - admin.username = "admin"; + // Create admin user + User admin = new User(); + admin.username = ADMIN_USERNAME; admin.email = "admin@tabemonpal.local"; admin.fullname = "Administrator"; admin.password = "admin123"; @@ -163,7 +165,7 @@ public User validateCredentials(String usernameOrEmail, String password) { * @return true if user is admin, false otherwise */ public boolean isAdmin(User user) { - return user != null && user.username != null && user.username.toLowerCase().equals("admin"); + return user != null && user.username != null && user.username.toLowerCase().equals(ADMIN_USERNAME); } /** @@ -171,7 +173,7 @@ public boolean isAdmin(User user) { * @return Admin user or null if not found */ public User getAdminUser() { - return findUser("admin"); + return findUser(ADMIN_USERNAME); } /** diff --git a/src/main/java/com/starlight/repository/PostDataRepository.java b/src/main/java/com/starlight/repository/PostDataRepository.java index 7092daa..50d185b 100644 --- a/src/main/java/com/starlight/repository/PostDataRepository.java +++ b/src/main/java/com/starlight/repository/PostDataRepository.java @@ -66,38 +66,53 @@ public List loadPosts(boolean useDummy) { return loadPosts(useDummy, false); } - @SuppressWarnings("unchecked") private List loadPosts(boolean useDummy, boolean fallbackToDummyIfMissing) { + File xmlFile = resolveXmlFile(useDummy, fallbackToDummyIfMissing); + if (xmlFile == null) return new ArrayList<>(); + + List posts = readPostsFromFile(xmlFile); + if (posts == null) return new ArrayList<>(); + + initializeMissingFields(posts); + return posts; + } + + /** Resolve which XML file to read based on flags; returns null if none available. */ + private File resolveXmlFile(boolean useDummy, boolean fallbackToDummyIfMissing) { File xmlFile = new File(useDummy ? DUMMY_XML_PATH : xmlPath); - if (!xmlFile.exists() || xmlFile.length() == 0) { - if (!useDummy && fallbackToDummyIfMissing) { - xmlFile = new File(DUMMY_XML_PATH); - if (!xmlFile.exists()) { - return new ArrayList<>(); - } - } else { - return new ArrayList<>(); + if (xmlFile.exists() && xmlFile.length() > 0) { + return xmlFile; + } + + if (!useDummy && fallbackToDummyIfMissing) { + File dummy = new File(DUMMY_XML_PATH); + if (dummy.exists() && dummy.length() > 0) { + return dummy; } } + + return null; + } + + @SuppressWarnings("unchecked") + private List readPostsFromFile(File xmlFile) { try (FileInputStream fis = new FileInputStream(xmlFile)) { Object obj = xstream.fromXML(fis); if (obj instanceof List) { - List posts = (List) obj; - // Initialize missing fields for existing posts - for (Post post : posts) { - if (post.commentcount == null) { - post.commentcount = "0"; - } - if (post.isLiked == null) { - post.isLiked = "false"; - } - } - return posts; + return (List) obj; } } catch (Exception e) { e.printStackTrace(); } - return new ArrayList<>(); + return null; + } + + /** Ensure required fields are present on loaded posts. */ + private void initializeMissingFields(List posts) { + for (Post post : posts) { + if (post.commentcount == null) post.commentcount = "0"; + if (post.isLiked == null) post.isLiked = "false"; + } } /** diff --git a/src/main/java/com/starlight/util/FXMLVerificator.java b/src/main/java/com/starlight/util/FXMLVerificator.java index ff38743..ac657ba 100644 --- a/src/main/java/com/starlight/util/FXMLVerificator.java +++ b/src/main/java/com/starlight/util/FXMLVerificator.java @@ -11,6 +11,9 @@ * by JavaFX. */ public class FXMLVerificator { + + private FXMLVerificator() {} + private static final Logger logger = Logger.getLogger(FXMLVerificator.class.getName()); // You can customize these diff --git a/src/main/java/com/starlight/util/ImageUtils.java b/src/main/java/com/starlight/util/ImageUtils.java index 1f3da39..5f5752f 100644 --- a/src/main/java/com/starlight/util/ImageUtils.java +++ b/src/main/java/com/starlight/util/ImageUtils.java @@ -13,6 +13,8 @@ * Contains methods for loading and scaling images with proper fallback handling. */ public class ImageUtils { + + private ImageUtils() {} /** Default path to the missing image placeholder */ public static final String DEFAULT_MISSING_IMAGE = "/com/starlight/images/missing.png"; @@ -42,8 +44,10 @@ public static void scaleToFit(ImageView imageView, double frameWidth, double fra double imageAspect = imageWidth / imageHeight; double frameAspect = frameWidth / frameHeight; - double newWidth, newHeight; - double xOffset = 0, yOffset = 0; + double newWidth; + double newHeight; + double xOffset = 0; + double yOffset = 0; // Determine the cropping area if (imageAspect > frameAspect) { diff --git a/src/main/java/com/starlight/util/NutritionParser.java b/src/main/java/com/starlight/util/NutritionParser.java index cfd363a..13c849d 100644 --- a/src/main/java/com/starlight/util/NutritionParser.java +++ b/src/main/java/com/starlight/util/NutritionParser.java @@ -165,7 +165,7 @@ private Nutrition.Protein parseProteinValue(String content, String tagName, Stri /** * Parses fat values from XML content. */ - private Nutrition.Fat parseFatValue(String content, String tagName, String defaultUnit) { + private Nutrition.Fat parseFatValue(String content, String tagName) { Pattern pattern = Pattern.compile("<" + tagName + "\\s+unit=\"([^\"]*?)\"[^>]*>([^<]*)"); Matcher matcher = pattern.matcher(content); @@ -184,7 +184,7 @@ private Nutrition.Fat parseFatValue(String content, String tagName, String defau /** * Parses carbohydrates values from XML content. */ - private Nutrition.Carbohydrates parseCarbohydratesValue(String content, String tagName, String defaultUnit) { + private Nutrition.Carbohydrates parseCarbohydratesValue(String content, String tagName) { Pattern pattern = Pattern.compile("<" + tagName + "\\s+unit=\"([^\"]*?)\"[^>]*>([^<]*)"); Matcher matcher = pattern.matcher(content); @@ -203,7 +203,7 @@ private Nutrition.Carbohydrates parseCarbohydratesValue(String content, String t /** * Parses fiber values from XML content. */ - private Nutrition.Fiber parseFiberValue(String content, String tagName, String defaultUnit) { + private Nutrition.Fiber parseFiberValue(String content, String tagName) { Pattern pattern = Pattern.compile("<" + tagName + "\\s+unit=\"([^\"]*?)\"[^>]*>([^<]*)"); Matcher matcher = pattern.matcher(content); @@ -241,7 +241,7 @@ private Nutrition.Sugar parseSugarValue(String content, String tagName, String d /** * Parses salt values from XML content. */ - private Nutrition.Salt parseSaltValue(String content, String tagName, String defaultUnit) { + private Nutrition.Salt parseSaltValue(String content, String tagName) { Pattern pattern = Pattern.compile("<" + tagName + "\\s+unit=\"([^\"]*?)\"[^>]*>([^<]*)"); Matcher matcher = pattern.matcher(content); diff --git a/src/test/java/com/starlight/api/ChatbotAPITest.java b/src/test/java/com/starlight/api/ChatbotAPITest.java index 2f69744..4aa0490 100644 --- a/src/test/java/com/starlight/api/ChatbotAPITest.java +++ b/src/test/java/com/starlight/api/ChatbotAPITest.java @@ -7,16 +7,16 @@ /** * Test class for ChatbotAPI. */ -public class ChatbotAPITest { +class ChatbotAPITest { @BeforeEach - public void setUp() { + void setUp() { // Note: This test won't actually create the ChatbotAPI since it requires a valid API key // We'll test the structure and error handling instead } @Test - public void testChatbotExceptionCreation() { + void testChatbotExceptionCreation() { // Test exception creation ChatbotAPI.ChatbotException exception = new ChatbotAPI.ChatbotException("Test message"); assertEquals("Test message", exception.getMessage()); @@ -28,7 +28,7 @@ public void testChatbotExceptionCreation() { } @Test - public void testConfigCreation() { + void testConfigCreation() { // Test config object creation ChatbotAPI.Config config = new ChatbotAPI.Config(); assertNull(config.getOpenaiKey()); @@ -38,7 +38,7 @@ public void testConfigCreation() { } @Test - public void testChatbotInitializationWithoutValidKey() { + void testChatbotInitializationWithoutValidKey() { // The ChatbotAPI should initialize successfully ChatbotAPI chatbot = new ChatbotAPI(); @@ -48,7 +48,7 @@ public void testChatbotInitializationWithoutValidKey() { // If we get here, either demo mode is working or API key is configured assertTrue(response.contains("demo mode") || response.contains("configure your OpenAI API key") || - response.length() > 0); // Any non-empty response is acceptable + !response.isEmpty()); // Any non-empty response is acceptable } catch (ChatbotAPI.ChatbotException e) { // This is also acceptable - it means the API key is missing or there's an error assertTrue(e.getMessage().contains("demo mode") || @@ -58,58 +58,62 @@ public void testChatbotInitializationWithoutValidKey() { } @Test - public void testJsonResponseParsing() throws ChatbotAPI.ChatbotException { + void testJsonResponseParsing() throws ChatbotAPI.ChatbotException { // Test the improved JSON parsing with a mock OpenAI API response ChatbotAPI chatbot = new ChatbotAPI(); // Mock OpenAI API response format - String mockResponse = "{\n" + - " \"id\": \"chatcmpl-123\",\n" + - " \"object\": \"chat.completion\",\n" + - " \"created\": 1677652288,\n" + - " \"model\": \"gpt-3.5-turbo\",\n" + - " \"choices\": [\n" + - " {\n" + - " \"index\": 0,\n" + - " \"message\": {\n" + - " \"role\": \"assistant\",\n" + - " \"content\": \"Hello! How can I help you today?\"\n" + - " },\n" + - " \"finish_reason\": \"stop\"\n" + - " }\n" + - " ],\n" + - " \"usage\": {\n" + - " \"prompt_tokens\": 10,\n" + - " \"completion_tokens\": 9,\n" + - " \"total_tokens\": 19\n" + - " }\n" + - "}"; + String mockResponse = """ + { + "id": "chatcmpl-123", + "object": "chat.completion", + "created": 1677652288, + "model": "gpt-3.5-turbo", + "choices": [ + { + "index": 0, + "message": { + "role": "assistant", + "content": "Hello! How can I help you today?" + }, + "finish_reason": "stop" + } + ], + "usage": { + "prompt_tokens": 10, + "completion_tokens": 9, + "total_tokens": 19 + } + } + """; String result = chatbot.parseResponse(mockResponse); assertEquals("Hello! How can I help you today?", result); } @Test - public void testJsonResponseParsingWithEscapedCharacters() throws ChatbotAPI.ChatbotException { + void testJsonResponseParsingWithEscapedCharacters() throws ChatbotAPI.ChatbotException { // Test JSON parsing with escaped characters ChatbotAPI chatbot = new ChatbotAPI(); - String mockResponse = "{\n" + - " \"choices\": [\n" + - " {\n" + - " \"message\": {\n" + - " \"content\": \"Hello! I can help with \\\"nutrition\\\" and \\n food advice.\"\n" + - " }\n" + - " }\n" + - " ]\n" + - "}"; + String mockResponse = """ + { + "choices": [ + { + "message": { + "content": "Hello! I can help with \"nutrition\" and \n food advice." + } + } + ] + } + """; String result = chatbot.parseResponse(mockResponse); assertEquals("Hello! I can help with \"nutrition\" and \n food advice.", result); } @Test - public void testJsonResponseParsingInvalidFormat() { + void testJsonResponseParsingInvalidFormat() { // Test error handling with invalid JSON format ChatbotAPI chatbot = new ChatbotAPI(); @@ -123,20 +127,22 @@ public void testJsonResponseParsingInvalidFormat() { } @Test - public void testNutritionXMLValidationWithVerdict() { + void testNutritionXMLValidationWithVerdict() { // Test that XML validation works with verdict attributes // Test valid XML with verdict attribute (like what the AI returns) - String validResponseWithVerdict = "\n" + - " \n" + - " 100\n" + - " 10\n" + - " 5\n" + - " 15\n" + - " 2\n" + - " 3\n" + - " 200\n" + - " \n" + - ""; + String validResponseWithVerdict = """ + + + 100 + 10 + 5 + 15 + 2 + 3 + 200 + + + """; // This should not throw an exception (simulating internal validation) // Since analyzeNutritionFacts requires API key, we'll test the validation logic indirectly diff --git a/src/test/java/com/starlight/api/UserApiServerTest.java b/src/test/java/com/starlight/api/UserApiServerTest.java index 7acdc2d..a06de3b 100644 --- a/src/test/java/com/starlight/api/UserApiServerTest.java +++ b/src/test/java/com/starlight/api/UserApiServerTest.java @@ -11,7 +11,7 @@ /** * Unit tests for {@link UserApiServer}. */ -public class UserApiServerTest { +class UserApiServerTest { private UserApiServer server; private static final int TEST_PORT = 9000; // Use a different port range to avoid conflicts diff --git a/src/test/java/com/starlight/controller/AuthorizationControllerTest.java b/src/test/java/com/starlight/controller/AuthorizationControllerTest.java index 2becb96..b49c1f4 100644 --- a/src/test/java/com/starlight/controller/AuthorizationControllerTest.java +++ b/src/test/java/com/starlight/controller/AuthorizationControllerTest.java @@ -15,7 +15,7 @@ /** * Unit tests for {@link AuthorizationController}. */ -public class AuthorizationControllerTest extends ApplicationTest { +class AuthorizationControllerTest extends ApplicationTest { private AuthorizationController controller; private BorderPane testPane; diff --git a/src/test/java/com/starlight/controller/ConsultControllerTest.java b/src/test/java/com/starlight/controller/ConsultControllerTest.java index 6d89e00..e4e4c3d 100644 --- a/src/test/java/com/starlight/controller/ConsultControllerTest.java +++ b/src/test/java/com/starlight/controller/ConsultControllerTest.java @@ -9,10 +9,10 @@ /** * Test class for ConsultController avatar path resolution. */ -public class ConsultControllerTest { +class ConsultControllerTest { @Test - public void testAvatarPathResolution() { + void testAvatarPathResolution() { // Test that the avatar paths can be resolved by FileSystemManager String botAvatarPath = "src/main/resources/com/starlight/images/dummy/profilewoman.jpg"; String userAvatarPath = "src/main/resources/com/starlight/images/dummy/profilewoman.jpg"; @@ -32,7 +32,7 @@ public void testAvatarPathResolution() { } @Test - public void testResourcePathFormat() { + void testResourcePathFormat() { // Test that our path format works with the FileSystemManager String resourcePath = "src/main/resources/com/starlight/images/dummy/profilewoman.jpg"; diff --git a/src/test/java/com/starlight/controller/LoadingControllerTest.java b/src/test/java/com/starlight/controller/LoadingControllerTest.java index db2d062..ebe45e0 100644 --- a/src/test/java/com/starlight/controller/LoadingControllerTest.java +++ b/src/test/java/com/starlight/controller/LoadingControllerTest.java @@ -13,7 +13,7 @@ /** * Unit tests for {@link LoadingController}. */ -public class LoadingControllerTest extends ApplicationTest { +LoadingControllerTest extends ApplicationTest { private LoadingController controller; diff --git a/src/test/java/com/starlight/controller/SettingControllerTest.java b/src/test/java/com/starlight/controller/SettingControllerTest.java index 33ea61d..ccdfd7c 100644 --- a/src/test/java/com/starlight/controller/SettingControllerTest.java +++ b/src/test/java/com/starlight/controller/SettingControllerTest.java @@ -17,7 +17,7 @@ /** * Test class for SettingController. */ -public class SettingControllerTest { +class SettingControllerTest { @TempDir Path tempDir; @@ -25,7 +25,7 @@ public class SettingControllerTest { private XStream xstream; @BeforeEach - public void setUp() { + void setUp() { this.xstream = new XStream(new DomDriver()); this.xstream.allowTypesByWildcard(new String[]{"com.starlight.api.*"}); this.xstream.alias("config", ChatbotAPI.Config.class); @@ -33,7 +33,7 @@ public void setUp() { } @Test - public void testConfigCreationAndSerialization() throws Exception { + void testConfigCreationAndSerialization() throws Exception { // Create config object ChatbotAPI.Config config = new ChatbotAPI.Config(); config.setOpenaiKey("test-api-key-123"); @@ -50,7 +50,7 @@ public void testConfigCreationAndSerialization() throws Exception { } @Test - public void testConfigFileCreation() throws Exception { + void testConfigFileCreation() throws Exception { // Create the directory structure Path configDir = tempDir.resolve(".tabemonpal").resolve("Database"); Files.createDirectories(configDir); @@ -72,7 +72,7 @@ public void testConfigFileCreation() throws Exception { } @Test - public void testEmptyApiKeyValidation() { + void testEmptyApiKeyValidation() { ChatbotAPI.Config config = new ChatbotAPI.Config(); assertNull(config.getOpenaiKey()); diff --git a/src/test/java/com/starlight/model/PostDataRepositoryTest.java b/src/test/java/com/starlight/model/PostDataRepositoryTest.java index 294fd38..f682c74 100644 --- a/src/test/java/com/starlight/model/PostDataRepositoryTest.java +++ b/src/test/java/com/starlight/model/PostDataRepositoryTest.java @@ -17,7 +17,7 @@ /** * Unit tests for {@link PostDataRepository}. */ -public class PostDataRepositoryTest { +class PostDataRepositoryTest { private Path tempFile; private PostDataRepository repository; diff --git a/src/test/java/com/starlight/model/PostLikedStateTest.java b/src/test/java/com/starlight/model/PostLikedStateTest.java index 614b882..a200c2e 100644 --- a/src/test/java/com/starlight/model/PostLikedStateTest.java +++ b/src/test/java/com/starlight/model/PostLikedStateTest.java @@ -17,7 +17,7 @@ /** * Test class to verify that liked state is properly saved and loaded from XML. */ -public class PostLikedStateTest { +class PostLikedStateTest { private Path tempFile; private PostDataRepository repository; diff --git a/src/test/java/com/starlight/model/PostTest.java b/src/test/java/com/starlight/model/PostTest.java index 6f6b934..665cd9a 100644 --- a/src/test/java/com/starlight/model/PostTest.java +++ b/src/test/java/com/starlight/model/PostTest.java @@ -8,7 +8,7 @@ /** * Unit tests for {@link Post} data model. */ -public class PostTest { +class PostTest { private Post post; @BeforeEach diff --git a/src/test/java/com/starlight/model/UserDataRepositoryTest.java b/src/test/java/com/starlight/model/UserDataRepositoryTest.java index 2a9f14c..6898917 100644 --- a/src/test/java/com/starlight/model/UserDataRepositoryTest.java +++ b/src/test/java/com/starlight/model/UserDataRepositoryTest.java @@ -17,7 +17,7 @@ /** * Unit tests for {@link UserDataRepository}. */ -public class UserDataRepositoryTest { +class UserDataRepositoryTest { private Path tempFile; private Path tempDummyFile; private UserDataRepository repository; diff --git a/src/test/java/com/starlight/model/UserTest.java b/src/test/java/com/starlight/model/UserTest.java index a83332d..01140fc 100644 --- a/src/test/java/com/starlight/model/UserTest.java +++ b/src/test/java/com/starlight/model/UserTest.java @@ -8,7 +8,7 @@ /** * Unit tests for {@link User} data model. */ -public class UserTest { +class UserTest { private User user; @BeforeEach diff --git a/src/test/java/com/starlight/util/DataRepositoryIntegrationTest.java b/src/test/java/com/starlight/util/DataRepositoryIntegrationTest.java index 7f4f7d7..d7357bb 100644 --- a/src/test/java/com/starlight/util/DataRepositoryIntegrationTest.java +++ b/src/test/java/com/starlight/util/DataRepositoryIntegrationTest.java @@ -10,7 +10,7 @@ /** * Integration test to verify that data repositories work correctly with the new file system. */ -public class DataRepositoryIntegrationTest { +class DataRepositoryIntegrationTest { @BeforeEach void setUp() { diff --git a/src/test/java/com/starlight/util/FXMLLoadingTest.java b/src/test/java/com/starlight/util/FXMLLoadingTest.java index 0946be9..df96814 100644 --- a/src/test/java/com/starlight/util/FXMLLoadingTest.java +++ b/src/test/java/com/starlight/util/FXMLLoadingTest.java @@ -19,7 +19,7 @@ * Tests that all FXML files in the view package can be loaded using FXMLLoader, * including their controllers (if declared), using TestFX in headless mode. */ -public class FXMLLoadingTest extends ApplicationTest { +class FXMLLoadingTest extends ApplicationTest { static { // Enable TestFX headless mode so JavaFX doesn't require a display diff --git a/src/test/java/com/starlight/util/FXMLVerificatorTest.java b/src/test/java/com/starlight/util/FXMLVerificatorTest.java index 1f59644..844df98 100644 --- a/src/test/java/com/starlight/util/FXMLVerificatorTest.java +++ b/src/test/java/com/starlight/util/FXMLVerificatorTest.java @@ -14,7 +14,7 @@ /** * Unit tests for {@link FXMLVerificator} utility class. */ -public class FXMLVerificatorTest { +class FXMLVerificatorTest { private Path tempDir; private Path tempFxmlFile; @@ -38,12 +38,14 @@ void testVerifyAllWithNoFxmlFiles() { @Test void testFxmlWithCorrectNamespace() throws IOException { - String validFxml = "\n" + - "\n" + - " \n" + - " \n" + - ""; + String validFxml = """ + + + + + + """; Files.writeString(tempFxmlFile, validFxml); @@ -53,12 +55,14 @@ void testFxmlWithCorrectNamespace() throws IOException { @Test void testFxmlWithIncorrectNamespace() throws IOException { - String fxmlWithOldNamespace = "\n" + - "\n" + - " \n" + - " \n" + - ""; + String fxmlWithOldNamespace = """ + + + + + + """; Files.writeString(tempFxmlFile, fxmlWithOldNamespace); @@ -74,12 +78,14 @@ void testFxmlWithIllegalAttribute() throws IOException { Path testFxmlFile = resourcesDir.resolve("test_illegal.fxml"); try { - String fxmlWithIllegalAttr = "\n" + - "\n" + - " \n" + - " \n" + - ""; + String fxmlWithIllegalAttr = """ + + + + + + """; Files.writeString(testFxmlFile, fxmlWithIllegalAttr); @@ -99,14 +105,16 @@ void testFxmlWithUnsupportedTag() throws IOException { Path testFxmlFile = resourcesDir.resolve("test_unsupported.fxml"); try { - String fxmlWithUnsupportedTag = "\n" + - "\n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - ""; + String fxmlWithUnsupportedTag = """ + + + + + + + + + """; Files.writeString(testFxmlFile, fxmlWithUnsupportedTag); @@ -120,13 +128,15 @@ void testFxmlWithUnsupportedTag() throws IOException { @Test void testFxmlWithCustomComponents() throws IOException { - String fxmlWithCustom = "\n" + - "\n" + - " \n" + - "