mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 14:23:28 +07:00
29 lines
1.5 KiB
Java
29 lines
1.5 KiB
Java
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
|
package com.intellij.modcommand;
|
|
|
|
import com.intellij.codeInsight.intention.preview.IntentionPreviewInfo;
|
|
import com.intellij.openapi.fileTypes.UserBinaryFileType;
|
|
import com.intellij.openapi.vfs.VirtualFile;
|
|
import com.intellij.testFramework.LightPlatformCodeInsightTestCase;
|
|
|
|
import java.io.IOException;
|
|
|
|
public final class ModCommandTest extends LightPlatformCodeInsightTestCase {
|
|
public void testBinaryFile() throws IOException {
|
|
configureFromFileText("dummy.txt", "");
|
|
VirtualFile root = getSourceRoot();
|
|
FutureVirtualFile futureFile = new FutureVirtualFile(root, "test.dat", UserBinaryFileType.INSTANCE);
|
|
byte[] content = {'h', 'e', 'l', 'l', 'o'};
|
|
ModCreateFile command = new ModCreateFile(futureFile, new ModCreateFile.Binary(content));
|
|
ModCommandExecutor executor = ModCommandExecutor.getInstance();
|
|
ActionContext context = ActionContext.from(null, getFile());
|
|
IntentionPreviewInfo preview = executor.getPreview(command, context);
|
|
assertEquals(new IntentionPreviewInfo.CustomDiff(UserBinaryFileType.INSTANCE, "test.dat", "", "(binary content)", true), preview);
|
|
ModCommandExecutor.BatchExecutionResult result = executor.executeInBatch(context, command);
|
|
assertEquals(ModCommandExecutor.Result.SUCCESS, result);
|
|
VirtualFile child = root.findChild("test.dat");
|
|
assertNotNull(child);
|
|
assertOrderedEquals(content, child.contentsToByteArray());
|
|
}
|
|
}
|