!361 test: 测试 Row 包含 null 值字段

Merge pull request !361 from 王帅/main
This commit is contained in:
Michael Yang 2023-10-11 11:50:33 +00:00 committed by Gitee
commit 83a22fa5b0
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -0,0 +1,73 @@
/*
* Copyright (c) 2022-2023, Mybatis-Flex (fuhai999@gmail.com).
* <p>
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.mybatisflex.test;
import com.mybatisflex.core.MybatisFlexBootstrap;
import com.mybatisflex.core.row.Db;
import com.mybatisflex.core.row.Row;
import org.apache.ibatis.session.Configuration;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
import javax.sql.DataSource;
import java.util.List;
/**
* @author 王帅
* @since 2023-10-11
*/
public class DbTest {
@BeforeClass
public static void init() {
DataSource dataSource = new EmbeddedDatabaseBuilder()
.setType(EmbeddedDatabaseType.H2)
.addScript("schema.sql")
.addScript("data.sql")
.build();
MybatisFlexBootstrap bootstrap = MybatisFlexBootstrap.getInstance()
.setDataSource(dataSource)
.start();
/*
* 指定当结果集中值为 null 的时候是否调用映射对象的 settermap 对象时为 put方法
* 这在依赖于 Map.keySet() null 值进行初始化时比较有用注意基本类型intboolean
* 是不能设置成 null
*/
Configuration configuration = bootstrap.getConfiguration();
configuration.setCallSettersOnNulls(true);
Db.updateBySql("update tb_account set options = null;");
}
@SuppressWarnings("all")
static String tb_account = "tb_account";
@Test
public void test01() {
List<Row> rows = Db.selectAll(tb_account);
rows.stream()
.map(row -> row.get("OPTIONS"))
.forEach(Assert::assertNull);
}
}