diff --git a/sdk/servicebus/microsoft-azure-servicebus/src/test/java/com/microsoft/azure/servicebus/SendReceiveTests.java b/sdk/servicebus/microsoft-azure-servicebus/src/test/java/com/microsoft/azure/servicebus/SendReceiveTests.java index b0e67d2609a7..aaafbc2f799d 100644 --- a/sdk/servicebus/microsoft-azure-servicebus/src/test/java/com/microsoft/azure/servicebus/SendReceiveTests.java +++ b/sdk/servicebus/microsoft-azure-servicebus/src/test/java/com/microsoft/azure/servicebus/SendReceiveTests.java @@ -83,11 +83,17 @@ public void tearDown() throws ServiceBusException, InterruptedException, Executi this.drainAllMessages(); } - this.sender.close(); + if (this.sender != null) { + this.sender.close(); + } + if (this.receiver != null) { this.receiver.close(); } - this.factory.close(); + + if (this.factory != null) { + this.factory.close(); + } if (this.shouldCreateEntityForEveryTest()) { managementClient.deleteQueueAsync(this.entityName).get(); diff --git a/sdk/servicebus/microsoft-azure-servicebus/src/test/java/com/microsoft/azure/servicebus/SessionTests.java b/sdk/servicebus/microsoft-azure-servicebus/src/test/java/com/microsoft/azure/servicebus/SessionTests.java index f6eec7dc530f..447019d67a5b 100644 --- a/sdk/servicebus/microsoft-azure-servicebus/src/test/java/com/microsoft/azure/servicebus/SessionTests.java +++ b/sdk/servicebus/microsoft-azure-servicebus/src/test/java/com/microsoft/azure/servicebus/SessionTests.java @@ -87,12 +87,18 @@ public void tearDown() throws ServiceBusException, InterruptedException, Executi if (!this.shouldCreateEntityForEveryTest()) { this.drainSession(); } - - this.sender.close(); + + if (this.sender != null) { + this.sender.close(); + } + if (this.session != null) { this.session.close(); } - this.factory.close(); + + if (this.factory != null) { + this.factory.close(); + } if (this.shouldCreateEntityForEveryTest()) { managementClient.deleteQueueAsync(this.entityName).get();