小编mog*_*gli的帖子

错误的参数匹配器在这里检测到.您不能在Mockito中使用验证或存根之外的参数匹配器

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)

java junit unit-testing mockito

25
推荐指数
1
解决办法
5万
查看次数

为什么不能在scala中覆盖可变变量?

为什么不能在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,那么上面的代码工作正常.

inheritance overriding scala

15
推荐指数
2
解决办法
3714
查看次数

以编程方式从jenkins插件触发jenkins hudson.model.Job

我正在努力找出一些示例来从插件触发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)

jobs jenkins jenkins-plugins jenkins-pipeline

9
推荐指数
1
解决办法
475
查看次数

我用autoflush创建了一个PrintWriter; 为什么不是自动冷却?

我的客户端是一个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)

java io flush printwriter

8
推荐指数
1
解决办法
1万
查看次数

这是否可以编写Marker接口

我已经完成了以下教程:

http://www.javaworld.com/community/node/2915

在阅读完上面的文章之后,我觉得,编写Marker接口是不可能的,因为,如何指导编译器,它是什么标记,它嵌入到Marker接口的.class文件中.

如果我错了,请纠正我.欢呼:)

java serialization

8
推荐指数
2
解决办法
9948
查看次数

虽然没有对实际引用对象的强引用,但WeakReference不返回null

我正在阅读以下有关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)

java reference weak-references

7
推荐指数
1
解决办法
2154
查看次数

什么是Applicative Builder

我是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中使用代码来理解这一点的示例都会有所帮助。

functional-programming scala applicative

5
推荐指数
1
解决办法
482
查看次数

ArrayList.remove(int index)不使用非匿名类对象

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)

java collections arraylist anonymous-class

4
推荐指数
2
解决办法
6825
查看次数

对于 Scala 中具有默认参数的方法,Mockito 验证失败并显示“TooManyActualInitations”

在下面的代码中,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)

unit-testing scala verify mockito

4
推荐指数
1
解决办法
8007
查看次数

在主构造函数中初始化时重新分配给val

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)

constructor scala final initialization

3
推荐指数
1
解决办法
1356
查看次数