为了实现100%的代码覆盖率,我遇到了一种需要单元测试代码块的情况InterruptedException.如何正确地测试这个?(请使用JUnit 4语法)
private final LinkedBlockingQueue<ExampleMessage> m_Queue;
public void addMessage(ExampleMessage hm) {
if( hm!=null){
try {
m_Queue.put(hm);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud) 我在这里一无所知......
1: private static class ForeignKeyConstraint implements Comparable<ForeignKeyConstraint> {
2: String tableName;
3: String fkFieldName;
4:
5: public int compareTo(ForeignKeyConstraint o) {
6: if (this.tableName.compareTo(o.tableName) == 0) {
7: return this.fkFieldName.compareTo(o.fkFieldName);
8: }
9: return this.tableName.compareTo(o.tableName);
10: }
11: }
Run Code Online (Sandbox Code Playgroud)
在第6行,我从FindBugs得到: Bug: net.blabla.SqlFixer$ForeignKeyConstraint defines compareTo(SqlFixer$ForeignKeyConstraint) and uses Object.equals()
我不知道如何纠正这个问题.
在Instant有方法:
toEpochMilli它将此瞬间转换为1970-01-01T00:00:00Z时代的毫秒数getEpochSecond它得到的从1970-01-01T00了Java时代的秒数:00:00Z.这两种方法都失去了精度,例如在toEpochMilliJavaDoc中我看到:
如果此瞬间具有大于毫秒的精度,则转换将丢弃任何多余的精度信息,就好像以纳秒为单位的整数除以一百万.
我没有看到相应的方法来获得更精确的时间戳.如何从Java 8中获取epoch中的微数或纳米数?
我非常喜欢Java 7+写作hashCode()方式:
@Override
public int hashCode() {
Objects.hash(field1, field2);
}
Run Code Online (Sandbox Code Playgroud)
但它无法正常使用数组.以下代码:
@Override
public int hashCode() {
Objects.hash(field1, field2, array1, array2);
}
Run Code Online (Sandbox Code Playgroud)
将不会工作,因为array1和array2常规hashCode()而不是Arrays.hashCode()被调用.
如何Objects.hash()以正确的方式使用数组?
我想确保列表中的所有数字都组合在一起.让我通过例子解释一下:
{1, 1, 1, 2, 2} // OK, two distinct groups
{1, 1, 2, 2, 1, 1} // Bad, two groups with "1"
{1, 2, 3, 4} // OK, 4 distinct groups of size 1
{1, 1, 1, 1} // OK, 1 group
{3, 4, 3} // Bad, two groups with "3"
{99, -99, 99} // Bad, two groups with "99"
{} // OK, no groups
Run Code Online (Sandbox Code Playgroud)
这是我获取流的方式:
IntStream.of(numbers)
...
Run Code Online (Sandbox Code Playgroud)
现在我需要为"OK"示例传递或返回true,并AssertionError在"坏"示例上抛出或返回false.如何使用Stream API执行此操作?
这是我目前使用附加Set创建的解决方案:
Set<Integer> previousNumbers = new …Run Code Online (Sandbox Code Playgroud) We are using a 3 site, 3 nodes per site Cassandra 1.1.12 cluster that has 8GB ram allocated per node. We have been seeing long GC pauses on nodes periodically and that is messing with our applications realtime requirements. The systems we run on are 8 core systems with 24GB of ram.
We've been seeing 120+ second pauses where it does a stop the world GC.
We are running with these flags on JDK 1.7.0_04
-XX:+UseThreadPriorities
-XX:ThreadPriorityPolicy=42
-Xms8G
-Xmx8G
-Xmn1600M …Run Code Online (Sandbox Code Playgroud) 比方说,我有迁移从脚本V1_1到V1_300-这是一个相当庞大的数量和花费的时间很长一段时间.但是有时会有一个版本 - 从飞路的角度来看,我可以以某种方式合并所有这些迁移:
V1_1,以V1_300将在一个文件中(例如:V2_1)手动检查重叠非常耗时.提前感谢您的回答.
在停止开发之后我使用FEST-Assert并移动了AssertJ.
最近我被指向谷歌存储库与另一个断言库Truth(http://google.github.io/truth/).
阅读这些例子,我找不到任何开始使用它的优点AssertJ.所以这只是味道的问题.但也许我错过了这一点,是吗?
我正在尝试使用IntelliJ IDEA中的"在文件中查找"菜单中找到文件末尾没有换行符的所有文件.
我已经尝试了正则表达式[^\n]\Z,但它也找到了带换行符的文件.
什么是正确的正则表达式?或者也许有其他方法可以实现这一目标?
有一个用于刷新Gradle项目的图标,如果禁用自动导入,该图标非常有用:
当我将鼠标悬停在它上面时,状态栏会显示Force refresh all linked Gradle projects.
但是,我找不到任何方法为此按钮分配键盘快捷键,我也没有在CTRLSHIFTA菜单中看到它.有没有办法只使用键盘调用此刷新?
我正在使用IDEA 2016.3 EAP.