package org.weakref.jmx;

import java.lang.management.ManagementFactory;

import javax.management.InstanceNotFoundException;
import javax.management.MBeanServer;
import javax.management.ObjectName;

import org.testng.Assert;
import org.testng.annotations.Test;

public class TestUnexporter
{
	@Test
	public void testUnexport() throws Exception
	{
		ObjectName objectName = Util.getUniqueObjectName();
		String name = objectName.getCanonicalName();
		MBeanServer server = ManagementFactory.getPlatformMBeanServer();
		MBeanExporter exporter = new MBeanExporter(server);
		exporter.export(name, new TestBean());
		try {
			Assert.assertEquals("Hello!", server.getAttribute(objectName, "Hello"));
		} finally {
			exporter.unexport(name);
		}
		boolean caught = false;
		try {
			server.getAttribute(objectName, "Hello");
			Assert.fail();
		} catch (InstanceNotFoundException e) {
			caught = true;
		}
		Assert.assertTrue(caught);
		caught = false;
		try {
			exporter.unexport(name);
			Assert.fail();
		} catch (RuntimeException e) {
			Assert.assertTrue(e.getCause() instanceof InstanceNotFoundException);
			caught = true;
		}
		Assert.assertTrue(caught);
	}

	public static class TestBean
	{
		@Managed
		public String getHello()
		{
			return "Hello!";
		}
	}
}

@@ -289,16 +289,22 @@
 r%0A%7B%0A
-%09
+    
 @Test%0A
-%09
+    
 publ
@@ -325,16 +325,28 @@
 export()
+%0A           
  throws 
@@ -355,21 +355,30 @@
 ception%0A
-%09%7B%0A%09%09
+    %7B%0A        
 ObjectNa
@@ -421,18 +421,24 @@
 Name();%0A
-%09%09
+        
 String n
@@ -470,26 +470,32 @@
 icalName();%0A
-%09%09
+        
 MBeanServer 
@@ -547,18 +547,24 @@
 rver();%0A
-%09%09
+        
 MBeanExp
@@ -607,18 +607,24 @@
 erver);%0A
-%09%09
+        
 exporter
@@ -654,27 +654,42 @@
 ean());%0A
-%09%09try %7B%0A%09%09%09
+        try %7B%0A            
 Assert.a
@@ -757,25 +757,48 @@
 ));%0A
-%09%09%7D finally %7B%0A%09%09%09
+        %7D%0A        finally %7B%0A            
 expo
@@ -818,22 +818,34 @@
 (name);%0A
-%09%09%7D%0A%09%09
+        %7D%0A        
 boolean 
@@ -860,27 +860,42 @@
  false;%0A
-%09%09try %7B%0A%09%09%09
+        try %7B%0A            
 server.g
@@ -928,19 +928,28 @@
 ello%22);%0A
-%09%09%09
+            
 Assert.f
@@ -947,35 +947,49 @@
  Assert.fail();%0A
-%09%09%7D
+        %7D%0A       
  catch (Instance
@@ -1011,19 +1011,28 @@
 on e) %7B%0A
-%09%09%09
+            
 caught =
@@ -1030,38 +1030,50 @@
  caught = true;%0A
-%09%09%7D%0A%09%09
+        %7D%0A        
 Assert.assertTru
@@ -1083,18 +1083,24 @@
 aught);%0A
-%09%09
+        
 caught =
@@ -1111,19 +1111,34 @@
 se;%0A
-%09%09try %7B%0A%09%09%09
+        try %7B%0A            
 expo
@@ -1158,19 +1158,28 @@
 (name);%0A
-%09%09%09
+            
 Assert.f
@@ -1185,19 +1185,33 @@
 fail();%0A
-%09%09%7D
+        %7D%0A       
  catch (
@@ -1232,19 +1232,28 @@
 on e) %7B%0A
-%09%09%09
+            
 Assert.a
@@ -1314,19 +1314,28 @@
 ption);%0A
-%09%09%09
+            
 caught =
@@ -1345,14 +1345,26 @@
 ue;%0A
-%09%09%7D%0A%09%09
+        %7D%0A        
 Asse
@@ -1390,13 +1390,19 @@
 t);%0A
-%09%7D%0A%0A%09
+    %7D%0A%0A    
 publ
@@ -1426,21 +1426,30 @@
 estBean%0A
-%09%7B%0A%09%09
+    %7B%0A        
 @Managed
@@ -1449,18 +1449,24 @@
 Managed%0A
-%09%09
+        
 public S
@@ -1486,15 +1486,30 @@
 o()%0A
-%09%09%7B%0A%09%09%09
+        %7B%0A            
 retu
@@ -1525,13 +1525,22 @@
 !%22;%0A
-%09%09%7D%0A%09
+        %7D%0A    
 %7D%0A%7D%0A

fix formatting