Fix dispose issues identified by Gendarme (part 3)

This patch includes the cases that required changes in test code.

Change-Id: Icfd7271fdb62cab9e6f86bd4c4b81c9293c0ed72