Program: 124548
Project: 124548
Buggy source:
@Test public void testValidContext(){
  final String region=Regions.US_WEST_2.getName();
  final String instanceId=RandomStringUtils.random(20,"String_Node_Str");
  final String availabilityZone=region + RandomStringUtils.random(20,"String_Node_Str");
  final String environment=RandomStringUtils.random(20,"String_Node_Str");
  final String userData=new UserData(environment).toString();
  final String elbName=environment + "String_Node_Str";
  final String exhibitorUrl="String_Node_Str" + elbName + "String_Node_Str"+ region+ "String_Node_Str";
  final int exhibitorPort=80;
  final String version="String_Node_Str";
  Ec2MetadataClient ec2MetadataClient=EasyMock.createMock(Ec2MetadataClient.class);
  EasyMock.expect(ec2MetadataClient.getAvailabilityZone()).andAnswer(new IAnswer<String>(){
    @Override public String answer() throws Throwable {
      return availabilityZone;
    }
  }
);
  EasyMock.expect(ec2MetadataClient.getInstanceId()).andAnswer(new IAnswer<String>(){
    @Override public String answer() throws Throwable {
      return instanceId;
    }
  }
);
  EasyMock.expect(ec2MetadataClient.getUserData()).andAnswer(new IAnswer<String>(){
    @Override public String answer() throws Throwable {
      return userData;
    }
  }
);
  EasyMock.expect(ec2MetadataClient.getPrivateIpAddress()).andAnswer(new IAnswer<String>(){
    @Override public String answer() throws Throwable {
      return "String_Node_Str";
    }
  }
);
  EasyMock.expect(ec2MetadataClient.getPublicIpAddress()).andAnswer(new IAnswer<String>(){
    @Override public String answer() throws Throwable {
      return "String_Node_Str";
    }
  }
);
  AmazonEC2 amazonEC2=EasyMock.createMock(AmazonEC2.class);
  EasyMock.expect(amazonEC2.describeRegions()).andAnswer(new IAnswer<DescribeRegionsResult>(){
    @Override public DescribeRegionsResult answer() throws Throwable {
      DescribeRegionsResult result=new DescribeRegionsResult();
      List<Region> regions=new ArrayList<>();
      for (      Regions region : Regions.values()) {
        Region r=new Region();
        r.setRegionName(region.getName());
        regions.add(r);
      }
      result.setRegions(regions);
      return result;
    }
  }
);
  EasyMock.expect(amazonEC2.describeTags(EasyMock.anyObject(DescribeTagsRequest.class))).andAnswer(new IAnswer<DescribeTagsResult>(){
    @Override public DescribeTagsResult answer() throws Throwable {
      return new DescribeTagsResult();
    }
  }
);
  com.amazonaws.regions.Region r=com.amazonaws.regions.Region.getRegion(Regions.fromName(region));
  amazonEC2.setRegion(eqRegion(r));
  EasyMock.expectLastCall();
  AmazonElasticLoadBalancing amazonElasticLoadBalancing=EasyMock.createMock(AmazonElasticLoadBalancing.class);
  EasyMock.expect(amazonElasticLoadBalancing.describeLoadBalancers()).andAnswer(new IAnswer<DescribeLoadBalancersResult>(){
    @Override public DescribeLoadBalancersResult answer() throws Throwable {
      DescribeLoadBalancersResult result=new DescribeLoadBalancersResult();
      List<LoadBalancerDescription> loadBalancers=new ArrayList<>();
      LoadBalancerDescription lb1=new LoadBalancerDescription();
      lb1.setDNSName(exhibitorUrl);
      lb1.setLoadBalancerName(elbName);
      List<ListenerDescription> listenerDescriptions=new ArrayList<>();
      ListenerDescription httpListenerDescription=new ListenerDescription();
      Listener httpListener=new Listener();
      httpListener.setProtocol("String_Node_Str");
      httpListener.setLoadBalancerPort(exhibitorPort);
      httpListener.setInstancePort(8080);
      httpListenerDescription.setListener(httpListener);
      ListenerDescription httpsListenerDescription=new ListenerDescription();
      Listener httpsListener=new Listener();
      httpsListener.setProtocol("String_Node_Str");
      httpsListener.setLoadBalancerPort(443);
      httpsListener.setInstancePort(8080);
      httpsListenerDescription.setListener(httpListener);
      listenerDescriptions.add(httpListenerDescription);
      listenerDescriptions.add(httpsListenerDescription);
      lb1.setListenerDescriptions(listenerDescriptions);
      loadBalancers.add(lb1);
      result.setLoadBalancerDescriptions(loadBalancers);
      return result;
    }
  }
);
  amazonElasticLoadBalancing.setRegion(eqRegion(r));
  EasyMock.expectLastCall();
  EasyMock.replay(ec2MetadataClient,amazonEC2,amazonElasticLoadBalancing);
  ServerInstanceContext context=new ServerInstanceContext(ec2MetadataClient,amazonEC2,amazonElasticLoadBalancing);
  Assert.assertEquals(region,context.getRegion());
  Assert.assertEquals(instanceId,context.getInstanceId());
  Assert.assertEquals(availabilityZone,context.getAvailabilityZone());
  Assert.assertEquals(environment,context.getEnvironment());
  Assert.assertEquals(exhibitorUrl,context.getExhibitorHost());
  Assert.assertEquals(exhibitorPort,context.getExhibitorPort());
  Assert.assertNull(context.getAppName());
  EasyMock.verify(ec2MetadataClient,amazonEC2,amazonElasticLoadBalancing);
  EasyMock.reset(amazonEC2,amazonElasticLoadBalancing);
  amazonEC2.shutdown();
  EasyMock.expectLastCall();
  amazonElasticLoadBalancing.shutdown();
  EasyMock.expectLastCall();
  String name=RandomStringUtils.random(20,"String_Node_Str");
  CreateTagsRequest request=new CreateTagsRequest();
  String tagName=Joiner.on("String_Node_Str").join(environment,name,version);
  List<Tag> tags=new ArrayList<>();
  tags.add(new Tag().withKey("String_Node_Str").withValue(tagName));
  tags.add(new Tag().withKey("String_Node_Str").withValue(environment));
  tags.add(new Tag().withKey("String_Node_Str").withValue(version));
  tags.add(new Tag().withKey("String_Node_Str").withValue(name));
  request.setTags(tags);
  ArrayList<String> resources=new ArrayList<>();
  resources.add(instanceId);
  request.setResources(resources);
  amazonEC2.createTags(eqCreateTagsRequest(request));
  EasyMock.expectLastCall();
  EasyMock.replay(amazonEC2,amazonElasticLoadBalancing);
  context.setAppName(name);
  context.setVersion(version);
  context.tagInstance(tagName);
  Assert.assertEquals(name,context.getAppName());
  context.shutdown();
  EasyMock.verify(ec2MetadataClient,amazonEC2,amazonElasticLoadBalancing);
}

