1818import io .dapr .exceptions .DaprException ;
1919import io .dapr .serializer .DaprObjectSerializer ;
2020import org .junit .jupiter .api .Test ;
21+ import org .junit .jupiter .api .AfterEach ;
2122
2223import static org .junit .jupiter .api .Assertions .assertNotNull ;
2324import static org .junit .jupiter .api .Assertions .assertThrows ;
2728
2829public class DaprClientBuilderTest {
2930
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+
3041 @ Test
3142 public void build () {
3243 DaprObjectSerializer objectSerializer = mock (DaprObjectSerializer .class );
@@ -35,17 +46,17 @@ public void build() {
3546 DaprClientBuilder daprClientBuilder = new DaprClientBuilder ();
3647 daprClientBuilder .withObjectSerializer (objectSerializer );
3748 daprClientBuilder .withStateSerializer (stateSerializer );
38- DaprClient daprClient = daprClientBuilder .build ();
39- assertNotNull (daprClient );
49+ client = daprClientBuilder .build ();
50+ assertNotNull (client );
4051 }
4152
4253 @ Test
4354 public void buildWithOverrideSidecarIP () {
4455 DaprClientBuilder daprClientBuilder = new DaprClientBuilder ();
4556 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 (); });
4960 assertTrue (thrown .toString ().contains ("UNAVAILABLE" ), thrown .toString ());
5061
5162 }
0 commit comments