Skip to content

Commit

Permalink
Fix code smells
Browse files Browse the repository at this point in the history
Signed-off-by: sdimitrov9 <[email protected]>
  • Loading branch information
sdimitrov9 committed Dec 9, 2024
1 parent 9d8315f commit 51fdb80
Show file tree
Hide file tree
Showing 80 changed files with 478 additions and 525 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ void testAddContractTransaction() {
var recordItem = RecordItem.builder()
.payerAccountId(EntityId.of(payerAccountId))
.transaction(transaction)
.contractTransactionPredicate((entityId) -> true)
.contractTransactionPredicate(entityId -> true)
.transactionRecord(transactionRecord)
.build();
var account = EntityId.of(id++);
Expand Down Expand Up @@ -652,7 +652,6 @@ void testAddContractTransactionDisabled() {
long id = random.nextLong(2000) + 2000L;
var now = Instant.now();
var payerAccountId = AccountID.newBuilder().setAccountNum(id++).build();
long consensusTimestamp = now.getEpochSecond() * 1_000_000_000 + now.getNano();
var validStart =
Timestamp.newBuilder().setSeconds(now.getEpochSecond() - 1).setNanos(now.getNano());
var transactionBody = TransactionBody.newBuilder()
Expand All @@ -675,7 +674,7 @@ void testAddContractTransactionDisabled() {
var recordItem = RecordItem.builder()
.payerAccountId(EntityId.of(payerAccountId))
.transaction(transaction)
.contractTransactionPredicate((entityId) -> false)
.contractTransactionPredicate(entityId -> false)
.transactionRecord(transactionRecord)
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void filterOnError(CapturedOutput output) {
var exception = new IllegalArgumentException("error");
StepVerifier.withVirtualTime(() -> loggingFilter
.filter(exchange, serverWebExchange -> Mono.error(exception))
.onErrorResume((t) -> exchange.getResponse().setComplete()))
.onErrorResume(t -> exchange.getResponse().setComplete()))
.thenAwait(WAIT)
.expectComplete()
.verify(WAIT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void toEntityId() {
@Test
void validateOneOf() {
GraphQlUtils.validateOneOf("a");
assertThatThrownBy(() -> GraphQlUtils.validateOneOf()).isInstanceOf(IllegalArgumentException.class);
assertThatThrownBy(GraphQlUtils::validateOneOf).isInstanceOf(IllegalArgumentException.class);
assertThatThrownBy(() -> GraphQlUtils.validateOneOf("a", "b")).isInstanceOf(IllegalArgumentException.class);
}

Expand Down
2 changes: 1 addition & 1 deletion hedera-mirror-grpc/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM eclipse-temurin:21-jre-noble as builder
FROM eclipse-temurin:21-jre-noble AS builder
WORKDIR /app
COPY build/libs/*.jar ./
RUN java -Djarmode=layertools -jar *.jar extract
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.hedera.mirror.common.domain.topic.TopicMessage;
import com.hedera.mirror.grpc.domain.TopicMessageFilter;
import java.time.Duration;
import java.util.stream.Collectors;
import java.util.stream.LongStream;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -53,7 +52,7 @@ void slowSubscriberOverflowException() {
.listen(filterFast)
.map(TopicMessage::getSequenceNumber)
.as(StepVerifier::create)
.expectNextSequence(LongStream.range(1, numMessages + 1).boxed().collect(Collectors.toList()))
.expectNextSequence(LongStream.range(1, numMessages + 1).boxed().toList())
.thenCancel()
.verifyLater();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ void findByFilterEmpty() {
@Test
void findByFilterNoMatch() {
TopicMessage topicMessage1 = domainBuilder.topicMessage().block();
TopicMessage topicMessage2 = domainBuilder.topicMessage().block();
TopicMessage topicMessage3 = domainBuilder.topicMessage().block();

TopicMessageFilter filter = TopicMessageFilter.builder()
.startTime(DomainUtils.convertToNanosMax(Instant.now().plusSeconds(10)))
Expand All @@ -65,8 +63,6 @@ void findByFilterWithTopicId() {
domainBuilder.topicMessage(t -> t.topicId(EntityId.of(1))).block();
TopicMessage topicMessage2 =
domainBuilder.topicMessage(t -> t.topicId(EntityId.of(2))).block();
TopicMessage topicMessage3 =
domainBuilder.topicMessage(t -> t.topicId(EntityId.of(3))).block();

TopicMessageFilter filter = TopicMessageFilter.builder()
.topicId(EntityId.of(2L))
Expand Down Expand Up @@ -108,8 +104,6 @@ void findByFilterWithEndTime() {
@Test
void findByFilterWithLimit() {
TopicMessage topicMessage1 = domainBuilder.topicMessage().block();
TopicMessage topicMessage2 = domainBuilder.topicMessage().block();
TopicMessage topicMessage3 = domainBuilder.topicMessage().block();

TopicMessageFilter filter = TopicMessageFilter.builder()
.limit(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import com.hedera.mirror.grpc.domain.ReactiveDomainBuilder;
import com.hedera.mirror.grpc.domain.TopicMessageFilter;
import java.time.Duration;
import java.util.stream.Collectors;
import java.util.stream.LongStream;
import lombok.RequiredArgsConstructor;
import org.junit.jupiter.api.AfterEach;
Expand Down Expand Up @@ -278,7 +277,7 @@ void unthrottledShouldKeepPolling() {
.then(firstBatch::blockLast)
.then(secondBatch::blockLast)
.thenAwait(WAIT)
.expectNextSequence(LongStream.range(1, 11).boxed().collect(Collectors.toList()))
.expectNextSequence(LongStream.range(1, 11).boxed().toList())
.expectComplete()
.verify(WAIT);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import com.hedera.mirror.importer.parser.record.pubsub.PubSubProperties;
import jakarta.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.TestConfiguration;
Expand Down Expand Up @@ -76,7 +75,7 @@ protected List<PubsubMessage> getAllMessages(int numMessages) {
m.ack();
return m.getPubsubMessage();
})
.collect(Collectors.toList());
.toList();
}

@TestConfiguration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,7 @@ void startupWithOtherNetworkIncorrectInitialAddressBookPath() {
otherNetworkImporterProperties,
nodeStakeRepository,
transactionTemplate);
assertThrows(IllegalStateException.class, () -> {
customAddressBookService.getCurrent();
});
assertThrows(IllegalStateException.class, customAddressBookService::getCurrent);
assertEquals(0, addressBookRepository.count());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ private void assertContractResult(RecordItem recordItem) {
var functionResult = getFunctionResult(recordItem);
var createdIds = functionResult.getCreatedContractIDsList().stream()
.map(x -> EntityId.of(x).getId())
.collect(Collectors.toList());
.toList();
var failedInitcode = getFailedInitcode(recordItem);
var hash = getTransactionHash(recordItem);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.time.Instant;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
Expand Down Expand Up @@ -113,7 +112,7 @@ void getFilename(StreamType streamType, StreamFilename.FileType fileType, Instan
Set<StreamType.Extension> extensions =
fileType == DATA ? streamType.getDataExtensions() : streamType.getSignatureExtensions();
List<String> names =
extensions.stream().map(StreamType.Extension::getName).collect(Collectors.toList());
extensions.stream().map(StreamType.Extension::getName).toList();
assertThat(filename).startsWith(expectedPrefix);
assertThat(extension).isIn(names);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ void startDate(long seconds, String fileChoice) {
List<String> expectedFiles = instantFilenamePairs.stream()
.filter(pair -> pair.getLeft().isAfter(startDate))
.map(Pair::getRight)
.collect(Collectors.toList());
.toList();

fileCopier.copy();
downloader.download();
Expand All @@ -542,7 +542,7 @@ void endDate(long seconds, String fileChoice) {
List<String> expectedFiles = instantFilenamePairs.stream()
.filter(pair -> !pair.getLeft().isAfter(importerProperties.getEndDate()))
.map(Pair::getRight)
.collect(Collectors.toList());
.toList();
expectLastStreamFile(Instant.EPOCH);

fileCopier.copy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ void initNoNetworkDefaultBucketName() {
var properties = new CommonDownloaderProperties(mirrorProperties);

mirrorProperties.setNetwork(HederaNetwork.OTHER);
assertThrows(IllegalArgumentException.class, () -> properties.init());
assertThrows(IllegalArgumentException.class, properties::init);

mirrorProperties.setNetwork("mynetwork");
assertThrows(IllegalArgumentException.class, () -> properties.init());
assertThrows(IllegalArgumentException.class, properties::init);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void sidecarTypesFilter() {
super.verifyStreamFiles(List.of(file1, file2), actual -> {
var transactionSidecarRecords = actual.getItems().stream()
.flatMap(r -> r.getSidecarRecords().stream())
.collect(Collectors.toList());
.toList();
assertThat(transactionSidecarRecords).isEmpty();
});
assertThat(importerProperties.getDataPath()).isEmptyDirectory();
Expand All @@ -111,7 +111,7 @@ void sidecarTypesFilterSome() {
var sidecarTypes = recordFile.getItems().stream()
.flatMap(r -> r.getSidecarRecords().stream())
.map(TransactionSidecarRecord::getSidecarRecordsCase)
.collect(Collectors.toList());
.toList();
if (Objects.equals(recordFile.getName(), RECORD_FILE_WITH_SIDECAR)) {
assertThat(sidecarTypes).containsExactly(TransactionSidecarRecord.SidecarRecordsCase.BYTECODE);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void unsupportedNetwork() {
List<Tuple> expectedBlockNumbersAndConsensusEnd =
insertDefaultRecordFiles(Set.of(CORRECT_CONSENSUS_END)).stream()
.map(recordFile -> Tuple.tuple(recordFile.getConsensusEnd(), recordFile.getIndex()))
.collect(Collectors.toList());
.toList();

blockNumberMigration.doMigrate();

Expand All @@ -79,7 +79,7 @@ void theCorrectOffsetMustBeAddedToTheBlockNumbers() {
long offset = CORRECT_BLOCK_NUMBER - 8L;
List<Tuple> expectedBlockNumbersAndConsensusEnd = defaultRecordFiles.stream()
.map(recordFile -> Tuple.tuple(recordFile.getConsensusEnd(), recordFile.getIndex() + offset))
.collect(Collectors.toList());
.toList();

blockNumberMigration.doMigrate();

Expand All @@ -91,7 +91,7 @@ void ifCorrectConsensusEndNotFoundDoNothing() {
List<Tuple> expectedBlockNumbersAndConsensusEnd =
insertDefaultRecordFiles(Set.of(CORRECT_CONSENSUS_END)).stream()
.map(recordFile -> Tuple.tuple(recordFile.getConsensusEnd(), recordFile.getIndex()))
.collect(Collectors.toList());
.toList();

blockNumberMigration.doMigrate();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import lombok.RequiredArgsConstructor;
import org.junit.jupiter.api.AfterEach;
Expand Down Expand Up @@ -273,21 +272,21 @@ void onEndHapiVersionNotMatched() {
.containsExactlyInAnyOrderElementsOf(
Stream.of(cryptoTransfersPair.getLeft(), cryptoTransfersPair.getRight())
.flatMap(Collection::stream)
.collect(Collectors.toList()));
.toList());

assertThat(tokenTransferRepository.findAll())
.containsExactlyInAnyOrderElementsOf(
Stream.of(tokenTransfersPair.getLeft(), tokenTransfersPair.getRight())
.flatMap(Collection::stream)
.collect(Collectors.toList()));
.toList());

var repositoryNftTransfers = new ArrayList<NftTransfer>();
transactionRepository.findAll().forEach(t -> repositoryNftTransfers.addAll(t.getNftTransfer()));
assertThat(repositoryNftTransfers)
.containsExactlyInAnyOrderElementsOf(
Stream.of(nftTransfersTransactionPair.getLeft(), nftTransfersTransactionPair.getRight())
.flatMap(Collection::stream)
.collect(Collectors.toList()));
.toList());
}

private void assertTransfers(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ void migrate() {

// add current tokens, and the expected current tokens
tokens.forEach(
(t) -> t.timestampRange = Range.atLeast(t.getTimestampRange().upperEndpoint()));
t -> t.timestampRange = Range.atLeast(t.getTimestampRange().upperEndpoint()));
var expectedCurrent = expectedHistory.stream()
.map((t) -> t.toBuilder()
.map(t -> t.toBuilder()
.timestampRange(Range.atLeast(t.getTimestampRange().upperEndpoint()))
.build())
.toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,11 @@ void persistTransactionHashInvalid(byte[] bytes) {
});

shardMap.forEach((shard, items) -> assertThat(TestUtils.getShardTransactionHashes(shard, jdbcTemplate))
.isEqualTo(items.stream().filter(TransactionHash::hashIsValid).collect(Collectors.toList())));
.isEqualTo(items.stream().filter(TransactionHash::hashIsValid).toList()));
assertThat(transactionHashRepository.findAll())
.containsExactlyInAnyOrderElementsOf(transactionHashes.stream()
.filter(TransactionHash::hashIsValid)
.collect(Collectors.toList()));
.toList());
}

@SneakyThrows
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void testThreadCommit() {
TestUtils.insertIntoTransactionHash(jdbcTemplate, hash4);
});

transactionTemplate.executeWithoutResult((status) -> {
transactionTemplate.executeWithoutResult(status -> {
try {
transactionHashTxManager.initialize(Collections.singleton(hash1), "transaction_hash");
assertThat(transactionHashTxManager.getItemCount()).isEqualTo(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1342,7 +1342,7 @@ private void assertContractResult(
ObjectAssert<ContractResult> contractResult) {
List<Long> createdContractIds = result.getCreatedContractIDsList().stream()
.map(ContractID::getContractNum)
.collect(Collectors.toList());
.toList();

contractResult
.returns(result.getBloom().toByteArray(), ContractResult::getBloom)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1399,7 +1399,7 @@ void cryptoTransferUpdatesAllowanceAmount() {
TransactionBody transactionBody = getTransactionBody(transaction);
var recordCryptoTransfers = cryptoTransfers.stream()
.map(transfer -> transfer.toBuilder().setIsApproval(false).build())
.collect(Collectors.toList());
.toList();
TransactionRecord record = buildTransactionRecordWithNoTransactions(
builder -> builder.getTransferListBuilder().addAllAccountAmounts(recordCryptoTransfers),
transactionBody,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ void fileUpdateAllToExisting() {
.build());

assertAll(
() -> assertRowCountOnTwoFileTransactions(),
this::assertRowCountOnTwoFileTransactions,
() -> assertTransactionAndRecord(transactionBody, record),
() -> assertFileEntityAndData(transactionBody.getFileUpdate(), record.getConsensusTimestamp()));
}
Expand Down Expand Up @@ -329,7 +329,7 @@ void fileAppendToAddressBook() throws IOException {
() -> assertArrayEquals(addressBook, newAddressBook.getFileData()));

assertAll(
() -> assertRowCountOnAddressBookTransactions(),
this::assertRowCountOnAddressBookTransactions,
() -> assertTransactionAndRecord(transactionBodyUpdate, recordUpdate),
() -> assertTransactionAndRecord(transactionBodyAppend, recordAppend),
() -> assertFileData(fileAppendTransactionBody.getContents(), recordAppend.getConsensusTimestamp()),
Expand Down Expand Up @@ -446,7 +446,7 @@ void fileUpdateContentsToExisting() {
Entity actualFile = getTransactionEntity(record.getConsensusTimestamp());

assertAll(
() -> assertRowCountOnTwoFileTransactions(),
this::assertRowCountOnTwoFileTransactions,
() -> assertTransactionAndRecord(transactionBody, record),
() -> assertFileData(transactionBody.getFileUpdate().getContents(), record.getConsensusTimestamp()),
// Additional entity checks
Expand Down Expand Up @@ -507,7 +507,7 @@ void fileUpdateExpiryToExisting() {

assertAll(
// TODO: Review row count of fileDataRepository with issue #294, probably should be 1
() -> assertRowCountOnTwoFileTransactions(),
this::assertRowCountOnTwoFileTransactions,
() -> assertTransactionAndRecord(transactionBody, record),
// Additional entity checks
() -> assertFalse(actualFile.getDeleted()),
Expand Down Expand Up @@ -575,7 +575,7 @@ void fileUpdateKeysToExisting() {

assertAll(
// TODO: Review row count of fileDataRepository with issue #294, probably should be 1
() -> assertRowCountOnTwoFileTransactions(),
this::assertRowCountOnTwoFileTransactions,
() -> assertTransactionAndRecord(transactionBody, record),
// Additional entity checks
() -> assertFalse(dbFileEntity.getDeleted()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ void tokenCreateWithAutoTokenAssociations(
List<TokenAccount> expectedTokenAccounts) {
List<EntityId> autoAssociatedAccounts = expectedTokenAccounts.stream()
.map(t -> EntityId.of(t.getAccountId()))
.collect(Collectors.toList());
.toList();
tokenCreate(
customFees,
freezeDefault,
Expand Down Expand Up @@ -541,7 +541,7 @@ void tokenCreateWithNfts(
CREATE_TIMESTAMP);
var autoAssociatedAccounts = expectedTokenAccounts.stream()
.map(t -> EntityId.of(t.getAccountId()))
.collect(Collectors.toList());
.toList();

// when
createTokenEntity(
Expand Down
Loading

0 comments on commit 51fdb80

Please sign in to comment.