Search in sources :

Example 1 with InstanceOfAssertFactories.list

use of org.assertj.core.api.InstanceOfAssertFactories.list in project today-framework by TAKETODAY.

the class StreamConverterTests method convertFromListToStream.

@Test
@SuppressWarnings("resource")
void convertFromListToStream() throws NoSuchFieldException {
    this.conversionService.addConverterFactory(new StringToNumberConverterFactory());
    List<String> list = Arrays.asList("1", "2", "3");
    TypeDescriptor streamOfInteger = new TypeDescriptor(Types.class.getField("streamOfIntegers"));
    Object result = this.conversionService.convert(list, streamOfInteger);
    assertThat(result).as("Converted object must be a stream").isInstanceOf(Stream.class);
    @SuppressWarnings("unchecked") Stream<Integer> content = (Stream<Integer>) result;
    assertThat(content.mapToInt(x -> x).sum()).isEqualTo(6);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertThatIllegalStateException(org.assertj.core.api.Assertions.assertThatIllegalStateException) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) InstanceOfAssertFactories.list(org.assertj.core.api.InstanceOfAssertFactories.list) Test(org.junit.jupiter.api.Test) ConversionFailedException(cn.taketoday.core.conversion.ConversionFailedException) List(java.util.List) Stream(java.util.stream.Stream) ConverterNotFoundException(cn.taketoday.core.conversion.ConverterNotFoundException) InstanceOfAssertFactories.stream(org.assertj.core.api.InstanceOfAssertFactories.stream) TypeDescriptor(cn.taketoday.core.TypeDescriptor) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) TypeDescriptor(cn.taketoday.core.TypeDescriptor) Stream(java.util.stream.Stream) Test(org.junit.jupiter.api.Test)

Example 2 with InstanceOfAssertFactories.list

use of org.assertj.core.api.InstanceOfAssertFactories.list in project hedera-mirror-node by hashgraph.

the class TokenMintTransactionSupplierTest method createWithCustomNonFungibleDataMessageSize.

@Test
void createWithCustomNonFungibleDataMessageSize() {
    TokenMintTransactionSupplier tokenMintTransactionSupplier = new TokenMintTransactionSupplier();
    tokenMintTransactionSupplier.setAmount(2);
    tokenMintTransactionSupplier.setMaxTransactionFee(1);
    tokenMintTransactionSupplier.setMetadataSize(14);
    tokenMintTransactionSupplier.setTokenId(TOKEN_ID.toString());
    tokenMintTransactionSupplier.setType(TokenType.NON_FUNGIBLE_UNIQUE);
    TokenMintTransaction actual = tokenMintTransactionSupplier.get();
    assertThat(actual).returns(0L, TokenMintTransaction::getAmount).returns(ONE_TINYBAR, TokenMintTransaction::getMaxTransactionFee).returns(TOKEN_ID, TokenMintTransaction::getTokenId).extracting(TokenMintTransaction::getMetadata).returns(2, List::size).returns(14, metadataList -> metadataList.get(0).length).returns(14, metadataList -> metadataList.get(1).length);
}
Also used : TokenMintTransaction(com.hedera.hashgraph.sdk.TokenMintTransaction) Test(org.junit.jupiter.api.Test) TokenType(com.hedera.hashgraph.sdk.TokenType) List(java.util.List) LIST(org.assertj.core.api.InstanceOfAssertFactories.LIST) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TokenMintTransaction(com.hedera.hashgraph.sdk.TokenMintTransaction) Collections(java.util.Collections) AbstractTransactionSupplierTest(com.hedera.mirror.monitor.publish.transaction.AbstractTransactionSupplierTest) StandardCharsets(java.nio.charset.StandardCharsets) List(java.util.List) Test(org.junit.jupiter.api.Test) AbstractTransactionSupplierTest(com.hedera.mirror.monitor.publish.transaction.AbstractTransactionSupplierTest)

Example 3 with InstanceOfAssertFactories.list

use of org.assertj.core.api.InstanceOfAssertFactories.list in project hedera-mirror-node by hashgraph.

the class CryptoTransferTransactionSupplierTest method createWithCustomAllTransfer.

