我正在尝试使用模拟 2.0.2 和 mockito 2.0。以前我用powermock来模拟一些局部变量:我在测试类上用过
@RunWith(PowerMockRunner.class)
@PrepareForTest({MyClass.class})
whenNew(MyClass.class).withAnyArguments().thenReturn(myClassMock);
Run Code Online (Sandbox Code Playgroud)
一切都很好,带有电源模拟1.6。当我试图转移到Powermock 2.X我不能再找到whenNew()在PowerMock方法。这在新的 Powermock 中有何变化?依赖项:
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>2.0.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>2.0.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.15.0</version>
<scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
顺便说一下,哪个版本的 mockito 与 Powermock 兼容?- 我看到使用 mockito 支持 Powermock 存在一些问题
有多种的MaxProductOfThree任务答案codility.com,其中大部分涉及排序算法.
问题是:
给出了由N个整数组成的非空零索引数组A.
问题是找到给定数组中3个元素的最大乘积.
阵列的长度在3到100,000之间
数组A的每个元素都是[-1,000..1,000]范围内的整数
expected worst-case time complexity is O(N*log(N));
expected worst-case space complexity is O(1),
Run Code Online (Sandbox Code Playgroud)
超出输入存储(不计入输入参数所需的存储).例:
a[0] = -3;
a[1] = 7;
a[2] = 2;
a[3] = 1;
a[4] = 5;
a[5] = 7;
Run Code Online (Sandbox Code Playgroud)
最大乘积是[1]*a [4]*a [5] = 245
除了涉及排序的O(n log n)方法之外,是否存在线性时间解决该问题的方法?
我有一个问题,创建用于弹性搜索的TransportClient bean,compiller它说构造函数是私有的,就像那样.我怎样才能正确创建bean?这是我的配置类:
import org.elasticsearch.client.Client;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.common.transport.TransportAddress;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.elasticsearch.core.ElasticsearchOperations;
import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
@Configuration
@EnableElasticsearchRepositories(basePackages = "example.spring.data.es.repository")
@ComponentScan(basePackages = { "example.spring.data.es.service" })
public class Config {
@Bean
public Client client() {
//here compiller says that the TransportClient() is private. How else i cna create the transport client?
TransportClient client = new TransportClient();
TransportAddress address = new InetSocketTransportAddress(
"localhost",9200);
client.addTransportAddress(address);
return client;
}
@Bean
public ElasticsearchOperations elasticsearchTemplate() {
return new ElasticsearchTemplate(client());
} …Run Code Online (Sandbox Code Playgroud)