Program: 5952
Project: 5952
Buggy source:
@Test public void testAuditPublish() throws Exception {
  grantAndAssertSuccess(new NamespaceId(FOO_NAMESPACE),USER,EnumSet.of(Action.ALL));
  getInMemoryAuditPublisher().popMessages();
  final List<AuditMessage> expectedMessages=new ArrayList<>();
  StreamAdmin streamAdmin=getStreamAdmin();
  Id.Stream stream1=Id.Stream.from(FOO_NAMESPACE,"String_Node_Str");
  streamAdmin.create(stream1);
  expectedMessages.add(new AuditMessage(0,stream1.toEntityId(),"String_Node_Str",AuditType.CREATE,AuditPayload.EMPTY_PAYLOAD));
  Id.Stream stream2=Id.Stream.from(FOO_NAMESPACE,"String_Node_Str");
  streamAdmin.create(stream2);
  expectedMessages.add(new AuditMessage(0,stream2.toEntityId(),"String_Node_Str",AuditType.CREATE,AuditPayload.EMPTY_PAYLOAD));
  streamAdmin.truncate(stream1);
  expectedMessages.add(new AuditMessage(0,stream1.toEntityId(),"String_Node_Str",AuditType.TRUNCATE,AuditPayload.EMPTY_PAYLOAD));
  streamAdmin.updateConfig(stream1,new StreamProperties(100L,new FormatSpecification("String_Node_Str",null),100));
  expectedMessages.add(new AuditMessage(0,stream1.toEntityId(),"String_Node_Str",AuditType.UPDATE,AuditPayload.EMPTY_PAYLOAD));
  Id.Run run=new Id.Run(Id.Program.from("String_Node_Str","String_Node_Str",ProgramType.FLOW,"String_Node_Str"),RunIds.generate().getId());
  streamAdmin.addAccess(run,stream1,AccessType.READ);
  expectedMessages.add(new AuditMessage(0,stream1.toEntityId(),"String_Node_Str",AuditType.ACCESS,new AccessPayload(co.cask.cdap.proto.audit.payload.access.AccessType.READ,run.toEntityId())));
  streamAdmin.drop(stream1);
  expectedMessages.add(new AuditMessage(0,stream1.toEntityId(),"String_Node_Str",AuditType.DELETE,AuditPayload.EMPTY_PAYLOAD));
  streamAdmin.dropAllInNamespace(Id.Namespace.from(FOO_NAMESPACE));
  expectedMessages.add(new AuditMessage(0,stream2.toEntityId(),"String_Node_Str",AuditType.DELETE,AuditPayload.EMPTY_PAYLOAD));
  final String systemNs=NamespaceId.SYSTEM.getNamespace();
  final Iterable<AuditMessage> actualMessages=Iterables.filter(getInMemoryAuditPublisher().popMessages(),new Predicate<AuditMessage>(){
    @Override public boolean apply(    AuditMessage input){
      return !(input.getEntityId() instanceof NamespacedId && ((NamespacedId)input.getEntityId()).getNamespace().equals(systemNs));
    }
  }
);
  Assert.assertEquals(expectedMessages,Lists.newArrayList(actualMessages));
}

Fixed version (ground truth):
@Test public void testAuditPublish() throws Exception {
  grantAndAssertSuccess(new NamespaceId(FOO_NAMESPACE),USER,EnumSet.allOf(Action.class));
  getInMemoryAuditPublisher().popMessages();
  final List<AuditMessage> expectedMessages=new ArrayList<>();
  StreamAdmin streamAdmin=getStreamAdmin();
  Id.Stream stream1=Id.Stream.from(FOO_NAMESPACE,"String_Node_Str");
  streamAdmin.create(stream1);
  expectedMessages.add(new AuditMessage(0,stream1.toEntityId(),"String_Node_Str",AuditType.CREATE,AuditPayload.EMPTY_PAYLOAD));
  Id.Stream stream2=Id.Stream.from(FOO_NAMESPACE,"String_Node_Str");
  streamAdmin.create(stream2);
  expectedMessages.add(new AuditMessage(0,stream2.toEntityId(),"String_Node_Str",AuditType.CREATE,AuditPayload.EMPTY_PAYLOAD));
  streamAdmin.truncate(stream1);
  expectedMessages.add(new AuditMessage(0,stream1.toEntityId(),"String_Node_Str",AuditType.TRUNCATE,AuditPayload.EMPTY_PAYLOAD));
  streamAdmin.updateConfig(stream1,new StreamProperties(100L,new FormatSpecification("String_Node_Str",null),100));
  expectedMessages.add(new AuditMessage(0,stream1.toEntityId(),"String_Node_Str",AuditType.UPDATE,AuditPayload.EMPTY_PAYLOAD));
  Id.Run run=new Id.Run(Id.Program.from("String_Node_Str","String_Node_Str",ProgramType.FLOW,"String_Node_Str"),RunIds.generate().getId());
  streamAdmin.addAccess(run,stream1,AccessType.READ);
  expectedMessages.add(new AuditMessage(0,stream1.toEntityId(),"String_Node_Str",AuditType.ACCESS,new AccessPayload(co.cask.cdap.proto.audit.payload.access.AccessType.READ,run.toEntityId())));
  streamAdmin.drop(stream1);
  expectedMessages.add(new AuditMessage(0,stream1.toEntityId(),"String_Node_Str",AuditType.DELETE,AuditPayload.EMPTY_PAYLOAD));
  streamAdmin.dropAllInNamespace(Id.Namespace.from(FOO_NAMESPACE));
  expectedMessages.add(new AuditMessage(0,stream2.toEntityId(),"String_Node_Str",AuditType.DELETE,AuditPayload.EMPTY_PAYLOAD));
  final String systemNs=NamespaceId.SYSTEM.getNamespace();
  final Iterable<AuditMessage> actualMessages=Iterables.filter(getInMemoryAuditPublisher().popMessages(),new Predicate<AuditMessage>(){
    @Override public boolean apply(    AuditMessage input){
      return !(input.getEntityId() instanceof NamespacedId && ((NamespacedId)input.getEntityId()).getNamespace().equals(systemNs));
    }
  }
);
  Assert.assertEquals(expectedMessages,Lists.newArrayList(actualMessages));
}