18
18
import io .dapr .exceptions .DaprException ;
19
19
import io .dapr .serializer .DaprObjectSerializer ;
20
20
import org .junit .jupiter .api .Test ;
21
+ import org .junit .jupiter .api .AfterEach ;
21
22
22
23
import static org .junit .jupiter .api .Assertions .assertNotNull ;
23
24
import static org .junit .jupiter .api .Assertions .assertThrows ;
27
28
28
29
public class DaprClientBuilderTest {
29
30
31
+ private DaprClient client ;
32
+
33
+ @ AfterEach
34
+ public void cleanup () throws Exception {
35
+ if (client != null ) {
36
+ client .close ();
37
+ client = null ;
38
+ }
39
+ }
40
+
30
41
@ Test
31
42
public void build () {
32
43
DaprObjectSerializer objectSerializer = mock (DaprObjectSerializer .class );
@@ -35,17 +46,17 @@ public void build() {
35
46
DaprClientBuilder daprClientBuilder = new DaprClientBuilder ();
36
47
daprClientBuilder .withObjectSerializer (objectSerializer );
37
48
daprClientBuilder .withStateSerializer (stateSerializer );
38
- DaprClient daprClient = daprClientBuilder .build ();
39
- assertNotNull (daprClient );
49
+ client = daprClientBuilder .build ();
50
+ assertNotNull (client );
40
51
}
41
52
42
53
@ Test
43
54
public void buildWithOverrideSidecarIP () {
44
55
DaprClientBuilder daprClientBuilder = new DaprClientBuilder ();
45
56
daprClientBuilder .withPropertyOverride (Properties .SIDECAR_IP , "unknownhost" );
46
- DaprClient daprClient = daprClientBuilder .build ();
47
- assertNotNull (daprClient );
48
- DaprException thrown = assertThrows (DaprException .class , () -> { daprClient .getMetadata ().block (); });
57
+ client = daprClientBuilder .build ();
58
+ assertNotNull (client );
59
+ DaprException thrown = assertThrows (DaprException .class , () -> { client .getMetadata ().block (); });
49
60
assertTrue (thrown .toString ().contains ("UNAVAILABLE" ), thrown .toString ());
50
61
51
62
}
0 commit comments