Prevent null pointer when extracting AccountAttribute

AccountAttribute may contain null values (e.g. ownerEmail);
extract its attributes by checking for null values beforehand
as none of the three attributes are mandatory for a Gerrit
account to exist.

Bug: Issue 10645
Change-Id: I69b762e6ce9460fb87f026a3af0d784e37107f96
diff --git a/src/main/java/com/googlesource/gerrit/plugins/its/base/util/PropertyAttributeExtractor.java b/src/main/java/com/googlesource/gerrit/plugins/its/base/util/PropertyAttributeExtractor.java
index 2a72273..f87f7b5 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/its/base/util/PropertyAttributeExtractor.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/its/base/util/PropertyAttributeExtractor.java
@@ -38,9 +38,15 @@
   Map<String, String> extractFrom(AccountAttribute accountAttribute, String prefix) {
     Map<String, String> properties = new HashMap<>();
     if (accountAttribute != null) {
-      properties.put(prefix + "Email", accountAttribute.email);
-      properties.put(prefix + "Username", accountAttribute.username);
-      properties.put(prefix + "Name", accountAttribute.name);
+      if (accountAttribute.email != null) {
+        properties.put(prefix + "Email", accountAttribute.email);
+      }
+      if (accountAttribute.username != null) {
+        properties.put(prefix + "Username", accountAttribute.username);
+      }
+      if (accountAttribute.name != null) {
+        properties.put(prefix + "Name", accountAttribute.name);
+      }
     }
     return properties;
   }
diff --git a/src/test/java/com/googlesource/gerrit/plugins/its/base/util/PropertyAttributeExtractorTest.java b/src/test/java/com/googlesource/gerrit/plugins/its/base/util/PropertyAttributeExtractorTest.java
index 721e788..3e61bc1 100644
--- a/src/test/java/com/googlesource/gerrit/plugins/its/base/util/PropertyAttributeExtractorTest.java
+++ b/src/test/java/com/googlesource/gerrit/plugins/its/base/util/PropertyAttributeExtractorTest.java
@@ -117,6 +117,51 @@
     assertEquals("Properties do not match", expected, actual);
   }
 
+  public void testChangeAttributeNoOwnerEmail() {
+    AccountAttribute owner = new AccountAttribute();
+    owner.name = "testName";
+    owner.username = "testUsername";
+
+    ChangeAttribute changeAttribute = new ChangeAttribute();
+    changeAttribute.branch = "testBranch";
+    changeAttribute.topic = "testTopic";
+    changeAttribute.subject = "testSubject";
+    changeAttribute.id = "testId";
+    changeAttribute.number = 4711;
+    changeAttribute.url = "http://www.example.org/test";
+    changeAttribute.owner = owner;
+    changeAttribute.commitMessage = "Commit Message";
+    changeAttribute.status = Change.Status.NEW;
+
+    expect(facade.createLinkForWebui("http://www.example.org/test", "http://www.example.org/test"))
+        .andReturn("http://www.example.org/test");
+
+    replayMocks();
+
+    PropertyAttributeExtractor extractor = injector.getInstance(PropertyAttributeExtractor.class);
+
+    Map<String, String> actual = extractor.extractFrom(changeAttribute);
+
+    ImmutableMap<String, String> expected =
+        new ImmutableMap.Builder<String, String>()
+            .put("branch", "testBranch")
+            .put("topic", "testTopic")
+            .put("subject", "testSubject")
+            .put("escapedSubject", "testSubject")
+            .put("changeId", "testId")
+            .put("changeNumber", "4711")
+            .put("changeUrl", "http://www.example.org/test")
+            .put("status", Change.Status.NEW.name())
+            .put("ownerName", "testName")
+            .put("ownerUsername", "testUsername")
+            .put("commitMessage", "Commit Message")
+            .put("formatChangeUrl", "http://www.example.org/test")
+            .put("private", "false")
+            .put("wip", "false")
+            .build();
+    assertEquals("Properties do not match", expected, actual);
+  }
+
   public void testChangeAttributeFull() {
     AccountAttribute owner = new AccountAttribute();
     owner.email = "testEmail";