Establish buildable modules and shared host-service boundaries
This commit is contained in:
+70
@@ -0,0 +1,70 @@
|
||||
package de.neitzel.fxdesigner.standalone;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import de.neitzel.fxdesigner.contracts.*;
|
||||
import java.nio.file.*;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
class FileDocumentsTest {
|
||||
@TempDir Path folder;
|
||||
|
||||
@Test
|
||||
void sharedDraftHistorySurvivesClosingOneHandleAndUndoNeverReusesRevision() throws Exception {
|
||||
Path file = folder.resolve("View.fxml");
|
||||
Files.writeString(file, "abcdef");
|
||||
var permissions = Files.getPosixFilePermissions(file);
|
||||
try (var docs = new FileDocuments()) {
|
||||
var a = docs.open(file.toUri()).toCompletableFuture().get();
|
||||
var b = docs.open(file.toUri()).toCompletableFuture().get();
|
||||
var start = a.snapshot().toCompletableFuture().get();
|
||||
var changed =
|
||||
a.apply(
|
||||
new EditBatch(
|
||||
start.revision(),
|
||||
"two edits",
|
||||
List.of(
|
||||
new EditBatch.Replacement(0, 1, "A"),
|
||||
new EditBatch.Replacement(5, 6, "F"))))
|
||||
.toCompletableFuture()
|
||||
.get();
|
||||
assertEquals("AbcdeF", b.snapshot().toCompletableFuture().get().text());
|
||||
a.close();
|
||||
var undone = b.undo().toCompletableFuture().get();
|
||||
assertEquals("abcdef", undone.text());
|
||||
assertTrue(undone.revision() > changed.revision());
|
||||
assertThrows(
|
||||
ExecutionException.class,
|
||||
() ->
|
||||
b.apply(new EditBatch(start.revision(), "stale", List.of()))
|
||||
.toCompletableFuture()
|
||||
.get());
|
||||
var redone = b.redo().toCompletableFuture().get();
|
||||
b.save(redone.revision()).toCompletableFuture().get();
|
||||
assertEquals("AbcdeF", Files.readString(file));
|
||||
assertEquals(permissions, Files.getPosixFilePermissions(file));
|
||||
assertFalse(b.snapshot().toCompletableFuture().get().dirty());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void externalChangeBlocksSaveWithoutLosingDraft() throws Exception {
|
||||
Path file = folder.resolve("View.fxml");
|
||||
Files.writeString(file, "old");
|
||||
try (var docs = new FileDocuments()) {
|
||||
var d = docs.open(file.toUri()).toCompletableFuture().get();
|
||||
var changed =
|
||||
d.apply(new EditBatch(0, "edit", List.of(new EditBatch.Replacement(0, 3, "draft"))))
|
||||
.toCompletableFuture()
|
||||
.get();
|
||||
Files.writeString(file, "external");
|
||||
assertThrows(
|
||||
ExecutionException.class, () -> d.save(changed.revision()).toCompletableFuture().get());
|
||||
assertEquals("external", Files.readString(file));
|
||||
assertEquals("draft", d.snapshot().toCompletableFuture().get().text());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user