Method to set the <code>I${enclosing_type}</code> implementation that this class will use.
*
* @param ${enclosing_method_arguments}<code>I${enclosing_type}</code> instance
java.io.FileOutputStream fos = new java.io.FileOutputStream( new java.io.File("c:\\x.x"));
fos.write(buffer.toString().getBytes());
fos.flush();
fos.close();
if (${varName} == null) {
throw new NullPointerException(
"Illegal argument. The argument cannot be null: ${varName}");
}
${varName} = ${varName}.trim();
if (${varName}.isEmpty()) {
throw new IllegalArgumentException(
"Illegal argument. The argument cannot be an empty string: ${varName}");
}
if (${varName} == null) {
throw new NullPointerException(
"Illegal argument. The argument cannot be null: ${varName}");
}
if (${varName}.trim().isEmpty()) {
throw new IllegalArgumentException(
"Illegal argument. The argument cannot be an empty string: ${varName}");
}
if (${varName} == null) {
throw new IllegalStateException(
"Illegal state. The variable or class field cannot be null: ${varName}");
}
testNullOrEmptyStringFieldState
if (${varName} == null) {
throw new IllegalStateException(
"Illegal state. The variable or class field cannot be null: ${varName}");
}
${varName} = ${varName}.trim();
if (${varName}.isEmpty()) {
throw new IllegalStateException(
"Illegal state. The variable or class field " +
"cannot be an empty string: ${varName}");
}
${:import(javax.swing.SwingUtilities)}
// Ensure that any Swing components will be invoked only from the AWT thread
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
${line_selection}${cursor}
}
});
因此,我可以突出显示违规语句,并使用转变 + Alt + Z来包围。我称这个模板为swinvoke。
这个模板将在一个类上创建一个新的测试方法,遵循注释上的行为驱动开发 (BDD)范例中的给定-何时-然后接近,作为构建代码的指南。它将以“should”开始方法名称,并允许您用测试方法职责的最佳描述替换其余的虚拟方法名称“CheckThisAndThat”。在填写名称后,TAB将直接带您到// Given section,因此您可以开始输入先决条件。
我把它映射到三个字母“tst”,描述为“测试方法应该在什么时候给出”;)
我希望你能像我看到它时一样觉得它很有用:
@Test
public void should${CheckThisAndThat}() {
Assert.fail("Not yet implemented");
// Given
${cursor}
// When
// Then
}${:import(org.junit.Test, org.junit.Assert)}
${imports:import(org.eclipse.swt.widgets.Listener)}
private class ${className} implements Listener{
@Override
public void handleEvent(Event e) {
final Widget w = e.widget;
}
}