我不确定为什么PowerMockito.when返回null。这是我正在测试的课程:
public class A {
public Integer callMethod(){
return someMethod();
}
private Integer someMethod(){
//Some Code
HttpPost httpPost = new HttpPost(oAuthMessage.URL);
//Some Code
HttpClient httpClient = HttpClientBuilder.create().build();
HttpResponse httpResponse = httpClient.execute(httpPost); ------1
Integer code = httpResponse.getStatusLine().getStatusCode(); ---2
return code;
}
}
@RunWith(PowerMockRunner.class)
@PrepareForTest({ MacmillanServiceImpl.class, PersonService.class, AuthorizeServiceImpl.class, ProvisionHelper.class, ESPHelper.class,
DPFServiceImpl.class, TransactionLogServiceImpl.class, HttpClient.class, HttpEntity.class, InputStream.class, IOUtils.class,
DTOUtils.class, MacmillanESPResponseDTO.class, HttpClientBuilder.class, CloseableHttpClient.class, HttpPost.class, IOUtils.class,
HttpResponse.class, CloseableHttpResponse.class, StatusLine.class })
@PowerMockIgnore({ "javax.crypto.*", "javax.net.ssl.*" })
public class TestA {
//Spying some things here …Run Code Online (Sandbox Code Playgroud) 我在互联网上阅读了它,但我无法得到某些查询的答案。
一季度。据说在执行PreparedStatement时,DBMS可以直接运行PreparedStatement SQL语句,无需先编译。我的问题是当preparedStetement.execute() 被调用时会发生什么?(我的理解:没有任何参数的sql被发送到DBMS,由DBMS编译和缓存以备将来使用。然后发送参数&DBMS用占位符替换它们&执行。)
Q2。如果下次我使用相同的 sql 执行 PreparedStetement.execute() 那么会发生什么?(我的理解:DBMS 将 sql 与之前的 sql 进行比较,如果匹配则采用编译后的 sql,替换参数并执行。)
Q3。如果我偶尔调用数据库,那么准备好的语句不会帮助我提高性能,因为在此期间数据库缓存将被清除。所以每次都会编译sql。对?
List<? super IOException>表示列表可以包含IOException对象或任何属于super类的对象IOException。那么为什么下面的第2行不编译?
同样在第3行FileNotFoundException中也不是的super类IOException。那为什么编译呢?
List<? super IOException> myList = new ArrayList<Exception>();
myList.add(new Exception()); //Line 2 This line do not compile
myList.add(new FileNotFoundException()); //Line 3 This compiles
Run Code Online (Sandbox Code Playgroud) 问题标题可能看起来与其他帖子相同,但内容不同。所以请不要将其标记为重复。
问题:
我有以下课程:
public class SCDTO extends RDTO {
private List<String> sCPairs = Collections.emptyList();
public SCDTO(List<String> sCPairs) {
this.sCPairs = sCPairs;
}
//Getter setter
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用下面的 lambda 表达式来设置sCPairs.
sCPairsObject.setSCPairs(
util.getSCMap().entrySet().stream()
.filter(entry -> entry.getValue().contains("abc"))
.collect(Collectors.toCollection(ArrayList<String>::new))
);
Run Code Online (Sandbox Code Playgroud)
但我有一个编译错误:
no instance(s) of type variable(s) exist so that Entry<String, List<String>> conforms to String
Run Code Online (Sandbox Code Playgroud)
util.getSCMap返回Map<String, List<String>>。
谁能解释一下为什么会发生这种情况以及如何解决它?
谢谢。
我在 Oracle 中创建了一个存储过程。程序编译成功,没有错误。该过程有 3 个 UPDATE 查询,它们更新 3 个表“TBLHOTEL”、“TBLHOTELDETAIL”和“TBLHOTELFARE”。
在每个 Update 语句之后,一个变量 successCnt1 会递增以获取成功插入查询的数量。最后将 successCnt1 分配给 successCnt 以存储最终结果。如果在任何查询中发生异常,则将其设置为 0 ,以指示不发生插入。
问题也不例外,数据库也没有发生更新。
这是我的代码:
架构:
TBLHOTEL 架构: {DATE1 (DATE) , ACROOMS (NUMBER) , NACROOMS (NUMBER), HOTELID (VARCHAR2(10)) }
TBLHOTELFARE 架构: {HOTELID (VARCHAR2(10)), CLASS (VARCHAR2(5)), FARE (NUMBER)}
TBLHOTELDETAIL 架构: {HOTELID (VARCHAR2(10)) , PLACE (VARCHAR2(15)) , HOTELNAME (VARCHAR2(15)) }
程序:
CREATE OR REPLACE PROCEDURE TableUpdateByParameter (acrooms in number,
nacrooms in number,
date1 in date,
hotelid in varchar2,
fare in number,
place in varchar2, …Run Code Online (Sandbox Code Playgroud) 这是我需要测试的课程:
@Repository
@Transactional
public class ProductDAOImpl implements ProductDAO {
private static final Logger logger = Logger.getLogger(ProductDAOImpl.class);
@Autowired
private SessionFactory hibernateSessionFactory;
@Override
public ProductDTO getProduct(String isbn) throws ProductException {
ProductDTO productDTO = new ProductDTO();
Product product = getProductFromDb(isbn);
BeanUtils.copyProperties(product, productDTO);
return productDTO;
}
private Product getProductFromDb(String isbn) throws ProductException{
Session session = this.hibernateSessionFactory.getCurrentSession();
String hql = "FROM com.esp.dao.entity.Product P WHERE P.isbn13 = :isbn13";
Query query = session.createQuery(hql);
query.setParameter("isbn13",isbn);
List<Product> productList = query.list(); // Want to mock this call
if(productList.size() ==1)
return …Run Code Online (Sandbox Code Playgroud) 我有HashMap以下结构。
Map<String, Container>
本Container类包含一个List。我想清除此列表的内容,以便该列表存在但具有0个元素。稍后,我将再次输入值。
在replaceAll()期望一个BiFunction。由于这个原因,以下给出编译错误,因为返回类型clear()为void:
personMap.replaceAll((k,v) -> v.getMyList().clear());
我必须使用node.js从S3存储桶下载多个文件。为此,我必须编写for loop&调用s3.getObject(param)下载方法。下载文件后,我必须合并其内容。
我这样写:
var fileContentList = new ArrayList();
for(i=0; i<fileNameList.length i++){
s3.getObject({ Bucket: "my-bucket", Key: fileNameList.get(i) }, function (error, data) {
if (error != null) {
alert("Failed to retrieve an object: " + error);
} else {
alert("Loaded " + data.ContentLength + " bytes");
fileContentList.add(data.Body.toString());
}
}
);
}
//Do merging with the fileContentList.
Run Code Online (Sandbox Code Playgroud)
但是作为s3.getObject异步调用,当前线程继续前进,fileContentList而在执行合并时没有任何添加。
我该如何解决这个问题?任何的想法?
在aws-sdk中是否有任何同步方法来下载文件?
javascript amazon-s3 amazon-web-services node.js aws-sdk-nodejs
我必须执行以下操作:
Solr 7.4.0 和 Zookeeper 版本: 3.4.12
我做了以下事情:
设置动物园管理员:
./zkServer.sh start设置 Solr:
使用以下命令启动 Solr:
./solr start -cloud -s /home/demo/LocalFolder/Downloads/SolrHome -p 8987 -z localhost:2181
尝试使用以下方式在 Zookeeper 中上传配置:
./solr create -c mycollection -d /media/sf_VM/Dump/conf
它给了我一个例外:
Caused by: javax.servlet.UnavailableException: Error processing the request. CoreContainer is either not initialized or shutting down.
at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:341)
at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:323)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1634)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:533)
at …Run Code Online (Sandbox Code Playgroud) java ×5
java-8 ×2
mockito ×2
powermockito ×2
sql ×2
unit-testing ×2
amazon-s3 ×1
database ×1
generics ×1
java-stream ×1
javascript ×1
jdbc ×1
junit ×1
lambda ×1
lucene ×1
node.js ×1
oracle10g ×1
plsql ×1
powermock ×1
solr ×1
solr4 ×1
solrcloud ×1
spring ×1
sql-update ×1