Skip to content

Commit

Permalink
Purify adapter codes
Browse files Browse the repository at this point in the history
Signed-off-by: Taeik Lim <[email protected]>
  • Loading branch information
acktsap committed Feb 19, 2024
1 parent c9cce27 commit 1a651f2
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemStreamReader;
import org.springframework.lang.NonNull;

import reactor.core.publisher.Flux;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,6 @@ public T read() {
}
}

protected Iterator<? extends T> getIterator() {
if (this.iterator == null) {
this.iterator = Optional.ofNullable(this.iterable)
.map(Iterable::iterator)
.orElseThrow(() -> new IllegalStateException("No iterable is set. Call 'open' first."));
}
return this.iterator;
}

@SuppressWarnings("NullableProblems")
@Override
public void update(ExecutionContext executionContext) {
Expand All @@ -90,4 +81,13 @@ public void update(ExecutionContext executionContext) {
public void close() {
this.delegate.onCloseRead();
}

protected Iterator<? extends T> getIterator() {
if (this.iterator == null) {
this.iterator = Optional.ofNullable(this.iterable)
.map(Iterable::iterator)
.orElseThrow(() -> new IllegalStateException("No iterable is set. Call 'open' first."));
}
return this.iterator;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@

package com.navercorp.spring.batch.plus.item.adapter;

import java.util.Iterator;

import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.ItemStreamReader;
import org.springframework.lang.NonNull;

import java.util.Iterator;

/**
* A delegate for {@link ItemStreamReader} which uses {@link Iterator<T>}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ void testItemWriter() {
assertThat(actual).isInstanceOf(ItemStreamWriterAdapter.class);
}

@SuppressWarnings({"ResultOfMethodCallIgnored", "ConstantConditions"})
@Test
void testPassingNull() {
assertThatThrownBy(() -> AdapterFactory.itemStreamReader(null));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ void testProcess() throws Exception {
assertThat(actual).isEqualTo(expected);
}

@SuppressWarnings({"ResultOfMethodCallIgnored", "ConstantConditions"})
@Test
void testPassingNull() {
// when, then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ void testClose() {
verify(itemStreamReaderDelegate, times(1)).onCloseRead();
}

@SuppressWarnings({"ResultOfMethodCallIgnored", "ConstantConditions"})
@Test
void testPassingNull() {
// when, then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ void testClose() {
verify(itemStreamWriterDelegate, times(1)).onCloseWrite();
}

@SuppressWarnings({"ResultOfMethodCallIgnored", "ConstantConditions"})
@Test
void testPassingNull() {
// when, then
Expand Down

0 comments on commit 1a651f2

Please sign in to comment.