我遇到了使用mockito模拟方法的问题,如下所示:
Map<Foo, ? extends Collection<Bar>> getValue();
Run Code Online (Sandbox Code Playgroud)
以下是我在测试中使用它的方法:
model = Mockito.mock(Model.class);
Map<Foo, List<Bar>> value = new HashMap<Foo, List<Bar>>();
Mockito.when(model.getValue()).thenReturn(value);
Run Code Online (Sandbox Code Playgroud)
它给出以下错误:
错误:找不到合适的方法
thenReturn(Map<Foo,List<Bar>>)
我有两个图标,一个是透明的,所以我需要添加一个图标,我必须添加透明图标:
public static void main(String[] args) {
Icon icon = new ImageIcon("0.png");
Icon icon1 = new ImageIcon("2.png");
JLabel label = new JLabel();
label.setIcon(icon);
//label.setIcon(icon1);
JFrame frame = new JFrame();
frame.add(label, BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
Run Code Online (Sandbox Code Playgroud) 在大多数情况下,当我们编写工厂方法时,它是一堆if可以继续增长的条件.编写这种方法的最有效方法是什么(if条件最少)?
public A createA(final String id) {
if (id.equals("A1")) {
return new A1();
}
else if (id.equals("A2")) {
return new A2();
}
return null;
}
Run Code Online (Sandbox Code Playgroud) 我应该能够通过传递列和行来检查鼠标悬停期间是否正在编辑单元格:
TableCellEditor cellEditor = table.getCellEditor(rowPoint, colPoint);
Run Code Online (Sandbox Code Playgroud)
在上面的示例cellEditor中没有提供检查是否处于编辑模式的方法.
另一方面,通过检查table.isEditing()是不够的,因为true如果正在编辑任何一个单元格,它将返回.