|
| 1 | +/* |
| 2 | + * RowStructTest.java |
| 3 | + * |
| 4 | + * This source file is part of the FoundationDB open source project |
| 5 | + * |
| 6 | + * Copyright 2015-2025 Apple Inc. and the FoundationDB project authors |
| 7 | + * |
| 8 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 9 | + * you may not use this file except in compliance with the License. |
| 10 | + * You may obtain a copy of the License at |
| 11 | + * |
| 12 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | + * |
| 14 | + * Unless required by applicable law or agreed to in writing, software |
| 15 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 16 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 17 | + * See the License for the specific language governing permissions and |
| 18 | + * limitations under the License. |
| 19 | + */ |
| 20 | + |
| 21 | +package com.apple.foundationdb.relational.recordlayer; |
| 22 | + |
| 23 | +import com.apple.foundationdb.relational.api.FieldDescription; |
| 24 | +import com.apple.foundationdb.relational.api.ImmutableRowStruct; |
| 25 | +import com.apple.foundationdb.relational.api.MutableRowStruct; |
| 26 | +import com.apple.foundationdb.relational.api.RelationalStructMetaData; |
| 27 | +import com.apple.foundationdb.relational.api.RowStruct; |
| 28 | +import org.junit.jupiter.api.Assertions; |
| 29 | +import org.junit.jupiter.params.ParameterizedTest; |
| 30 | +import org.junit.jupiter.params.provider.ValueSource; |
| 31 | + |
| 32 | +import java.sql.DatabaseMetaData; |
| 33 | +import java.sql.SQLException; |
| 34 | +import java.sql.Types; |
| 35 | + |
| 36 | +public class RowStructTest { |
| 37 | + |
| 38 | + @ParameterizedTest |
| 39 | + @ValueSource(booleans = {true, false}) |
| 40 | + void wasNullWorks(boolean mutable) throws SQLException { |
| 41 | + final var struct = createStruct(mutable); |
| 42 | + struct.getObject(1); |
| 43 | + Assertions.assertTrue(struct.wasNull()); |
| 44 | + } |
| 45 | + |
| 46 | + @ParameterizedTest |
| 47 | + @ValueSource(booleans = {true, false}) |
| 48 | + void wasNullWorksWithToString(boolean mutable) throws SQLException { |
| 49 | + final var struct = createStruct(mutable); |
| 50 | + struct.getObject(1); |
| 51 | + Assertions.assertFalse(struct.toString().isEmpty()); |
| 52 | + Assertions.assertTrue(struct.wasNull()); |
| 53 | + } |
| 54 | + |
| 55 | + private static RowStruct createStruct(boolean mutable) { |
| 56 | + final var metadata = new RelationalStructMetaData( |
| 57 | + FieldDescription.primitive("fInt", Types.INTEGER, DatabaseMetaData.columnNullable), |
| 58 | + FieldDescription.primitive("fLong", Types.BIGINT, DatabaseMetaData.columnNullable) |
| 59 | + ); |
| 60 | + final var row = new ArrayRow(null, 1L); |
| 61 | + if (mutable) { |
| 62 | + final var toReturn = new MutableRowStruct(metadata); |
| 63 | + toReturn.setRow(row); |
| 64 | + return toReturn; |
| 65 | + } else { |
| 66 | + return new ImmutableRowStruct(row, metadata); |
| 67 | + } |
| 68 | + } |
| 69 | +} |
0 commit comments