move method down

This commit is contained in:
Carsten Otto
2021-12-18 15:22:02 +01:00
parent 317af96409
commit 62878602b5
4 changed files with 35 additions and 24 deletions

View File

@@ -30,13 +30,6 @@ public class GrpcChannelsBase {
throw new IllegalStateException("unexpected open initiator: " + openInitiator);
}
Optional<ChannelId> getChannelId(long chanId, ChannelPoint channelPoint) {
if (chanId == 0) {
return resolveChannelId(channelPoint);
}
return Optional.of(ChannelId.fromShortChannelId(chanId));
}
Optional<ChannelId> resolveChannelId(ChannelPoint channelPoint) {
return channelIdResolver.resolveFromChannelPoint(channelPoint);
}

View File

@@ -140,4 +140,11 @@ public class GrpcClosedChannels extends GrpcChannelsBase {
}
throw new IllegalStateException("unexpected close initiator: " + closeInitiator);
}
private Optional<ChannelId> getChannelId(long chanId, ChannelPoint channelPoint) {
if (chanId == 0) {
return resolveChannelId(channelPoint);
}
return Optional.of(ChannelId.fromShortChannelId(chanId));
}
}

View File

@@ -43,23 +43,6 @@ class GrpcChannelsBaseTest {
assertThat(grpcChannelsBase.getOpenInitiator(Initiator.INITIATOR_REMOTE)).isEqualTo(OpenInitiator.REMOTE);
}
@Test
void getChannelId_already_resolved() {
assertThat(grpcChannelsBase.getChannelId(CHANNEL_ID.getShortChannelId(), CHANNEL_POINT)).contains(CHANNEL_ID);
verify(channelIdResolver, never()).resolveFromChannelPoint(any());
}
@Test
void getChannelId_resolved() {
when(channelIdResolver.resolveFromChannelPoint(CHANNEL_POINT)).thenReturn(Optional.of(CHANNEL_ID_2));
assertThat(grpcChannelsBase.getChannelId(0, CHANNEL_POINT)).contains(CHANNEL_ID_2);
}
@Test
void getChannelId_not_resolved() {
assertThat(grpcChannelsBase.getChannelId(0, CHANNEL_POINT)).isEmpty();
}
@Test
void resolveChannelId_resolved() {
when(channelIdResolver.resolveFromChannelPoint(CHANNEL_POINT)).thenReturn(Optional.of(CHANNEL_ID_2));

View File

@@ -1,6 +1,7 @@
package de.cotto.lndmanagej.grpc;
import de.cotto.lndmanagej.hardcoded.HardcodedService;
import de.cotto.lndmanagej.model.Channel;
import de.cotto.lndmanagej.model.ChannelIdResolver;
import de.cotto.lndmanagej.model.CloseInitiator;
import de.cotto.lndmanagej.model.ClosedChannelFixtures;
@@ -222,6 +223,33 @@ class GrpcClosedChannelsTest {
verify(channelIdResolver, never()).resolveFromChannelPoint(any());
}
@Test
void getChannelId_already_resolved() {
when(grpcService.getClosedChannels()).thenReturn(List.of(
closedChannel(CHANNEL_ID_SHORT, COOPERATIVE_CLOSE, INITIATOR_LOCAL, INITIATOR_REMOTE)
));
assertThat(grpcClosedChannels.getClosedChannels()).map(Channel::getId).containsExactly(CHANNEL_ID);
verify(channelIdResolver, never()).resolveFromChannelPoint(any());
}
@Test
void getChannelId_resolved() {
when(grpcService.getClosedChannels()).thenReturn(List.of(
closedChannel(0, COOPERATIVE_CLOSE, INITIATOR_LOCAL, INITIATOR_REMOTE)
));
when(channelIdResolver.resolveFromChannelPoint(CHANNEL_POINT)).thenReturn(Optional.of(CHANNEL_ID_2));
assertThat(grpcClosedChannels.getClosedChannels()).map(Channel::getId).containsExactly(CHANNEL_ID_2);
}
@Test
void getChannelId_not_resolved() {
when(grpcService.getClosedChannels()).thenReturn(List.of(
closedChannel(0, COOPERATIVE_CLOSE, INITIATOR_LOCAL, INITIATOR_REMOTE)
));
assertThat(grpcClosedChannels.getClosedChannels()).isEmpty();
}
private ChannelCloseSummary closedChannel(
long channelId,
ChannelCloseSummary.ClosureType closeType,