小编nin*_*nja的帖子

为什么Mockito不能在Kotlin中使用数字类型模拟通用参数类型?

我们正在将项目转移到Kotlin语言.我们决定从测试开始,但面临一些奇怪的行为.

这是我们的测试用例:

Service.java

public final class Service {
    private final JdbcTemplate jdbcTemplate;

    public Service(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    public long check() {
        return jdbcTemplate.queryForObject("SELECT COUNT(*) FROM table", Long.class);
    }
}
Run Code Online (Sandbox Code Playgroud)

JavaTest.java(工作正常)

@RunWith(MockitoJUnitRunner.class)
public final class JavaTest {
    @Mock
    private JdbcTemplate jdbcTemplate;

    @InjectMocks
    private Service testSubject;

    @Test
    public void test() {
        //given
        when(jdbcTemplate.queryForObject(anyString(), eq(Long.class))).thenReturn(1L);

        //when
        long result = testSubject.check();

        //then
        assertThat(result, is(1L));
    }
}
Run Code Online (Sandbox Code Playgroud)

KotlinTest.kt(不工作)

@RunWith(MockitoJUnitRunner::class)
class KotlinTest {
    @Mock
    private lateinit var jdbcTemplate: JdbcTemplate

    @InjectMocks
    private …
Run Code Online (Sandbox Code Playgroud)

java junit unit-testing mockito kotlin

8
推荐指数
1
解决办法
2776
查看次数

Apache Commons VFS:使用 FTP

我正在尝试通过 FTP 使用 Apache Commons VFS。在我的 FTP 上有下一个文件和文件夹结构:

/
/test
/test/in
/test/in/file1.txt
/test/in/file2.txt
Run Code Online (Sandbox Code Playgroud)

我需要连接并读取文件夹 /test/in 中的所有文件(它一直在变化)。代码:

        FileSystemManager fsManager = null;
        FileSystem fs = null;
        FileSystemOptions opts = new FileSystemOptions();
        fsManager = VFS.getManager();

        FileObject path = fsManager.resolveFile("ftp://user:password@my.ftp.host/test/in/", opts);

        fs = path.getFileSystem();

        //prints Connection successfully established to /test/in
        System.out.println("Connection successfully established to " + path.getName().getPath());
Run Code Online (Sandbox Code Playgroud)

但是我无法获得文件列表,因为它说 /test/in 不存在。A 做了一些测试来检查文件类型:System.out.println(path.getType());使用不同的路径。结果:

ftp://user:password@my.ftp.host/test - 文件

ftp://user:password@my.ftp.host/test/in - 虚构

ftp://user:password@my.ftp.host/test/in/file1.txt - 文件

FileType.IMAGINARY 表示该文件不存在。任何想法如何使用 ftp 文件夹?

java ftp apache-commons-vfs

3
推荐指数
1
解决办法
1万
查看次数

标签 统计

java ×2

apache-commons-vfs ×1

ftp ×1

junit ×1

kotlin ×1

mockito ×1

unit-testing ×1