@Test
void createWithCustomAllTransfer() {
    TokenId nftTokenId = TokenId.fromString("0.0.21");
    Hbar transferAmount = Hbar.fromTinybars(2);
    CryptoTransferTransactionSupplier cryptoTransferTransactionSupplier = new CryptoTransferTransactionSupplier();
    cryptoTransferTransactionSupplier.setAmount(2);
    cryptoTransferTransactionSupplier.setMaxTransactionFee(1);
    cryptoTransferTransactionSupplier.setNftTokenId(nftTokenId.toString());
    cryptoTransferTransactionSupplier.setRecipientAccountId(ACCOUNT_ID_2.toString());
    cryptoTransferTransactionSupplier.setSenderAccountId(ACCOUNT_ID.toString());
    cryptoTransferTransactionSupplier.setSerialNumber(new AtomicLong(10));
    cryptoTransferTransactionSupplier.setTokenId(TOKEN_ID.toString());
    cryptoTransferTransactionSupplier.setTransferTypes(Set.of(CRYPTO, NFT, TOKEN));
    TransferTransaction actual = cryptoTransferTransactionSupplier.get();
    assertThat(actual).returns(ONE_TINYBAR, TransferTransaction::getMaxTransactionFee).satisfies(a -> assertThat(a.getHbarTransfers()).containsEntry(ACCOUNT_ID, transferAmount.negated()).containsEntry(ACCOUNT_ID_2, transferAmount)).satisfies(a -> assertThat(a).extracting(TransferTransaction::getTokenNftTransfers, MAP).hasSize(1).extractingByKey(nftTokenId, LIST).extracting("serial", "sender", "receiver").containsExactlyInAnyOrder(tuple(10L, ACCOUNT_ID, ACCOUNT_ID_2), tuple(11L, ACCOUNT_ID, ACCOUNT_ID_2))).extracting(TransferTransaction::getHbarTransfers, MAP).hasSize(2).containsEntry(ACCOUNT_ID, transferAmount.negated()).containsEntry(ACCOUNT_ID_2, transferAmount);
}
Also used : TokenId(com.hedera.hashgraph.sdk.TokenId) Assertions.tuple(org.assertj.core.api.Assertions.tuple) TransferTransaction(com.hedera.hashgraph.sdk.TransferTransaction) MAP(org.assertj.core.api.InstanceOfAssertFactories.MAP) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TOKEN(com.hedera.mirror.monitor.publish.transaction.account.CryptoTransferTransactionSupplier.TransferType.TOKEN) Set(java.util.Set) CRYPTO(com.hedera.mirror.monitor.publish.transaction.account.CryptoTransferTransactionSupplier.TransferType.CRYPTO) NFT(com.hedera.mirror.monitor.publish.transaction.account.CryptoTransferTransactionSupplier.TransferType.NFT) Test(org.junit.jupiter.api.Test) AtomicLong(java.util.concurrent.atomic.AtomicLong) LIST(org.assertj.core.api.InstanceOfAssertFactories.LIST) Hbar(com.hedera.hashgraph.sdk.Hbar) Collections(java.util.Collections) AbstractTransactionSupplierTest(com.hedera.mirror.monitor.publish.transaction.AbstractTransactionSupplierTest) AtomicLong(java.util.concurrent.atomic.AtomicLong) Hbar(com.hedera.hashgraph.sdk.Hbar) TokenId(com.hedera.hashgraph.sdk.TokenId) TransferTransaction(com.hedera.hashgraph.sdk.TransferTransaction) Test(org.junit.jupiter.api.Test) AbstractTransactionSupplierTest(com.hedera.mirror.monitor.publish.transaction.AbstractTransactionSupplierTest)

Example 4 with InstanceOfAssertFactories.list

use of org.assertj.core.api.InstanceOfAssertFactories.list in project today-infrastructure by TAKETODAY.

the class StreamConverterTests method convertFromListToStream.

