Файли
openidea/src/editor/refactor/extractInterface.test.ts
T
l0ng-ai 4561ae05b2 feat(refactor): Extract Interface for Java classes (#3707)
Refactor > Extract Interface… (also in Refactor This) opens a dialog for the class of the current Java file: interface name, package and members. jdtls checks the extraction and computes the edit, which creates the interface, makes the class implement it and uses it where possible; the new file opens afterwards.
2026-11-16 15:50:27 +08:00

30 рядки
1.6 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { interfaceProblem, memberLabel, packageChoices } from "./extractInterface";
describe("extract interface", () => {
it("labels methods with their parameter types and fields with their type", () => {
const m = { name: "area", typeName: "double", parameters: ["int", "String"], handleIdentifier: "m" };
expect(memberLabel(m)).toBe("area(int, String): double");
expect(memberLabel({ ...m, parameters: [] })).toBe("area(): double");
expect(memberLabel({ name: "UNIT", typeName: "int", parameters: null, handleIdentifier: "f" })).toBe("UNIT: int");
});
it("keeps each package's server JSON and marks the file's own package", () => {
const json = [
JSON.stringify({ displayName: "com.a", path: "src/com/a", isParentOfSelectedFile: true }),
JSON.stringify({ displayName: "", path: "src" }),
];
const [own, root] = packageChoices(json);
expect(own).toMatchObject({ name: "com.a", current: true, json: json[0] });
expect(root).toMatchObject({ name: "(default package)", current: false });
});
it("needs a valid name other than the class's and at least one member", () => {
expect(interfaceProblem("", "Shape", 1)).toBe("No interface name specified");
expect(interfaceProblem("1x", "Shape", 1)).toBe("Interface name is not a valid identifier");
expect(interfaceProblem("Shape", "Shape", 1)).toBe("Interface name should differ from the class name");
expect(interfaceProblem("HasArea", "Shape", 0)).toBe("Select the members to form the interface");
expect(interfaceProblem("HasArea", "Shape", 2)).toBeNull();
});
});