-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
control-service: fix concatAddresses NPE
This change aims to fix the NPE when null is passed to EmailNotification.concatAddresses(). Testing done: unit tests Signed-off-by: Miroslav Ivanov [email protected]
- Loading branch information
1 parent
72f7c90
commit 65787ae
Showing
2 changed files
with
76 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...l_service/src/test/java/com/vmware/taurus/service/notification/EmailNotificationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright 2021 VMware, Inc. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package com.vmware.taurus.service.notification; | ||
|
||
import javax.mail.Address; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import com.vmware.taurus.ControlplaneApplication; | ||
|
||
@SpringBootTest(classes = ControlplaneApplication.class) | ||
public class EmailNotificationTest { | ||
|
||
@Autowired | ||
private EmailNotification emailNotification; | ||
|
||
@Test | ||
public void testConcatAddresses_nullAddresses_shouldReturnNull() { | ||
String result = emailNotification.concatAddresses(null); | ||
Assertions.assertNull(result); | ||
} | ||
|
||
@Test | ||
public void testConcatAddresses_validAddresses_shouldReturnNull() { | ||
String address1 = "[email protected]"; | ||
String address2 = "[email protected]"; | ||
String result = emailNotification.concatAddresses( | ||
new Address[]{createAddress(address1), createAddress(address2)}); | ||
|
||
Assertions.assertEquals(address1 + " " + address2, result); | ||
} | ||
|
||
private static Address createAddress(String address) { | ||
return new Address() { | ||
@Override | ||
public String getType() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return address; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object address) { | ||
return false; | ||
} | ||
}; | ||
} | ||
} |