Fixed version (ground truth):
@Test public void testValidContext(){
  final String region=Regions.US_WEST_2.getName();
  final String instanceId=RandomStringUtils.random(20,"String_Node_Str");
  final String availabilityZone=region + RandomStringUtils.random(20,"String_Node_Str");
  final String environment=RandomStringUtils.random(20,"String_Node_Str");
  final String userData=new UserData(environment).toString();
  final String elbName=environment + "String_Node_Str";
  final String exhibitorUrl="String_Node_Str" + elbName + "String_Node_Str"+ region+ "String_Node_Str";
  final int exhibitorPort=80;
  final String version="String_Node_Str";
  Ec2MetadataClient ec2MetadataClient=EasyMock.createMock(Ec2MetadataClient.class);
  EasyMock.expect(ec2MetadataClient.getAvailabilityZone()).andAnswer(new IAnswer<String>(){
    @Override public String answer() throws Throwable {
      return availabilityZone;
    }
  }
);
  EasyMock.expect(ec2MetadataClient.getInstanceId()).andAnswer(new IAnswer<String>(){
    @Override public String answer() throws Throwable {
      return instanceId;
    }
  }
);
  EasyMock.expect(ec2MetadataClient.getUserData()).andAnswer(new IAnswer<String>(){
    @Override public String answer() throws Throwable {
      return userData;
    }
  }
);
  EasyMock.expect(ec2MetadataClient.getPrivateIpAddress()).andAnswer(new IAnswer<String>(){
    @Override public String answer() throws Throwable {
      return "String_Node_Str";
    }
  }
);
  EasyMock.expect(ec2MetadataClient.getPublicIpAddress()).andAnswer(new IAnswer<String>(){
    @Override public String answer() throws Throwable {
      return "String_Node_Str";
    }
  }
);
  AmazonEC2 amazonEC2=EasyMock.createMock(AmazonEC2.class);
  EasyMock.expect(amazonEC2.describeRegions()).andAnswer(new IAnswer<DescribeRegionsResult>(){
    @Override public DescribeRegionsResult answer() throws Throwable {
      DescribeRegionsResult result=new DescribeRegionsResult();
      List<Region> regions=new ArrayList<>();
      for (      Regions region : Regions.values()) {
        Region r=new Region();
        r.setRegionName(region.getName());
        regions.add(r);
      }
      result.setRegions(regions);
      return result;
    }
  }
);
  EasyMock.expect(amazonEC2.describeTags(EasyMock.anyObject(DescribeTagsRequest.class))).andAnswer(new IAnswer<DescribeTagsResult>(){
    @Override public DescribeTagsResult answer() throws Throwable {
      return new DescribeTagsResult();
    }
  }
);
  com.amazonaws.regions.Region r=com.amazonaws.regions.Region.getRegion(Regions.fromName(region));
  amazonEC2.setRegion(eqRegion(r));
  EasyMock.expectLastCall();
  AmazonElasticLoadBalancing amazonElasticLoadBalancing=EasyMock.createMock(AmazonElasticLoadBalancing.class);
  EasyMock.expect(amazonElasticLoadBalancing.describeLoadBalancers()).andAnswer(new IAnswer<DescribeLoadBalancersResult>(){
    @Override public DescribeLoadBalancersResult answer() throws Throwable {
      DescribeLoadBalancersResult result=new DescribeLoadBalancersResult();
      List<LoadBalancerDescription> loadBalancers=new ArrayList<>();
      LoadBalancerDescription lb1=new LoadBalancerDescription();
      lb1.setDNSName(exhibitorUrl);
      lb1.setLoadBalancerName(elbName);
      List<ListenerDescription> listenerDescriptions=new ArrayList<>();
      ListenerDescription httpListenerDescription=new ListenerDescription();
      Listener httpListener=new Listener();
      httpListener.setProtocol("String_Node_Str");
      httpListener.setLoadBalancerPort(exhibitorPort);
      httpListener.setInstancePort(8080);
      httpListenerDescription.setListener(httpListener);
      ListenerDescription httpsListenerDescription=new ListenerDescription();
      Listener httpsListener=new Listener();
      httpsListener.setProtocol("String_Node_Str");
      httpsListener.setLoadBalancerPort(443);
      httpsListener.setInstancePort(8080);
      httpsListenerDescription.setListener(httpListener);
      listenerDescriptions.add(httpListenerDescription);
      listenerDescriptions.add(httpsListenerDescription);
      lb1.setListenerDescriptions(listenerDescriptions);
      loadBalancers.add(lb1);
      result.setLoadBalancerDescriptions(loadBalancers);
      return result;
    }
  }
);
  amazonElasticLoadBalancing.setRegion(eqRegion(r));
  EasyMock.expectLastCall();
  EasyMock.replay(ec2MetadataClient,amazonEC2,amazonElasticLoadBalancing);
  ServerInstanceContext context=new ServerInstanceContext(ec2MetadataClient,amazonEC2,amazonElasticLoadBalancing);
  Assert.assertEquals(region,context.getRegion());
  Assert.assertEquals(instanceId,context.getInstanceId());
  Assert.assertEquals(availabilityZone,context.getAvailabilityZone());
  Assert.assertEquals(environment,context.getEnvironment());
  Assert.assertEquals(exhibitorUrl,context.getExhibitorHost());
  Assert.assertEquals(exhibitorPort,context.getExhibitorPort());
  Assert.assertNull(context.getAppName());
  EasyMock.verify(ec2MetadataClient,amazonEC2,amazonElasticLoadBalancing);
  EasyMock.reset(amazonEC2,amazonElasticLoadBalancing);
  amazonEC2.shutdown();
  EasyMock.expectLastCall();
  amazonElasticLoadBalancing.shutdown();
  EasyMock.expectLastCall();
  String name=RandomStringUtils.random(20,"String_Node_Str");
  CreateTagsRequest request=new CreateTagsRequest();
  String tagName=Joiner.on("String_Node_Str").join(environment,name,version);
  List<Tag> tags=new ArrayList<>();
  tags.add(new Tag().withKey("String_Node_Str").withValue(tagName));
  tags.add(new Tag().withKey("String_Node_Str").withValue(environment));
  tags.add(new Tag().withKey("String_Node_Str").withValue(version));
  tags.add(new Tag().withKey("String_Node_Str").withValue(name));
  request.setTags(tags);
  ArrayList<String> resources=new ArrayList<>();
  resources.add(instanceId);
  request.setResources(resources);
  amazonEC2.createTags(eqCreateTagsRequest(request));
  EasyMock.expectLastCall();
  EasyMock.replay(amazonEC2,amazonElasticLoadBalancing);
  context.setAppName(name);
  context.setVersion(version);
  context.tagInstance();
  Assert.assertEquals(name,context.getAppName());
  context.shutdown();
  EasyMock.verify(ec2MetadataClient,amazonEC2,amazonElasticLoadBalancing);
}