首页 \ 问答 \ IntelliJ警告:为varargs参数创建未经检查的泛型数组(IntelliJ warning: Unchecked generics array creation for varargs parameter)

IntelliJ警告:为varargs参数创建未经检查的泛型数组(IntelliJ warning: Unchecked generics array creation for varargs parameter)

IntelliJ Idea对我的测试用例中的一个陈述给出以下警告。

警告:为varargs参数未经检查的泛型数组创建

信号编译器发出未经检查的警告的地方

我所做的只是:

when(someService.someMethod(id)).thenThrow(AccountNotFoundException.class)


IntelliJ Idea is giving following warning for one of the statements in my test cases.

Warning: Unchecked generics array creation for varargs parameter

Signals places where an unchecked warning is issued by the compiler

All I am doing is :

when(someService.someMethod(id)).thenThrow(AccountNotFoundException.class)


原文:https://stackoverflow.com/questions/50779176
更新时间:2021-12-19 07:12

最满意答案

更好的方法来完成这可能是:

when(someService.someMethod(id)).thenThrow(new AccountNotFoundException());

那么编译器应该正确地推断出类型。

如果someService.someMethod(id)返回类型为void那么可以这样做:

doThrow(new AccountNotFoundException()).when(someService).someMethod(id);

有关使用thenThrow示例,请参阅官方的Mockito文档 。 这个文件非常清楚。

您也可以检查以下非常相似的StackOverflow问题(如果不是完全相同的话):

如何模拟和断言抛出的异常


A better way to accomplish that would probably be:

when(someService.someMethod(id)).thenThrow(new AccountNotFoundException());

then the compiler should infer the type correctly.

If someService.someMethod(id) has return type void you can do:

doThrow(new AccountNotFoundException()).when(someService).someMethod(id);

Please refer to the official Mockito documentation for examples like this using thenThrow. The documentation is very clear on this point.

You can also check the following StackOverflow question which is very similar (if not an exact duplicate):

How to mock and assert a thrown exception

相关问答

更多

相关文章

更多

最新问答

更多
  • 在页面树中使用不同的域(Use different domains in page tree)
  • 为什么这个半圈不会成长?(Why won't this semi circle grow?)
  • 如何学习计算机编程?
  • 如何在单个gcc命令中将多个头文件包和库目录添加到搜索路径?(How to add multiple header include and library directories to the search path in a single gcc command?)
  • VB.Net绑定datagridview Comboboxcolumn到datagridviewTextboxColumn(VB.Net binding datagridview Comboboxcolumn to datagridviewTextboxColumn)
  • 数据库设计 - 当一个记录有许多属性时(database design - when one record has many properties)
  • MATLAB函数计算两个坐标(纬度和经度)之间的距离(MATLAB function to calculate distance between two coordinates (latitude and longitude))
  • 如何从TFS中的团队项目查询所有PBI的历史变更?(How to query all PBI's historical changes from a team project in TFS?)
  • 使用点表示法的Python导入无法按预期工作(Python import using dot notation doesn't work as expected)
  • 我们能否将String列设置为partitionColumn?(Can we able to set String column as partitionColumn?)
  • 下划线模板无法按预期工作(Underscore template doesn't work as intended)
  • 怎么写项目开发的文档?
  • 为什么我的plpgsql函数没有返回任何行(why does my plpgsql function return no rows)
  • 补偿ARM中断的延迟?(compensating latency on ARM interrupts?)
  • Clojure:半平铺嵌套序列(Clojure: Semi-Flattening a nested Sequence)
  • Array方法返回所有null元素而不是object元素(Array method returning all null elements instead of object elements)
  • 禁止基于IP的用户,而不允许管理员访问IP(Ban user based on IP without allowing Admin to access IP)
  • c#wpf多重绑定不是很流行(c# wpf Multibindings not aviable)
  • 亚马逊Generic是什么意思
  • 如何在jgroup复制的hashmap中为状态转移提供超时?(How to give timeout for state transfer in jgroup replicated hashmap?)
  • highcharts可以生成这样的3d柱形图吗?(Can highcharts generate a 3d column chart like this?)
  • 在rails控制台中选择第二个条目?(Selecting second entry in rails console?)
  • 通过了解标记并且不循环遍历项目,将值设置为列表视图的某列中的行(Set a value to a row in a certain column of a listview by knowing the tag and without looping through items)
  • 杀死一个分叉的孩子(Kill a Forked Child)
  • 什么是代码点和代码空间?(What is a code point and code space?)
  • 如何在ruby中获取第一个html标记和第二个html标记之间的内容(how to get the content between the first html tag and the second html tag in ruby)
  • 需要在recyclerview中获取新添加项的视图参考(Need to get the view reference of newly added item in recyclerview)
  • 我今天部计算机出现故障啊,在按开机后,主机便发出“迪”的开机的报警声啊,在上午上过后就不行了,我只是把计算机的所有线重插过就这样,因为D线太乱啊,整理下。但到晚上计算机又能开机啊,可以详细告诉原因吗
  • 将字符串转换为NumPy datetime64 dtype(Convert string to NumPy datetime64 dtype)
  • 模块VB.Net中的命名空间(Namespace in module VB.Net)