1818 */
1919package org .apache .pulsar .client .impl ;
2020
21+ import static org .mockito .Mockito .any ;
22+ import static org .mockito .Mockito .eq ;
23+ import static org .mockito .Mockito .mock ;
24+ import static org .mockito .Mockito .when ;
25+ import static org .testng .Assert .assertNotNull ;
26+ import java .util .HashMap ;
27+ import java .util .Map ;
28+ import java .util .concurrent .CompletableFuture ;
29+ import java .util .concurrent .TimeUnit ;
2130import org .apache .pulsar .client .api .Message ;
2231import org .apache .pulsar .client .api .MessageRouter ;
2332import org .apache .pulsar .client .api .MessageRoutingMode ;
2635import org .apache .pulsar .client .api .Schema ;
2736import org .apache .pulsar .client .api .TopicMetadata ;
2837import org .apache .pulsar .client .impl .conf .ProducerConfigurationData ;
38+ import org .apache .pulsar .client .impl .crypto .MessageCryptoBc ;
2939import org .testng .annotations .BeforeClass ;
3040import org .testng .annotations .Test ;
3141
32- import java .util .HashMap ;
33- import java .util .Map ;
34- import java .util .concurrent .CompletableFuture ;
35- import java .util .concurrent .TimeUnit ;
36-
37- import static org .mockito .Mockito .any ;
38- import static org .mockito .Mockito .eq ;
39- import static org .mockito .Mockito .mock ;
40- import static org .mockito .Mockito .when ;
41- import static org .testng .Assert .assertNotNull ;
42-
4342/**
4443 * Unit tests of {@link ProducerBuilderImpl}.
4544 */
4645public class ProducerBuilderImplTest {
4746
4847 private static final String TOPIC_NAME = "testTopicName" ;
4948 private PulsarClientImpl client ;
50- private ProducerBuilderImpl producerBuilderImpl ;
49+ private ProducerBuilderImpl < byte []> producerBuilderImpl ;
5150
5251 @ BeforeClass (alwaysRun = true )
5352 public void setup () {
54- Producer producer = mock (Producer .class );
53+ Producer <?> producer = mock (Producer .class );
5554 client = mock (PulsarClientImpl .class );
56- producerBuilderImpl = new ProducerBuilderImpl (client , Schema .BYTES );
55+ producerBuilderImpl = new ProducerBuilderImpl <> (client , Schema .BYTES );
5756 when (client .newProducer ()).thenReturn (producerBuilderImpl );
5857
5958 when (client .createProducerAsync (
@@ -66,8 +65,8 @@ public void testProducerBuilderImpl() throws PulsarClientException {
6665 Map <String , String > properties = new HashMap <>();
6766 properties .put ("Test-Key2" , "Test-Value2" );
6867
69- producerBuilderImpl = new ProducerBuilderImpl (client , Schema .BYTES );
70- Producer producer = producerBuilderImpl .topic (TOPIC_NAME )
68+ producerBuilderImpl = new ProducerBuilderImpl <> (client , Schema .BYTES );
69+ Producer <?> producer = producerBuilderImpl .topic (TOPIC_NAME )
7170 .producerName ("Test-Producer" )
7271 .maxPendingMessages (2 )
7372 .addEncryptionKey ("Test-EncryptionKey" )
@@ -78,6 +77,14 @@ public void testProducerBuilderImpl() throws PulsarClientException {
7877 assertNotNull (producer );
7978 }
8079
80+ @ Test
81+ public void testProducerBuilderImplWhenMessageCryptoSet () throws PulsarClientException {
82+ producerBuilderImpl = new ProducerBuilderImpl <>(client , Schema .BYTES );
83+ producerBuilderImpl .topic (TOPIC_NAME ).messageCrypto (new MessageCryptoBc ("ctx1" , true ));
84+ assertNotNull (producerBuilderImpl .create ());
85+ assertNotNull (producerBuilderImpl .getConf ().getMessageCrypto ());
86+ }
87+
8188 @ Test
8289 public void testProducerBuilderImplWhenMessageRoutingModeAndMessageRouterAreNotSet () throws PulsarClientException {
8390 producerBuilderImpl = new ProducerBuilderImpl (client , Schema .BYTES );
0 commit comments