/* * SPDX-License-Identifier: Apache-2.0 * * The OpenSearch Contributors require contributions made to * this file be licensed under the Apache-2.0 license or a * compatible open source license. */ /* * Licensed to Elasticsearch under one or more contributor * license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright * ownership. Elasticsearch licenses this file to you 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 * * http://www.apache.org/licenses/LICENSE-2.0 * * 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. */ /* * Modifications Copyright OpenSearch Contributors. See * GitHub history for details. */ package org.opensearch.common; import org.opensearch.test.OpenSearchTestCase; import java.util.List; import java.util.Map; import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; public class TableTests extends OpenSearchTestCase { public void testFailOnStartRowWithoutHeader() { Table table = new Table(); Exception e = expectThrows(IllegalStateException.class, () -> table.startRow()); assertThat(e.getMessage(), is("no headers added...")); } public void testFailOnEndHeadersWithoutStart() { Table table = new Table(); Exception e = expectThrows(IllegalStateException.class, () -> table.endHeaders()); assertThat(e.getMessage(), is("no headers added...")); } public void testFailOnAddCellWithoutHeader() { Table table = new Table(); Exception e = expectThrows(IllegalStateException.class, () -> table.addCell("error")); assertThat(e.getMessage(), is("no block started...")); } public void testFailOnAddCellWithoutRow() { Table table = this.getTableWithHeaders(); Exception e = expectThrows(IllegalStateException.class, () -> table.addCell("error")); assertThat(e.getMessage(), is("no block started...")); } public void testFailOnEndRowWithoutStart() { Table table = this.getTableWithHeaders(); Exception e = expectThrows(IllegalStateException.class, () -> table.endRow()); assertThat(e.getMessage(), is("no row started...")); } public void testFailOnLessCellsThanDeclared() { Table table = this.getTableWithHeaders(); table.startRow(); table.addCell("foo"); Exception e = expectThrows(IllegalStateException.class, () -> table.endRow()); assertThat(e.getMessage(), is("mismatch on number of cells 1 in a row compared to header 2")); } public void testOnLessCellsThanDeclaredUnchecked() { Table table = this.getTableWithHeaders(); table.startRow(); table.addCell("foo"); table.endRow(false); } public void testFailOnMoreCellsThanDeclared() { Table table = this.getTableWithHeaders(); table.startRow(); table.addCell("foo"); table.addCell("bar"); Exception e = expectThrows(IllegalStateException.class, () -> table.addCell("foobar")); assertThat(e.getMessage(), is("can't add more cells to a row than the header")); } public void testSimple() { Table table = this.getTableWithHeaders(); table.startRow(); table.addCell("foo1"); table.addCell("bar1"); table.endRow(); table.startRow(); table.addCell("foo2"); table.addCell("bar2"); table.endRow(); // Check headers List