-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from bia-technologies/feature/27
27 / Генерация моков для метода
- Loading branch information
Showing
19 changed files
with
437 additions
and
77 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
viewer/src/main/java/ru/biatech/edt/junit/ui/editor/EditionContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 BIA-Technologies Limited Liability Company. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*******************************************************************************/ | ||
|
||
package ru.biatech.edt.junit.ui.editor; | ||
|
||
import com._1c.g5.v8.dt.bsl.model.Module; | ||
import com._1c.g5.v8.dt.bsl.ui.editor.BslXtextDocument; | ||
import com._1c.g5.v8.dt.core.platform.IV8Project; | ||
import lombok.Data; | ||
import org.eclipse.text.edits.InsertEdit; | ||
import org.eclipse.text.edits.ReplaceEdit; | ||
import org.eclipse.text.edits.TextEdit; | ||
import org.eclipse.xtext.parser.IParser; | ||
import org.eclipse.xtext.ui.editor.XtextEditor; | ||
import ru.biatech.edt.junit.v8utils.Projects; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
|
||
@Data | ||
public class EditionContext { | ||
private final XtextEditor editor; | ||
private final BslXtextDocument document; | ||
private final Module module; | ||
private final IV8Project project; | ||
private final List<TextEdit> changes = new ArrayList<>(); | ||
private IParser parser; | ||
|
||
public EditionContext(XtextEditor editor) { | ||
this.editor = editor; | ||
document = EditorHelper.getDocument(editor); | ||
module = EditorHelper.getParsedModule(document); | ||
project = Projects.getParentProject(module); | ||
} | ||
|
||
public IParser getParser() { | ||
if (parser == null) { | ||
document.readOnly(state -> parser = state.getParser()); | ||
} | ||
return parser; | ||
} | ||
|
||
public void insert(int offset, String text) { | ||
changes.add(new InsertEdit(offset, text)); | ||
} | ||
|
||
public void replace(int offset, int length, String content) { | ||
changes.add(new ReplaceEdit(offset, length, content)); | ||
} | ||
|
||
public void append(String text) { | ||
changes.add(new InsertEdit(document.getLength(), text)); | ||
} | ||
|
||
public int lastOffset() { | ||
var ordered = changes.stream() | ||
.sorted(Comparator.comparingInt(TextEdit::getOffset)) | ||
.toArray(TextEdit[]::new); | ||
return ordered[ordered.length - 1].getOffset() + 2; | ||
|
||
} | ||
|
||
public boolean apply() { | ||
return EditorHelper.applyChanges(document, changes); | ||
} | ||
|
||
public void revealLast() { | ||
editor.selectAndReveal(lastOffset(), 0); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
viewer/src/main/java/ru/biatech/edt/junit/ui/testitemaction/GenerateMock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024 BIA-Technologies Limited Liability Company. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*******************************************************************************/ | ||
|
||
package ru.biatech.edt.junit.ui.testitemaction; | ||
|
||
import com._1c.g5.v8.dt.bsl.model.Module; | ||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.jface.viewers.StyledString; | ||
import org.eclipse.swt.graphics.Image; | ||
import ru.biatech.edt.junit.TestViewerPlugin; | ||
import ru.biatech.edt.junit.ui.viewsupport.ImageProvider; | ||
import ru.biatech.edt.junit.ui.viewsupport.LabelStylerFactory; | ||
import ru.biatech.edt.junit.yaxunit.MockCreator; | ||
|
||
import java.text.MessageFormat; | ||
|
||
public class GenerateMock implements ITestItemAction { | ||
private final Module module; | ||
private final String methodName; | ||
|
||
public GenerateMock(Module module, String methodName) { | ||
this.module = module; | ||
this.methodName = methodName; | ||
} | ||
|
||
@Override | ||
public String getPresent() { | ||
return INDENT + MessageFormat.format(Messages.GenerateMock_Present, methodName); | ||
} | ||
|
||
@Override | ||
public Image getIcon(ImageProvider provider) { | ||
return provider.getActionNewMock(); | ||
} | ||
|
||
@Override | ||
public StyledString getStyledString() { | ||
return LabelStylerFactory.format(INDENT + Messages.GenerateMock_Present, StyledString.COUNTER_STYLER, methodName); | ||
} | ||
|
||
@Override | ||
public void run() { | ||
var creator = new MockCreator(module, methodName); | ||
|
||
try { | ||
creator.createMock(); | ||
} catch (CoreException e) { | ||
TestViewerPlugin.log().logError("Не удалось создать мок", e); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.