是否有Hamcrest匹配器检查参数既不是空集合也不是空?
我想我总是可以使用
both(notNullValue()).and(not(hasSize(0))
Run Code Online (Sandbox Code Playgroud)
但我想知道是否有更简单的方法,我错过了它.
是什么区别getSize()
,并getNumberOfElements
在Spring数据类org.springframework.data.domain.Slice
?
Javadoc在这里没有提供太多帮助.
Spring Boot 1.4为测试带来了很多很好的改进。
我不清楚@TestConfiguration
. 它似乎没有按预期工作。
我认为,如果我@TestConfiguration
在顶级课程/src/test/java
上使用它,它会被@SpringBootTest
测试选中(请参阅此处)。但情况似乎并非如此。如果我改为使用,@Configuration
那么它会被正确拾取。
我误会了吗?说明书错了吗?Spring Boot 代码中是否存在错误?
我正在查看旧的代码库,我找到了一个只调用其父代的方法:
@Override
public void select(Object item) {
super.select(item);
}
Run Code Online (Sandbox Code Playgroud)
这种方法会有用例吗?对我来说,看起来我可以删除它.
在当前的groovy版本中,该方法DefaultGroovyMethods.toURL(String)
被标记为已弃用,但没有任何解释.
为什么要弃用它,我们应该使用什么呢?我想用它来轻松地从HTTP获取文件,如下所示:
def xml = "http://url.to/file.xml".toURL().text
Run Code Online (Sandbox Code Playgroud) 我有一个带有多个插件的Eclipse RCP项目.我正在编写简单的JUnit测试(不依赖于Eclipse/UI)作为测试插件的单独片段.
当使用Mockito并尝试从另一个插件模拟一个接口(正确导出;我可以在我的代码中使用该接口)时,我得到一个与类签名相关的SecurityException:
org.mockito.exceptions.base.MockitoException:
Mockito cannot mock this class: interface ch.sbb.polar.client.communication.inf.service.IUserService
Mockito can only mock visible & non-final classes.
If you're not sure why you're getting this error, please report to the mailing list.
at org.mockito.internal.runners.JUnit45AndHigherRunnerImpl$1.withBefores(JUnit45AndHigherRunnerImpl.java:27)
[...]
Caused by: org.mockito.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
at org.mockito.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:238)
[...]
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[...]
Caused by: java.lang.SecurityException: Signers of 'ch.sbb.polar.client.communication.inf.service.IUserService$$EnhancerByMockitoWithCGLIB$$a8bfe723' do not match signers of other classes in package
at java.lang.ClassLoader.checkPackageSigners(ClassLoader.java:361)
at java.lang.ClassLoader.defineClass(ClassLoader.java:295)
... 40 more
Run Code Online (Sandbox Code Playgroud)
当我将测试作为"JUnit插件测试"运行时,即使用OSGi环境,一切都按预期工作.但是我想因速度而使用普通的JUnit执行; 在被测试的类中,我不需要OSGi环境.
有人知道这样做的方法吗?
我将 AssertJextracting()
方法与 Java8 lambda 一起使用,并将一些字段映射到 BigDecimal,然后断言结果数组。但我需要使用 BigDecimalcompareTo()
和不使用BigDecimal 进行比较equals()
(因此)。我怎样才能做到这一点?
例子:
Actual actual = performTest();
Assertions.assertThat(actual)
.extracting(
Actual::getName, // returns String
Actual::getValue // returns BigDecimal
)
.containsExactly(
"abc", // ok, String equals comparison
new BigDecimal("1.1") // NOT OK, equals comparison, but I need compareTo comparison
);
Run Code Online (Sandbox Code Playgroud)
编辑:我正在寻找一种流畅的方法来执行此操作,因为我当然可以将其拆分为多个不同的断言并以这种方式进行比较,或者将所有内容放入一个巨大的Condition
.
如何在使用Spring Boot获取数据库连接后直接运行自定义SQL语句?
每次建立新连接时都需要运行SQL.
该解决方案应该与Spring Boot默认的DataSource实现(我认为是Tomcat池数据源)一起使用.
声明是什么并不重要,但就我而言,它将是 ALTER SESSION SET CURRENT_SCHEMA=xxxx
java ×6
spring ×3
junit ×2
spring-boot ×2
assertj ×1
datasource ×1
eclipse-rcp ×1
groovy ×1
hamcrest ×1
inheritance ×1
jdbc ×1
matcher ×1
mockito ×1
oop ×1
spring-data ×1