我想模拟一个scala伴侣对象,所以我试图使用PowerMockito.我有以下内容:
import org.junit.runner.RunWith
import org.mockito.Mockito.when
import org.powermock.core.classloader.annotations.PrepareForTest
import org.powermock.modules.junit4.PowerMockRunner
import org.powermock.api.mockito.PowerMockito._
@RunWith(classOf[PowerMockRunner])
@PrepareForTest(Array(classOf[ClassToMock]))
class Test {
describe("test") {
it("test") {
mockStatic(classOf[ClassToMock])
when(ClassToMock.apply()).thenReturn(null)
}
}
Run Code Online (Sandbox Code Playgroud)
运行测试时,我收到以下错误:
The class path.to.ClassToMock not prepared for test.
To prepare this class, add class to the '@PrepareForTest' annotation.
In case if you don't use this annotation, add the annotation on class or method level.
org.powermock.api.mockito.ClassNotPreparedException:
Run Code Online (Sandbox Code Playgroud)
关于如何设法使注释工作的任何想法?
谢谢!!
我正在尝试在 jinja 模板中创建 bash 脚本。我有以下几行:
SOME_ARRAY_COUNT=${#SOME_ARRAY[@]}
Run Code Online (Sandbox Code Playgroud)
但它会抛出一个错误:
AnsibleError: template error while templating string: Missing end of comment tag
Run Code Online (Sandbox Code Playgroud)
经过调查,我发现{% raw %}...{% endraw %}可以使用块来获取文字,但它仍然无法{#获得类似的错误:
An unhandled exception occurred while templating
Error was a <class 'ansible.errors.AnsibleError'>, original message: template error while templating string: Missing end of comment tag
Run Code Online (Sandbox Code Playgroud)
有没有解决这个问题而不改变 bash 逻辑的方法?
谢谢
更新:包括示例
Ansible 剧本:
... more ansible playbook stuff ...
tasks:
- name: create script
template:
src: "src/path/to/script.sh.j2"
dest: "dest/path/to/output/script.sh"
- name: user data script as string …Run Code Online (Sandbox Code Playgroud)