/** * Builds the {@link MultiResourceItemReader}. * * @return a {@link MultiResourceItemReader} */ public MultiResourceItemReader<T> build() { Assert.notNull(this.resources, "resources array is required."); Assert.notNull(this.delegate, "delegate is required."); if (this.saveState) { Assert.state(StringUtils.hasText(this.name), "A name is required when saveState is set to true."); } MultiResourceItemReader<T> reader = new MultiResourceItemReader<>(); reader.setResources(this.resources); reader.setDelegate(this.delegate); reader.setSaveState(this.saveState); reader.setStrict(this.strict); if (comparator != null) { reader.setComparator(this.comparator); } if (StringUtils.hasText(this.name)) { reader.setName(this.name); } return reader; }
/** * No resources to read should result in error in strict mode. */ @Test(expected = IllegalStateException.class) public void testStrictModeEnabled() throws Exception { tested.setResources(new Resource[] {}); tested.setStrict(true); tested.open(ctx); }
/** * No resources to read is OK when strict=false. */ @Test public void testStrictModeDisabled() throws Exception { tested.setResources(new Resource[] {}); tested.setStrict(false); tested.open(ctx); assertTrue("empty input doesn't cause an error", true); }
/** * Builds the {@link MultiResourceItemReader}. * * @return a {@link MultiResourceItemReader} */ public MultiResourceItemReader<T> build() { Assert.notNull(this.resources, "resources array is required."); Assert.notNull(this.delegate, "delegate is required."); if (this.saveState) { Assert.state(StringUtils.hasText(this.name), "A name is required when saveState is set to true."); } MultiResourceItemReader<T> reader = new MultiResourceItemReader<>(); reader.setResources(this.resources); reader.setDelegate(this.delegate); reader.setSaveState(this.saveState); reader.setStrict(this.strict); if (comparator != null) { reader.setComparator(this.comparator); } if (StringUtils.hasText(this.name)) { reader.setName(this.name); } return reader; }