public static void assertEquals(SourceRecord actual, SourceRecord expected, Predicate<String> ignoreFields, Map<String, RecordValueComparator> comparatorsByName, Map<String, RecordValueComparator> comparatorsBySchemaName) { assertThat(actual).isNotNull(); assertThat(expected).isNotNull(); assertEquals(null, actual.sourcePartition(), expected.sourcePartition(), "sourcePartition", "", ignoreFields, comparatorsByName, comparatorsBySchemaName); assertEquals(null, actual.sourceOffset(), expected.sourceOffset(), "sourceOffset", "", ignoreFields, comparatorsByName, comparatorsBySchemaName); assertThat(actual.topic()).isEqualTo(expected.topic()); assertThat(actual.kafkaPartition()).isEqualTo(expected.kafkaPartition()); Schema actualKeySchema = actual.keySchema(); Schema actualValueSchema = actual.valueSchema(); Schema expectedKeySchema = expected.keySchema(); Schema expectedValueSchema = expected.valueSchema(); if (!Objects.equals(actualKeySchema, expectedKeySchema)) { String actualStr = SchemaUtil.asString(actualKeySchema); String expectedStr = SchemaUtil.asString(expectedKeySchema); assertThat(actualStr).as("The key schema for record with key " + SchemaUtil.asString(actual.key()) + " did not match expected schema").isEqualTo(expectedStr); } if (!Objects.equals(actualValueSchema, expectedValueSchema)) { String actualStr = SchemaUtil.asString(actualValueSchema); String expectedStr = SchemaUtil.asString(expectedValueSchema); assertThat(actualStr).isEqualTo(expectedStr); } assertEquals(actualKeySchema, actual.key(), expected.key(), "key", "", ignoreFields, comparatorsByName, comparatorsBySchemaName); assertEquals(actualValueSchema, actual.value(), expected.value(), "value", "", ignoreFields, comparatorsByName, comparatorsBySchemaName); }
@Test public void checkDirectAddComponentWithObjectToComponentizer() throws Exception { JLabel label1 = new JLabel("Dummy1"); JComponent parent = Componentizer.create().fixedPref(label1).component(); JLabel label2 = new JLabel("Dummy2"); try { parent.add(label2, new Object()); fail("Adding a component directly to a container using Componentizer " + "should throw IllegalArgumentException!"); } catch (IllegalArgumentException e) { assertThat(e.getMessage()).as("IllegalArgumentException.getMessage()") .isEqualTo("Do not use this method"); } }
@Test public void checkDirectRemoveComponentFromDesignGridContainer() throws Exception { JLabel label1 = new JLabel("Dummy1"); JPanel parent = new JPanel(); DesignGridLayout layout = new DesignGridLayout(parent); layout.row().grid(label1); try { parent.remove(label1); fail("Removing a component directly to a container using DesignGridLayout " + "should throw IllegalArgumentException!"); } catch (IllegalArgumentException e) { assertThat(e.getMessage()).as("IllegalArgumentException.getMessage()") .isEqualTo("Do not use this method"); } }
@Test public void checkDirectAddComponentToComponentizer() throws Exception { JLabel label1 = new JLabel("Dummy1"); JComponent parent = Componentizer.create().fixedPref(label1).component(); JLabel label2 = new JLabel("Dummy2"); try { parent.add(label2); fail("Adding a component directly to a container using Componentizer " + "should throw IllegalArgumentException!"); } catch (IllegalArgumentException e) { assertThat(e.getMessage()).as("IllegalArgumentException.getMessage()") .isEqualTo("Do not use this method"); } }
@Test public void checkAddSameComponentToOneLeftRow() throws Exception { try { JPanel parent = new JPanel(); DesignGridLayout layout = new DesignGridLayout(parent); JLabel label = new JLabel("Dummy"); layout.row().left().add(label, label); fail(FAIL_ADD_2_COMPONENTS_TO_ONE_ROW); } catch (IllegalArgumentException e) { assertThat(e.getMessage()).as("IllegalArgumentException.getMessage()") .isEqualTo("Do not add the same component twice"); } }
@Test public void checkAddSameComponentToOneGridRow() throws Exception { try { JPanel parent = new JPanel(); DesignGridLayout layout = new DesignGridLayout(parent); JLabel label = new JLabel("Dummy"); layout.row().grid().add(label, label); fail(FAIL_ADD_2_COMPONENTS_TO_ONE_ROW); } catch (IllegalArgumentException e) { assertThat(e.getMessage()).as("IllegalArgumentException.getMessage()") .isEqualTo("Do not add the same component twice"); } }
@Test public void checkDirectRemoveComponentFromComponentizer() throws Exception { JLabel label1 = new JLabel("Dummy1"); JComponent parent = Componentizer.create().fixedPref(label1).component(); try { parent.remove(label1); fail("Removing a component directly to a container using Componentizer " + "should throw IllegalArgumentException!"); } catch (IllegalArgumentException e) { assertThat(e.getMessage()).as("IllegalArgumentException.getMessage()") .isEqualTo("Do not use this method"); } } }
@Test public void checkAddSameComponentToOneBarRow() throws Exception { try { JPanel parent = new JPanel(); DesignGridLayout layout = new DesignGridLayout(parent); JLabel label = new JLabel("Dummy"); layout.row().bar().add(label, Tag.CANCEL).add(label, Tag.APPLY); fail(FAIL_ADD_2_COMPONENTS_TO_ONE_ROW); } catch (IllegalArgumentException e) { assertThat(e.getMessage()).as("IllegalArgumentException.getMessage()") .isEqualTo("Do not add the same component twice"); } }
@Test public void checkAddSameMultiComponentToTwoRows() throws Exception { try { JPanel parent = new JPanel(); DesignGridLayout layout = new DesignGridLayout(parent); JLabel label = new JLabel("Dummy"); layout.row().grid().addMulti(label); layout.row().grid().addMulti(label); fail(FAIL_ADD_2_COMPONENTS_TO_ONE_LAYOUT); } catch (IllegalArgumentException e) { assertThat(e.getMessage()).as("IllegalArgumentException.getMessage()") .isEqualTo("Do not add the same component twice"); } }
@Test public void testMulitpleRequiredness() { ThriftStructMetadataBuilder builder = new ThriftStructMetadataBuilder(new ThriftCatalog(), MultipleRequiredness.class); MetadataErrors metadataErrors = builder.getMetadataErrors(); assertThat(metadataErrors.getErrors()) .as("metadata errors") .hasSize(1); assertThat(metadataErrors.getWarnings()) .as("metadata warnings") .isEmpty(); assertThat(metadataErrors.getErrors().get(0).getMessage()) .as("error message") .containsIgnoringCase("multiple requiredness"); }
@Test public void testMultipleIds() throws Exception { ThriftStructMetadataBuilder builder = new ThriftStructMetadataBuilder(new ThriftCatalog(), MultipleIds.class); MetadataErrors metadataErrors = builder.getMetadataErrors(); assertThat(metadataErrors.getErrors()) .as("metadata errors") .hasSize(1); assertThat(metadataErrors.getWarnings()) .as("metadata warnings") .isEmpty(); assertThat(metadataErrors.getErrors().get(0).getMessage()) .as("error message") .containsIgnoringCase("multiple ids"); }
@Test public void testUnsupportedType() throws Exception { ThriftStructMetadataBuilder builder = new ThriftStructMetadataBuilder(new ThriftCatalog(), UnsupportedJavaType.class); MetadataErrors metadataErrors = builder.getMetadataErrors(); assertThat(metadataErrors.getErrors()) .as("metadata errors") .hasSize(1); assertThat(metadataErrors.getWarnings()) .as("metadata warnings") .isEmpty(); assertThat(metadataErrors.getErrors().get(0).getMessage()) .as("error message") .containsIgnoringCase("not a supported Java type"); }
@Test public void testMultipleTypes() throws Exception { ThriftUnionMetadataBuilder builder = new ThriftUnionMetadataBuilder(new ThriftCatalog(), MultipleTypes.class); MetadataErrors metadataErrors = builder.getMetadataErrors(); assertThat(metadataErrors.getErrors()) .as("metadata errors") .hasSize(1); assertThat(metadataErrors.getWarnings()) .as("metadata warnings") .isEmpty(); assertThat(metadataErrors.getErrors().get(0).getMessage()) .as("error message") .containsIgnoringCase("multiple types"); }
@Test public void testMultipleNames() throws Exception { ThriftStructMetadataBuilder builder = new ThriftStructMetadataBuilder(new ThriftCatalog(), MultipleNames.class); MetadataErrors metadataErrors = builder.getMetadataErrors(); assertThat(metadataErrors.getErrors()) .as("metadata errors") .isEmpty(); assertThat(metadataErrors.getWarnings()) .as("metadata warnings") .hasSize(1); assertThat(metadataErrors.getWarnings().get(0).getMessage()) .as("error message") .containsIgnoringCase("multiple names"); }
@Test public void testNoId() throws Exception { ThriftUnionMetadataBuilder builder = new ThriftUnionMetadataBuilder(new ThriftCatalog(), NoId.class); MetadataErrors metadataErrors = builder.getMetadataErrors(); assertThat(metadataErrors.getErrors()) .as("metadata errors") .hasSize(1); assertThat(metadataErrors.getWarnings()) .as("metadata warnings") .isEmpty(); assertThat(metadataErrors.getErrors().get(0).getMessage()) .as("error message") .containsIgnoringCase("not have an id"); }
@Test public void testMultipleIds() throws Exception { ThriftUnionMetadataBuilder builder = new ThriftUnionMetadataBuilder(new ThriftCatalog(), MultipleIds.class); MetadataErrors metadataErrors = builder.getMetadataErrors(); assertThat(metadataErrors.getErrors()) .as("metadata errors") .hasSize(1); assertThat(metadataErrors.getWarnings()) .as("metadata warnings") .isEmpty(); assertThat(metadataErrors.getErrors().get(0).getMessage()) .as("error message") .containsIgnoringCase("multiple ids"); }
@Test public void testUnsupportedType() throws Exception { ThriftUnionMetadataBuilder builder = new ThriftUnionMetadataBuilder(new ThriftCatalog(), UnsupportedJavaType.class); MetadataErrors metadataErrors = builder.getMetadataErrors(); assertThat(metadataErrors.getErrors()) .as("metadata errors") .hasSize(1); assertThat(metadataErrors.getWarnings()) .as("metadata warnings") .isEmpty(); assertThat(metadataErrors.getErrors().get(0).getMessage()) .as("error message") .containsIgnoringCase("not a supported Java type"); }
@Test public void testNoId() throws Exception { ThriftStructMetadataBuilder builder = new ThriftStructMetadataBuilder(new ThriftCatalog(), NoId.class); MetadataErrors metadataErrors = builder.getMetadataErrors(); assertThat(metadataErrors.getErrors()) .as("metadata errors") .hasSize(1); assertThat(metadataErrors.getWarnings()) .as("metadata warnings") .isEmpty(); assertThat(metadataErrors.getErrors().get(0).getMessage()) .as("error message") .containsIgnoringCase("not have an id"); }
@Test public void testMultipleTypes() throws Exception { ThriftStructMetadataBuilder builder = new ThriftStructMetadataBuilder(new ThriftCatalog(), MultipleTypes.class); MetadataErrors metadataErrors = builder.getMetadataErrors(); assertThat(metadataErrors.getErrors()) .as("metadata errors") .hasSize(1); assertThat(metadataErrors.getWarnings()) .as("metadata warnings") .isEmpty(); assertThat(metadataErrors.getErrors().get(0).getMessage()) .as("error message") .containsIgnoringCase("multiple types"); }
@Test public void testMultipleNames() throws Exception { ThriftUnionMetadataBuilder builder = new ThriftUnionMetadataBuilder(new ThriftCatalog(), MultipleNames.class); MetadataErrors metadataErrors = builder.getMetadataErrors(); assertThat(metadataErrors.getErrors()) .as("metadata errors") .isEmpty(); assertThat(metadataErrors.getWarnings()) .as("metadata warnings") .hasSize(1); assertThat(metadataErrors.getWarnings().get(0).getMessage()) .as("error message") .containsIgnoringCase("multiple names"); }