在BundleProcessorTest.java中的以下两个测试用例中,我得到的是异常,但是,我的第一个测试用例成功通过了.
org.mockito.exceptions.misusing.InvalidUseOfMatchersException:此处检测到错位的参数匹配器:
- > at bundle.test.BundleProcessorTest.bundlePluginShouldNotBeNull(BundleProcessorTest.java:22)
您不能在验证或存根之外使用参数匹配器.正确使用参数匹配器的示例:when(mock.get(anyInt())).thenReturn(null); doThrow(new RuntimeException()).when(mock).someVoidMethod(anyObject()); 验证(模拟).someMethod(包含( "富"))
此外,此错误可能会显示,因为您使用参数匹配器与无法模拟的方法.以下方法无法进行存根/验证:final/private/equals()/ hashCode().
at the package.test.BundleProcessorTest.bundlePluginCollectionShouldNotBeNull(BundleProcessorTest.java:28)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
请在下面找到简化的代码清单: -
BundlePlugin.java
package bundle;
import java.util.List;
public class BundlePlugin {
private final String pluginName ;
private final List<String> featureContent ;
public BundlePlugin(String pluginName, List<String> featureContent) {
super();
this.pluginName = pluginName;
this.featureContent = featureContent;
}
public String getPluginName() {
return pluginName;
}
public List<String> getFeatureContent() {
return featureContent;
}
}
Run Code Online (Sandbox Code Playgroud)
BundleProcessor.java
package bundle;
import java.util.ArrayList;
import …Run Code Online (Sandbox Code Playgroud) 为什么不能在scala中覆盖可变变量?
class Abs(var name: String){
}
class AbsImpl(override var name: String) extends Abs(name){
}
Run Code Online (Sandbox Code Playgroud)
上面的代码给出了以下编译时错误: -
variable name cannot override a mutable variable
如果name声明为val,那么上面的代码工作正常.
我正在努力找出一些示例来从插件触发hudson.model.Job:
private void triggerPipelineJobs(){
for (Job<?,?> job : Jenkins.getInstance().getAllItems(Job.class)) {
System.out.println("job is : " + job.getName());
//how to trigger this jenkins pipeline job
}
}
Run Code Online (Sandbox Code Playgroud) 我的客户端是一个Web浏览器,并使用此url向myserver发送请求:
http://localhost
这是服务器端代码.问题在于ServingThread类的run方法.
class ServingThread implements Runnable{
private Socket socket ;
public ServingThread(Socket socket){
this.socket = socket ;
System.out.println("Receives a new browser request from "
+ socket + "\n\n");
}
public void run() {
PrintWriter out = null ;
try {
String str = "" ;
out = new PrintWriter( socket.getOutputStream() ) ;
out.write("This a web-page.") ;
// :-(
out.flush() ;
// :-(
socket.close() ;
System.out.println("Request successfully fulfilled.") ;
} catch (IOException io) {
System.out.println(io.getMessage());
}
}
} …Run Code Online (Sandbox Code Playgroud) 我已经完成了以下教程:
http://www.javaworld.com/community/node/2915
在阅读完上面的文章之后,我觉得,编写Marker接口是不可能的,因为,如何指导编译器,它是什么标记,它嵌入到Marker接口的.class文件中.
如果我错了,请纠正我.欢呼:)
我正在阅读以下有关java中弱引用的帖子: -
在完成理论部分之后,尝试测试无效条件的弱引用.但是,对于弱引用的null检查永远不会在以下代码中返回true: -
package com.weak;
import java.lang.ref.WeakReference;
class Widget{}
public class WeakReferenceDemo {
public static void main(String[] args) throws InterruptedException {
Widget widget = new Widget() ;
WeakReference<Widget> valueWrapper = new WeakReference<Widget>(widget) ;
System.out.println( valueWrapper.get() );
//here strong reference to object is lost
widget = null ;
int count = 0 ;
//here checking for null condition
while( valueWrapper.get() != null ){
System.out.print(".");
Thread.sleep(432) ;
if(++count % 25 == 0) System.out.println();
} …Run Code Online (Sandbox Code Playgroud) 我是scala和实用的新手,正在尝试学习应用程序。
val o1 = Some(1)
val o2 = Some(2)
val o3 = Some(3)
val result = (o1 |@| o2 |@| o3) {_ + _ + _}
Run Code Online (Sandbox Code Playgroud)
有一个关于Applicatives和函子一个非常良好的阅读这里
根据此博客,
运算符| @ | 是产品操作
和
使用| @ |将您的应用组合成产品 会导致一个ApplicativeBuilder,该ApplicativeBuilder带有对产品执行的功能(因为product + map是一个非常常见的用例)
我发现很难理解博客中的以上两个陈述。任何在scala中使用代码来理解这一点的示例都会有所帮助。
ArrayList.remove(int index)正在使用ActionListener类的匿名实例: -
DeleteModule.java: -
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
class MyFrame extends JFrame{
private ArrayList<String> list = new ArrayList<String>() ;
private JButton btn = new JButton("Enter index to delete : ") ;
private JTextField fld = new JTextField() ;
MyFrame(){
populateList() ;
setLayout(new GridLayout(1, 2)) ;
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE) ;
setSize(400, 60) ;
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
list.remove( Integer.parseInt( fld.getText() ) ) ;
JOptionPane.showConfirmDialog(null, list, …Run Code Online (Sandbox Code Playgroud) 在下面的代码中,Mockito verify 在具有默认参数的 scala 方法上无法按预期工作,但在没有默认参数的方法上工作正常。
package verifyMethods
import org.junit.runner.RunWith
import org.mockito.Mockito
import org.mockito.Mockito.times
import org.scalatest.FlatSpec
import org.scalatest.Matchers.be
import org.scalatest.Matchers.convertToAnyShouldWrapper
import org.scalatest.junit.JUnitRunner
import org.scalatest.mock.MockitoSugar
trait SUT {
def someMethod( bool: Boolean ): Int = if ( bool ) 4 else 5
def someMethodWithDefaultParameter( bool: Boolean, i: Int = 5 ): Int = if ( bool ) 4 else i
}
@RunWith( classOf[JUnitRunner] )
class VerifyMethodWithDefaultParameter extends FlatSpec with MockitoSugar with SUT {
"mockito verify method" should "pass" in {
val sutMock …Run Code Online (Sandbox Code Playgroud) class Person(){
val name : String
def this(n : String) {
this()
this.name = n
}
}
Run Code Online (Sandbox Code Playgroud)
compile time error : reassignment to val
Run Code Online (Sandbox Code Playgroud)
我是Scala的新手,到目前为止,我学习了如何使用主构造函数和case类初始化数据成员。我只是在徘徊,如果有一种方法可以在此内部初始化val数据成员。初始化var数据成员的工作原理如下:-
class Person(){
var name : String = _
def this(n : String) {
this()
this.name = n
}
}
Run Code Online (Sandbox Code Playgroud) java ×5
scala ×4
mockito ×2
unit-testing ×2
applicative ×1
arraylist ×1
collections ×1
constructor ×1
final ×1
flush ×1
inheritance ×1
io ×1
jenkins ×1
jobs ×1
junit ×1
overriding ×1
printwriter ×1
reference ×1
verify ×1