@Test
@SuppressWarnings("resource")
void convertFromListToStream() throws NoSuchFieldException {
    this.conversionService.addConverterFactory(new StringToNumberConverterFactory());
    List<String> list = Arrays.asList("1", "2", "3");
    TypeDescriptor streamOfInteger = new TypeDescriptor(Types.class.getField("streamOfIntegers"));
    Object result = this.conversionService.convert(list, streamOfInteger);
    assertThat(result).as("Converted object must be a stream").isInstanceOf(Stream.class);
    @SuppressWarnings("unchecked") Stream<Integer> content = (Stream<Integer>) result;
    assertThat(content.mapToInt(x -> x).sum()).isEqualTo(6);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Assertions.assertThatIllegalStateException(org.assertj.core.api.Assertions.assertThatIllegalStateException) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) InstanceOfAssertFactories.list(org.assertj.core.api.InstanceOfAssertFactories.list) Test(org.junit.jupiter.api.Test) ConversionFailedException(cn.taketoday.core.conversion.ConversionFailedException) List(java.util.List) Stream(java.util.stream.Stream) ConverterNotFoundException(cn.taketoday.core.conversion.ConverterNotFoundException) InstanceOfAssertFactories.stream(org.assertj.core.api.InstanceOfAssertFactories.stream) TypeDescriptor(cn.taketoday.core.TypeDescriptor) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) TypeDescriptor(cn.taketoday.core.TypeDescriptor) Stream(java.util.stream.Stream) Test(org.junit.jupiter.api.Test)

Example 5 with InstanceOfAssertFactories.list

use of org.assertj.core.api.InstanceOfAssertFactories.list in project spring-framework by spring-projects.

the class StreamConverterTests method convertFromListToStream.

@Test
@SuppressWarnings("resource")
void convertFromListToStream() throws NoSuchFieldException {
    this.conversionService.addConverterFactory(new StringToNumberConverterFactory());
    List<String> list = Arrays.asList("1", "2", "3");
    TypeDescriptor streamOfInteger = new TypeDescriptor(Types.class.getField("streamOfIntegers"));
    Object result = this.conversionService.convert(list, streamOfInteger);
    assertThat(result).as("Converted object must be a stream").isInstanceOf(Stream.class);
    @SuppressWarnings("unchecked") Stream<Integer> content = (Stream<Integer>) result;
    assertThat(content.mapToInt(x -> x).sum()).isEqualTo(6);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) ConversionFailedException(org.springframework.core.convert.ConversionFailedException) Assertions.assertThatIllegalStateException(org.assertj.core.api.Assertions.assertThatIllegalStateException) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) InstanceOfAssertFactories.list(org.assertj.core.api.InstanceOfAssertFactories.list) ConverterNotFoundException(org.springframework.core.convert.ConverterNotFoundException) Test(org.junit.jupiter.api.Test) List(java.util.List) Stream(java.util.stream.Stream) TypeDescriptor(org.springframework.core.convert.TypeDescriptor) InstanceOfAssertFactories.stream(org.assertj.core.api.InstanceOfAssertFactories.stream) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) TypeDescriptor(org.springframework.core.convert.TypeDescriptor) Stream(java.util.stream.Stream) Test(org.junit.jupiter.api.Test)

Aggregations

Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 Test (org.junit.jupiter.api.Test)5 List (java.util.List)4 Arrays (java.util.Arrays)3 Stream (java.util.stream.Stream)3 Assertions.assertThatExceptionOfType (org.assertj.core.api.Assertions.assertThatExceptionOfType)3 Assertions.assertThatIllegalStateException (org.assertj.core.api.Assertions.assertThatIllegalStateException)3 InstanceOfAssertFactories.list (org.assertj.core.api.InstanceOfAssertFactories.list)3 InstanceOfAssertFactories.stream (org.assertj.core.api.InstanceOfAssertFactories.stream)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 TypeDescriptor (cn.taketoday.core.TypeDescriptor)2 ConversionFailedException (cn.taketoday.core.conversion.ConversionFailedException)2 ConverterNotFoundException (cn.taketoday.core.conversion.ConverterNotFoundException)2 AbstractTransactionSupplierTest (com.hedera.mirror.monitor.publish.transaction.AbstractTransactionSupplierTest)2 Collections (java.util.Collections)2 LIST (org.assertj.core.api.InstanceOfAssertFactories.LIST)2 Hbar (com.hedera.hashgraph.sdk.Hbar)1 TokenId (com.hedera.hashgraph.sdk.TokenId)1 TokenMintTransaction (com.hedera.hashgraph.sdk.TokenMintTransaction)1 TokenType (com.hedera.hashgraph.sdk.TokenType)1