DataSetReferenceAvroTruncator implements AvroTruncator<DataSetReference> { @Override public DataSetReference truncate(DataSetReference source) { if (Objects.nonNull(source.getCreatorNames())) { source.setCreatorNames(creatorNamesTruncator.apply(source.getCreatorNames())); } if (Objects.nonNull(source.getTitles())) { source.setTitles(titlesTruncator.apply(source.getTitles())); } if (Objects.nonNull(source.getDescription())) { source.setDescription(descriptionTruncator.apply(source.getDescription())); } return source; } private  DataSetReferenceAvroTruncator(int maxCreatorNamesSize,
                                          int maxCreatorNameLength,
                                          int maxTitlesSize,
                                          int maxTitleLength,
                                          int maxDescriptionLength); @Override DataSetReference truncate(DataSetReference source); static Builder newBuilder();  }
@Test public void shouldNotTruncateCreatorNamesWhenItIsNull() { DataSetReference source = createDataSetReference(); DataSetReference result = dataSetReferenceAvroTruncator.truncate(source); assertEquals(source, result); verify(creatorNamesTruncator, never()).apply(any()); }
@Test public void shouldTruncateCreatorNamesWhenItIsNotNull() { DataSetReference source = createDataSetReference(); List<CharSequence> creatorNames = Collections.singletonList("creator name"); source.setCreatorNames(creatorNames); List<CharSequence> truncated = Collections.singletonList("truncated"); when(creatorNamesTruncator.apply(creatorNames)).thenReturn(truncated); DataSetReference result = dataSetReferenceAvroTruncator.truncate(source); assertEquals(truncated, result.getCreatorNames()); }
@Test public void shouldNotTruncateTitlesWhenItIsNull() { DataSetReference source = createDataSetReference(); DataSetReference result = dataSetReferenceAvroTruncator.truncate(source); assertEquals(source, result); verify(titlesTruncator, never()).apply(any()); }
@Test public void shouldTruncateTitlesWhenItIsNotNull() { DataSetReference source = createDataSetReference(); List<CharSequence> titles = Collections.singletonList("title"); source.setTitles(titles); List<CharSequence> truncated = Collections.singletonList("truncated"); when(titlesTruncator.apply(titles)).thenReturn(truncated); DataSetReference result = dataSetReferenceAvroTruncator.truncate(source); assertEquals(truncated, result.getTitles()); }
@Test public void shouldNotTruncateDescriptionWhenItIsNull() { DataSetReference source = createDataSetReference(); DataSetReference result = dataSetReferenceAvroTruncator.truncate(source); assertEquals(source, result); verify(descriptionTruncator, never()).apply(any()); }
@Test public void shouldTruncateAbstractWhenItIsNotNull() { DataSetReference source = createDataSetReference(); source.setDescription("description"); when(descriptionTruncator.apply("description")).thenReturn("truncated"); DataSetReference result = dataSetReferenceAvroTruncator.truncate(source); assertEquals("truncated", result.getDescription()); }