diff --git a/1.txt b/1.txt new file mode 100644 index 0000000..e69de29 diff --git a/doc/基于Git的分布式协同开发实验报告.docx b/doc/基于Git的分布式协同开发实验报告.docx new file mode 100644 index 0000000..5610abb Binary files /dev/null and b/doc/基于Git的分布式协同开发实验报告.docx differ diff --git a/src/MementoTest.java b/src/MementoTest.java new file mode 100644 index 0000000..0fc5b65 --- /dev/null +++ b/src/MementoTest.java @@ -0,0 +1,1002 @@ +package net.mooctest; + +import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.fail; + +import java.text.SimpleDateFormat; +import java.util.*; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * + * 开发者做题说明: + * 1、该测试类为测试类示例,不要求完全按照该示例类的格式;考生也可自行创建测试类,类名可自行定义 + * 2、所有测试方法放在该顶层类中,不建议再创建内部类 + * 3、不要修改被测代码 + * 4、提交答案时只提交一个测试类.java文件 + * 5、无论最终的类名是什么,都要保证文件名与类名一致(遵循Java语法),如测试类为MementoTest,则提交时的文件名应为MementoTest.java,否则将因不符合语法而判0分! + * 6、建议尽量避免卡点提交答案 + * + * */ +public class MementoTest { + + private Note note; + private Caretaker caretaker; + private HistoryManager historyManager; + private LabelManager labelManager; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + } + + @AfterClass + public static void tearDownAfterClass() throws Exception { + } + + @Before + public void setUp() throws Exception { + note = new Note("Initial content"); + caretaker = new Caretaker(); + historyManager = new HistoryManager(note); + labelManager = new LabelManager(); + } + + @After + public void tearDown() throws Exception { + } + + @Test + public void testNoteCreation() { + assertEquals("Initial content", note.getContent()); + assertTrue(note.getLabels().isEmpty()); + } + + @Test + public void testNoteContentUpdate() { + note.setContent("Updated content"); + assertEquals("Updated content", note.getContent()); + } + + @Test + public void testNoteMementoCreation() throws MementoException { + Memento memento = note.createMemento(); + assertNotNull(memento); + assertNotNull(memento.getId()); + assertNotNull(memento.getTimestamp()); + assertEquals("Initial content", memento.getState()); + } + + @Test + public void testNoteMementoRestore() throws MementoException { + Memento memento = note.createMemento(); + note.setContent("Modified content"); + note.restoreMemento(memento); + assertEquals("Initial content", note.getContent()); + } + + @Test(expected = MementoException.class) + public void testNoteMementoRestoreWrongType() throws MementoException { + Memento wrongMemento = new Memento() { + @Override + public Object getState() { + return "wrong state"; + } + }; + note.restoreMemento(wrongMemento); + } + + @Test + public void testCaretakerSave() throws MementoException { + Memento memento = note.createMemento(); + caretaker.save(memento); + Memento current = caretaker.getCurrent(); + assertEquals(memento.getId(), current.getId()); + assertEquals(memento.getState(), current.getState()); + } + + @Test + public void testCaretakerUndoRedo() throws MementoException { + // Save initial state + caretaker.save(note.createMemento()); + + // Modify and save new state + note.setContent("Second state"); + caretaker.save(note.createMemento()); + + // Undo to first state + Memento undoMemento = caretaker.undo(); + note.restoreMemento(undoMemento); + assertEquals("Initial content", note.getContent()); + + // Redo to second state + Memento redoMemento = caretaker.redo(); + note.restoreMemento(redoMemento); + assertEquals("Second state", note.getContent()); + } + + @Test(expected = MementoException.class) + public void testCaretakerUndoEmpty() throws MementoException { + caretaker.undo(); + } + + @Test(expected = MementoException.class) + public void testCaretakerRedoEmpty() throws MementoException { + caretaker.redo(); + } + + @Test + public void testCaretakerClear() throws MementoException { + caretaker.save(note.createMemento()); + caretaker.clear(); + + try { + caretaker.getCurrent(); + fail("Should throw exception after clear"); + } catch (MementoException e) { + // Expected + } + } + + @Test + public void testHistoryManagerSave() throws MementoException { + note.setContent("First content"); + historyManager.save(); + + note.setContent("Second content"); + historyManager.save(); + + List history = historyManager.getHistory(); + assertEquals(2, history.size()); + assertEquals("Second content", history.get(1).getState()); + } + + @Test + public void testHistoryManagerUndoRedo() throws MementoException { + note.setContent("First"); + historyManager.save(); + + note.setContent("Second"); + historyManager.save(); + + historyManager.undo(); + assertEquals("First", note.getContent()); + + historyManager.redo(); + assertEquals("Second", note.getContent()); + } + + @Test + public void testHistoryManagerBranching() throws MementoException { + // Save initial state + historyManager.save(); + + // Create branch and switch + historyManager.createBranch("feature"); + historyManager.switchBranch("feature"); + + note.setContent("Feature content"); + historyManager.save(); + + assertEquals("feature", historyManager.getCurrentBranch()); + assertEquals("Feature content", note.getContent()); + } + + @Test(expected = MementoException.class) + public void testHistoryManagerSwitchToNonExistentBranch() throws MementoException { + historyManager.switchBranch("nonexistent"); + } + + @Test + public void testLabelManagement() { + Label label = new Label("Important"); + labelManager.addLabelToNote(label, note); + + assertTrue(note.getLabels().contains(label)); + assertTrue(labelManager.getAllLabels().contains(label)); + + labelManager.removeLabelFromNote(label, note); + assertFalse(note.getLabels().contains(label)); + } + + @Test + public void testLabelGetNotes() { + Label label = new Label("Important"); + Note note2 = new Note("Another note"); + + labelManager.addLabelToNote(label, note); + labelManager.addLabelToNote(label, note2); + + assertEquals(2, labelManager.getNotesByLabel(label).size()); + } + + @Test + public void testNoteWithNullContent() { + Note nullNote = new Note(null); + assertEquals("", nullNote.getContent()); + + nullNote.setContent(null); + assertEquals("", nullNote.getContent()); + } + + @Test + public void testMementoTimestamp() throws InterruptedException { + Memento memento1 = note.createMemento(); + Thread.sleep(10); // Small delay to ensure different timestamps + Memento memento2 = note.createMemento(); + + Date timestamp1 = memento1.getTimestamp(); + Date timestamp2 = memento2.getTimestamp(); + + assertTrue(timestamp2.after(timestamp1)); + } + + @Test + public void testCaretakerHistoryPersistence() throws MementoException { + // Save multiple states + caretaker.save(note.createMemento()); + + note.setContent("State 2"); + caretaker.save(note.createMemento()); + + note.setContent("State 3"); + caretaker.save(note.createMemento()); + + // Verify history size + List history = caretaker.getAllHistory(); + assertEquals(3, history.size()); + + // Verify content of each state + assertEquals("Initial content", history.get(0).getState()); + assertEquals("State 2", history.get(1).getState()); + assertEquals("State 3", history.get(2).getState()); + } + + @Test + public void testHistoryManagerClear() throws MementoException { + historyManager.save(); + historyManager.clearHistory(); + + List history = historyManager.getHistory(); + assertTrue(history.isEmpty()); + } + + @Test + public void testMultipleBranches() throws MementoException { + // Initial state + historyManager.save(); + + // Create multiple branches + historyManager.createBranch("branch1"); + historyManager.createBranch("branch2"); + + List branches = historyManager.getAllBranches(); + assertTrue(branches.contains("main")); + assertTrue(branches.contains("branch1")); + assertTrue(branches.contains("branch2")); + assertEquals(3, branches.size()); + } + + @Test + public void testLabelEquality() { + Label label1 = new Label("Important"); + Label label2 = new Label("Important"); + Label label3 = new Label("Urgent"); + + // Labels with same name should be equal + assertEquals(label1, label2); + assertNotEquals(label1, label3); + } + + @Test + public void testNoteLabelOperations() { + Label label1 = new Label("Work"); + Label label2 = new Label("Personal"); + + note.addLabel(label1); + note.addLabel(label2); + + assertEquals(2, note.getLabels().size()); + + note.removeLabel(label1); + assertEquals(1, note.getLabels().size()); + assertTrue(note.getLabels().contains(label2)); + } + + @Test + public void testNullLabelHandling() { + // Adding null label should be ignored + note.addLabel(null); + assertTrue(note.getLabels().isEmpty()); + + // Removing null label should not cause exception + note.removeLabel(null); + } + + @Test + public void testCalendarManager() { + CalendarManager calendarManager = new CalendarManager(); + Date date = new Date(); + + calendarManager.addNoteByDate(note, date); + List notesByDay = calendarManager.getNotesByDay(date); + assertEquals(1, notesByDay.size()); + assertEquals(note, notesByDay.get(0)); + + List notesByMonth = calendarManager.getNotesByMonth(date); + assertEquals(1, notesByMonth.size()); + assertEquals(note, notesByMonth.get(0)); + } + + @Test + public void testCalendarManagerReminder() { + CalendarManager.Reminder reminder = new CalendarManager.Reminder(note, new Date()); + assertNotNull(reminder.getNote()); + assertNotNull(reminder.getRemindTime()); + assertFalse(reminder.isTriggered()); + + reminder.setTriggered(true); + assertTrue(reminder.isTriggered()); + } + + @Test(expected = IllegalArgumentException.class) + public void testCalendarManagerReminderNullArgs() { + new CalendarManager.Reminder(null, null); + } + + @Test + public void testNoteEncryptor() { + String original = "Test content"; + String encrypted = NoteEncryptor.encrypt(original); + String decrypted = NoteEncryptor.decrypt(encrypted); + + assertNotNull(encrypted); + assertEquals(original, decrypted); + assertNotEquals(original, encrypted); + } + + @Test + public void testNoteEncryptorNull() { + assertNull(NoteEncryptor.encrypt(null)); + assertNull(NoteEncryptor.decrypt(null)); + } + + @Test + public void testNoteDiffUtil() { + String oldContent = "Line 1\nLine 2\nLine 3"; + String newContent = "Line 1\nModified Line 2\nLine 3"; + + String diff = NoteDiffUtil.diff(oldContent, newContent); + assertNotNull(diff); + assertTrue(diff.contains("-")); + assertTrue(diff.contains("+")); + } + + @Test + public void testNoteDiffUtilNull() { + String diff1 = NoteDiffUtil.diff(null, "test"); + String diff2 = NoteDiffUtil.diff("test", null); + String diff3 = NoteDiffUtil.diff(null, null); + + assertNotNull(diff1); + assertNotNull(diff2); + assertNotNull(diff3); + } + + @Test + public void testUserManagement() { + UserManager userManager = new UserManager(); + User user = userManager.registerUser("testuser"); + + assertEquals("testuser", user.getName()); + assertTrue(user.getNotes().isEmpty()); + + user.addNote(note); + assertEquals(1, user.getNotes().size()); + assertEquals(note, user.getNotes().get(0)); + + HistoryManager historyManager = user.getHistoryManager(note); + assertNotNull(historyManager); + + user.removeNote(note); + assertTrue(user.getNotes().isEmpty()); + assertNull(user.getHistoryManager(note)); + } + + @Test(expected = IllegalArgumentException.class) + public void testUserCreationInvalidName() { + new User(null); + } + + @Test(expected = IllegalArgumentException.class) + public void testUserCreationEmptyName() { + new User(" "); + } + + @Test(expected = IllegalArgumentException.class) + public void testUserManagerDuplicateRegistration() { + UserManager userManager = new UserManager(); + userManager.registerUser("testuser"); + userManager.registerUser("testuser"); // Should throw exception + } + + @Test + public void testUserManagerGetAndRemove() { + UserManager userManager = new UserManager(); + User user = userManager.registerUser("testuser"); + + User retrieved = userManager.getUser("testuser"); + assertEquals(user, retrieved); + + userManager.removeUser("testuser"); + assertNull(userManager.getUser("testuser")); + assertEquals(0, userManager.getAllUsers().size()); + } + + @Test + public void testPermissionManagement() { + User user = new User("testuser"); + PermissionManager permissionManager = new PermissionManager(); + + permissionManager.grantPermission(user, Permission.EDIT); + assertEquals(Permission.EDIT, permissionManager.getPermission(user)); + + assertTrue(permissionManager.canEdit(user)); + assertTrue(permissionManager.canView(user)); + + permissionManager.revokePermission(user); + assertNull(permissionManager.getPermission(user)); + assertFalse(permissionManager.canEdit(user)); + assertFalse(permissionManager.canView(user)); + } + + @Test + public void testPermissionManagerNullHandling() { + PermissionManager permissionManager = new PermissionManager(); + + // Should not throw exception + permissionManager.grantPermission(null, null); + permissionManager.revokePermission(null); + + assertNull(permissionManager.getPermission(null)); + assertFalse(permissionManager.canEdit(null)); + assertFalse(permissionManager.canView(null)); + } + + @Test + public void testPermissionManagerCollaborators() { + User user1 = new User("user1"); + User user2 = new User("user2"); + PermissionManager permissionManager = new PermissionManager(); + + permissionManager.grantPermission(user1, Permission.VIEW); + permissionManager.grantPermission(user2, Permission.EDIT); + + Set collaborators = permissionManager.listCollaborators(); + assertEquals(2, collaborators.size()); + assertTrue(collaborators.contains(user1)); + assertTrue(collaborators.contains(user2)); + } + + @Test + public void testPermissionEnum() { + Permission[] permissions = Permission.values(); + assertEquals(3, permissions.length); + + Permission owner = Permission.valueOf("OWNER"); + Permission edit = Permission.valueOf("EDIT"); + Permission view = Permission.valueOf("VIEW"); + + assertEquals(Permission.OWNER, owner); + assertEquals(Permission.EDIT, edit); + assertEquals(Permission.VIEW, view); + } + + @Test + public void testNoteStatusEnum() { + NoteStatus[] statuses = NoteStatus.values(); + assertEquals(4, statuses.length); + + NoteStatus active = NoteStatus.valueOf("ACTIVE"); + NoteStatus locked = NoteStatus.valueOf("LOCKED"); + NoteStatus archived = NoteStatus.valueOf("ARCHIVED"); + NoteStatus deleted = NoteStatus.valueOf("DELETED"); + + assertEquals(NoteStatus.ACTIVE, active); + assertEquals(NoteStatus.LOCKED, locked); + assertEquals(NoteStatus.ARCHIVED, archived); + assertEquals(NoteStatus.DELETED, deleted); + } + + @Test + public void testLabelHierarchy() { + Label parent = new Label("Parent"); + Label child = new Label("Child", parent); + + assertEquals("Parent", parent.getName()); + assertEquals("Child", child.getName()); + assertEquals(parent, child.getParent()); + assertEquals("Parent/Child", child.getFullPath()); + + assertTrue(parent.getChildren().contains(child)); + } + + @Test(expected = IllegalArgumentException.class) + public void testLabelCreationInvalidName() { + new Label(null); + } + + @Test(expected = IllegalArgumentException.class) + public void testLabelCreationEmptyName() { + new Label(" "); + } + + @Test + public void testLabelToStringAndHashCode() { + Label label1 = new Label("Test"); + Label label2 = new Label("Test"); + Label label3 = new Label("Different"); + + assertEquals("Test", label1.toString()); + assertEquals(label1.hashCode(), label2.hashCode()); + assertNotEquals(label1.hashCode(), label3.hashCode()); + } + + @Test + public void testSearchService() { + User user = new User("testuser"); + user.addNote(note); + + Label label = new Label("Important"); + note.addLabel(label); + + SearchService searchService = new SearchService(); + + // Test search by label + List labelResults = searchService.searchByLabel(user, label); + assertEquals(1, labelResults.size()); + assertEquals(note, labelResults.get(0)); + + // Test search by keyword + List keywordResults = searchService.searchByKeyword(user, "Initial"); + assertEquals(1, keywordResults.size()); + assertEquals(note, keywordResults.get(0)); + + // Test fuzzy search + List fuzzyResults = searchService.fuzzySearch(user, "initial"); + assertEquals(1, fuzzyResults.size()); + assertEquals(note, fuzzyResults.get(0)); + + // Test highlight + String highlighted = searchService.highlight("This is initial content", "initial"); + assertEquals("This is [[initial]] content", highlighted); + } + + @Test + public void testSearchServiceNullHandling() { + SearchService searchService = new SearchService(); + User user = new User("testuser"); + + // Should not throw exceptions + List results1 = searchService.searchByLabel(user, null); + List results2 = searchService.searchByKeyword(user, null); + List results3 = searchService.fuzzySearch(user, null); + String highlighted = searchService.highlight(null, null); + + assertTrue(results1.isEmpty()); + assertTrue(results2.isEmpty()); + assertTrue(results3.isEmpty()); + assertNull(highlighted); + } + + @Test + public void testSearchServiceMultipleUsers() { + User user1 = new User("user1"); + User user2 = new User("user2"); + + Note note1 = new Note("User1 content"); + Note note2 = new Note("User2 content"); + + user1.addNote(note1); + user2.addNote(note2); + + SearchService searchService = new SearchService(); + List users = Arrays.asList(user1, user2); + + List results = searchService.searchByKeywordAllUsers(users, "content"); + assertEquals(2, results.size()); + } + + @Test + public void testMementoException() { + MementoException exception1 = new MementoException("Test message"); + MementoException exception2 = new MementoException("Test message", new RuntimeException("Cause")); + + assertEquals("Test message", exception1.getMessage()); + assertEquals("Test message", exception2.getMessage()); + assertNotNull(exception2.getCause()); + } + + @Test + public void testMementoAbstractClass() { + // Test that Memento is abstract and cannot be instantiated + assertTrue(java.lang.reflect.Modifier.isAbstract(Memento.class.getModifiers())); + } + + @Test + public void testOriginatorInterface() { + // Test that Originator is an interface + assertTrue(Originator.class.isInterface()); + } + + @Test + public void testComprehensiveScenario() { + // Comprehensive test covering multiple components working together + UserManager userManager = new UserManager(); + User user = userManager.registerUser("comprehensive_user"); + + // Create notes with different content + Note note1 = new Note("First note with important content"); + Note note2 = new Note("Second note with urgent content"); + + user.addNote(note1); + user.addNote(note2); + + // Add labels + Label important = new Label("Important"); + Label urgent = new Label("Urgent"); + + note1.addLabel(important); + note2.addLabel(urgent); + + // Test history management + HistoryManager history1 = user.getHistoryManager(note1); + HistoryManager history2 = user.getHistoryManager(note2); + + note1.setContent("Modified first note"); + history1.save(); + + note2.setContent("Modified second note"); + history2.save(); + + // Test search functionality + SearchService searchService = new SearchService(); + List importantNotes = searchService.searchByLabel(user, important); + List urgentNotes = searchService.searchByLabel(user, urgent); + List modifiedNotes = searchService.searchByKeyword(user, "Modified"); + + assertEquals(1, importantNotes.size()); + assertEquals(1, urgentNotes.size()); + assertEquals(2, modifiedNotes.size()); + + // Test calendar integration + CalendarManager calendarManager = new CalendarManager(); + Date today = new Date(); + calendarManager.addNoteByDate(note1, today); + calendarManager.addNoteByDate(note2, today); + + List todaysNotes = calendarManager.getNotesByDay(today); + assertEquals(2, todaysNotes.size()); + + // Test encryption + String encrypted = NoteEncryptor.encrypt("Sensitive content"); + String decrypted = NoteEncryptor.decrypt(encrypted); + assertEquals("Sensitive content", decrypted); + } + + @Test + public void testEdgeCases() { + // Test various edge cases + + // Empty note content + Note emptyNote = new Note(""); + assertEquals("", emptyNote.getContent()); + + // Very long content + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < 10000; i++) { + sb.append("x"); + } + String longContent = sb.toString(); + Note longNote = new Note(longContent); + assertEquals(longContent, longNote.getContent()); + + // Special characters in content + String specialContent = "Content with \n newline and \t tab"; + Note specialNote = new Note(specialContent); + assertEquals(specialContent, specialNote.getContent()); + + // Test diff with special characters + String diff = NoteDiffUtil.diff("Line1\nLine2", "Line1\nModified"); + assertNotNull(diff); + } + + @Test + public void testPerformanceScenarios() { + // Test scenarios that might have performance implications + + // Multiple undo/redo operations + for (int i = 0; i < 100; i++) { + note.setContent("Content " + i); + caretaker.save(note.createMemento()); + } + + // Verify we can undo all the way back + for (int i = 99; i >= 0; i--) { + try { + caretaker.undo(); + note.restoreMemento(caretaker.getCurrent()); + assertEquals("Content " + i, note.getContent()); + } catch (MementoException e) { + fail("Should not throw exception during undo"); + } + } + } + + // Plugin and PluginManager Tests + @Test + public void testPluginManagerRegisterAndGetPlugins() { + PluginManager pluginManager = new PluginManager(); + Plugin mockPlugin = new Plugin() { + @Override + public String getName() { + return "Mock Plugin"; + } + + @Override + public void execute(UserManager userManager) { + // Mock implementation + } + }; + + pluginManager.register(mockPlugin); + assertEquals(1, pluginManager.getPlugins().size()); + assertTrue(pluginManager.getPlugins().contains(mockPlugin)); + } + + @Test + public void testPluginManagerRegisterNull() { + PluginManager pluginManager = new PluginManager(); + pluginManager.register(null); + assertEquals(0, pluginManager.getPlugins().size()); + } + + @Test + public void testPluginManagerExecuteAll() { + PluginManager pluginManager = new PluginManager(); + final boolean[] executed = {false}; + Plugin mockPlugin = new Plugin() { + @Override + public String getName() { + return "Mock Plugin"; + } + + @Override + public void execute(UserManager userManager) { + executed[0] = true; + } + }; + + pluginManager.register(mockPlugin); + pluginManager.executeAll(new UserManager()); + assertTrue(executed[0]); + } + + // RecycleBin Tests + @Test + public void testRecycleBinRecycleAndRestore() { + RecycleBin recycleBin = new RecycleBin(); + Note note = new Note("Test note"); + + recycleBin.recycle(note); + assertTrue(recycleBin.isInBin(note)); + + boolean restored = recycleBin.restore(note); + assertTrue(restored); + assertFalse(recycleBin.isInBin(note)); + } + + @Test + public void testRecycleBinRecycleNull() { + RecycleBin recycleBin = new RecycleBin(); + recycleBin.recycle(null); + assertEquals(0, recycleBin.listDeletedNotes().size()); + } + + @Test + public void testRecycleBinRestoreNonExistent() { + RecycleBin recycleBin = new RecycleBin(); + Note note = new Note("Test note"); + boolean restored = recycleBin.restore(note); + assertFalse(restored); + } + + @Test + public void testRecycleBinClear() { + RecycleBin recycleBin = new RecycleBin(); + Note note1 = new Note("Test note 1"); + Note note2 = new Note("Test note 2"); + + recycleBin.recycle(note1); + recycleBin.recycle(note2); + assertEquals(2, recycleBin.listDeletedNotes().size()); + + recycleBin.clear(); + assertEquals(0, recycleBin.listDeletedNotes().size()); + } + + @Test + public void testRecycleBinListDeletedNotes() { + RecycleBin recycleBin = new RecycleBin(); + Note note1 = new Note("Test note 1"); + Note note2 = new Note("Test note 2"); + + recycleBin.recycle(note1); + recycleBin.recycle(note2); + + Set deletedNotes = recycleBin.listDeletedNotes(); + assertEquals(2, deletedNotes.size()); + assertTrue(deletedNotes.contains(note1)); + assertTrue(deletedNotes.contains(note2)); + } + + // RuleEngine Tests + @Test + public void testRuleEngineAddRuleAndGetRules() { + RuleEngine ruleEngine = new RuleEngine(); + RuleEngine.Rule mockRule = new RuleEngine.Rule() { + @Override + public void apply(Note note, UserManager userManager) { + // Mock implementation + } + }; + + ruleEngine.addRule(mockRule); + assertEquals(1, ruleEngine.getRules().size()); + assertTrue(ruleEngine.getRules().contains(mockRule)); + } + + @Test + public void testRuleEngineAddNullRule() { + RuleEngine ruleEngine = new RuleEngine(); + ruleEngine.addRule(null); + assertEquals(0, ruleEngine.getRules().size()); + } + + @Test + public void testRuleEngineApplyAll() { + RuleEngine ruleEngine = new RuleEngine(); + final boolean[] applied = {false}; + RuleEngine.Rule mockRule = new RuleEngine.Rule() { + @Override + public void apply(Note note, UserManager userManager) { + applied[0] = true; + } + }; + + ruleEngine.addRule(mockRule); + ruleEngine.applyAll(new Note("Test"), new UserManager()); + assertTrue(applied[0]); + } + + // LabelSuggestionService Tests + @Test + public void testLabelSuggestionService() { + LabelSuggestionService suggestionService = new LabelSuggestionService(); + Note note = new Note("This note contains Important and Urgent keywords"); + Collection