Try and fix old static wonkiness in test.

parent 5f192dd6
package org.springframework.cloud.netflix.eureka.server; package org.springframework.cloud.netflix.eureka.server;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.springframework.cloud.netflix.eureka.server.EurekaControllerTest.setInstance;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import com.netflix.appinfo.ApplicationInfoManager;
import com.netflix.appinfo.DataCenterInfo;
import com.netflix.appinfo.InstanceInfo;
import com.netflix.appinfo.MyDataCenterInfo;
import com.netflix.eureka.cluster.PeerEurekaNode;
import com.netflix.eureka.cluster.PeerEurekaNodes;
import org.junit.After;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import com.netflix.eureka.util.StatusInfo; import com.netflix.eureka.util.StatusInfo;
...@@ -21,6 +33,19 @@ public class EurekaControllerReplicasTest { ...@@ -21,6 +33,19 @@ public class EurekaControllerReplicasTest {
String empty = new String(); String empty = new String();
private ApplicationInfoManager original;
@Before
public void setup() throws Exception {
this.original = ApplicationInfoManager.getInstance();
setInstance(mock(ApplicationInfoManager.class));
}
@After
public void teardown() throws Exception {
setInstance(this.original);
}
@Test @Test
public void testFilterReplicasNoAuth() throws Exception { public void testFilterReplicasNoAuth() throws Exception {
Map<String, Object> model=new HashMap<String, Object>(); Map<String, Object> model=new HashMap<String, Object>();
......
...@@ -52,6 +52,7 @@ import static org.mockito.Mockito.when; ...@@ -52,6 +52,7 @@ import static org.mockito.Mockito.when;
public class EurekaControllerTest { public class EurekaControllerTest {
private ApplicationInfoManager infoManager; private ApplicationInfoManager infoManager;
private ApplicationInfoManager original;
@Before @Before
public void setup() throws Exception { public void setup() throws Exception {
...@@ -64,6 +65,7 @@ public class EurekaControllerTest { ...@@ -64,6 +65,7 @@ public class EurekaControllerTest {
.build(); .build();
this.infoManager = mock(ApplicationInfoManager.class); this.infoManager = mock(ApplicationInfoManager.class);
this.original = ApplicationInfoManager.getInstance();
setInstance(this.infoManager); setInstance(this.infoManager);
when(this.infoManager.getInfo()).thenReturn(instanceInfo); when(this.infoManager.getInfo()).thenReturn(instanceInfo);
...@@ -90,10 +92,10 @@ public class EurekaControllerTest { ...@@ -90,10 +92,10 @@ public class EurekaControllerTest {
@After @After
public void teardown() throws Exception { public void teardown() throws Exception {
setInstance(null); setInstance(this.original);
} }
void setInstance(ApplicationInfoManager infoManager) throws IllegalAccessException { static void setInstance(ApplicationInfoManager infoManager) throws IllegalAccessException {
Field instance = ReflectionUtils.findField(ApplicationInfoManager.class, "instance"); Field instance = ReflectionUtils.findField(ApplicationInfoManager.class, "instance");
ReflectionUtils.makeAccessible(instance); ReflectionUtils.makeAccessible(instance);
instance.set(null, infoManager); instance.set(null, infoManager);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment