小编use*_*976的帖子

如何在TestNG中使用Mockito模拟jdbc连接和resultSet

我必须写一些单元测试,但我有模拟ResultSet和jdbc的问题Connection.

我有这个方法:

@Test
public void test3() throws SQLException, IOException {

    Connection jdbcConnection = Mockito.mock(Connection.class);
    ResultSet resultSet = Mockito.mock(ResultSet.class);

    Mockito.when(resultSet.next()).thenReturn(true).thenReturn(true).thenReturn(true).thenReturn(false);
    Mockito.when(resultSet.getString(1)).thenReturn("table_r3").thenReturn("table_r1").thenReturn("table_r2");
    Mockito.when(jdbcConnection
            .createStatement()
            .executeQuery("SELECT name FROM tables"))
            .thenReturn(resultSet);

    //when
    List<String> nameOfTablesList = null;
    try {
        nameOfTablesList = Helper.getTablesName(jdbcConnection);
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    //then
    Assert.assertEquals(nameOfTablesList.size(), 3);
}
Run Code Online (Sandbox Code Playgroud)

错误显示在行中executeQuery("SELECT name FROM tables"),听起来像这样:

java.lang.NullPointerException HelperTest.test3(HelperTest.java:71)
Run Code Online (Sandbox Code Playgroud)

任何想法都出错了?

java unit-testing jdbc resultset mockito

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

Javafx - 在webview组件中打开login.microsoftonline.com页面

我在javafx的webview组件中打开login.microsoftonline.com页面时遇到问题.我只是应该打开这个页面的代码没有任何麻烦:

   WebView webView = new WebView();
    WebEngine webEngine = webView.getEngine();
    var url = "https://login.microsoftonline.com/";
    webEngine.load(url);

    VBox root = new VBox();
    root.getChildren().add(webView);
    Scene scene = new Scene(root);
    stage.setScene(scene);
    stage.show();

    webEngine.getLoadWorker().stateProperty().addListener((obs, oldValue, newValue) -> { 
     System.out.println(webEngine.getLocation());
    });
Run Code Online (Sandbox Code Playgroud)

当我尝试在带有Windows操作系统的机器上执行此代码时,我会收到空​​白页: 在此输入图像描述 当我在macbook上执行相同的代码时,网站正在打开: 在此输入图像描述

我正在使用java 10,真的不知道出了什么问题.有没有人有同样的问题?知道如何解决这个问题吗?也许有其他组件而不是webview我可以用来做我的东西?

windows macos javafx webview office365

10
推荐指数
1
解决办法
996
查看次数

自定义登录页面 Cognito

我知道可以在 cognito 提供的登录页面上自定义一些值。但这对我来说还不够。是否可以完全自定义?我只使用来自 Web 应用程序的第三方联合标识。是否有可能改变灰色背景?或者说有完全不同的看法?

user-interface amazon-web-services web amazon-cognito

6
推荐指数
3
解决办法
6066
查看次数