Skip to content

Commit e5fb462

Browse files
committed
feat(mail): Introduce EnvironmentProvider interface for SMTP settings
Introduced an interface to abstract the retrieval of environment variables for the SMTP mail service. Key changes: - Created a new interface with methods. - Refactored to implement the new interface. - Updated to depend on the interface instead of the concrete class. This change allows for easier mocking of environment variables in tests, improving the overall testability of the mail service and promoting a more decoupled design.
1 parent eb5794b commit e5fb462

3 files changed

Lines changed: 27 additions & 3 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.google.appengine.api.mail;
2+
3+
/**
4+
* An interface for providing environment variables.
5+
*/
6+
interface EnvironmentProvider {
7+
/**
8+
* Gets the value of the specified environment variable.
9+
* @param name the name of the environment variable
10+
* @return the string value of the variable, or {@code null} if the variable is not defined
11+
*/
12+
String getenv(String name);
13+
14+
/**
15+
* Gets the value of the specified environment variable, returning a default value if the
16+
* variable is not defined.
17+
* @param name the name of the environment variable
18+
* @param defaultValue the default value to return
19+
* @return the string value of the variable, or the default value if the variable is not defined
20+
*/
21+
String getenv(String name, String defaultValue);
22+
}

api/src/main/java/com/google/appengine/api/mail/MailServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@
5353
*/
5454
class MailServiceImpl implements MailService {
5555
static final String PACKAGE = "mail";
56-
private final SystemEnvironmentProvider envProvider;
56+
private final EnvironmentProvider envProvider;
5757

5858
/** Default constructor, used in production. */
5959
MailServiceImpl() {
6060
this(new SystemEnvironmentProvider());
6161
}
6262

6363
/** Constructor for testing, allowing a mock environment provider. */
64-
MailServiceImpl(SystemEnvironmentProvider envProvider) {
64+
MailServiceImpl(EnvironmentProvider envProvider) {
6565
this.envProvider = envProvider;
6666
}
6767

api/src/main/java/com/google/appengine/api/mail/SystemEnvironmentProvider.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
/**
44
* A simple wrapper around {@link System} to allow for easier testing.
55
*/
6-
class SystemEnvironmentProvider {
6+
class SystemEnvironmentProvider implements EnvironmentProvider {
77
/**
88
* Gets the value of the specified environment variable.
99
* @param name the name of the environment variable
1010
* @return the string value of the variable, or {@code null} if the variable is not defined
1111
*/
12+
@Override
1213
public String getenv(String name) {
1314
return System.getenv(name);
1415
}
@@ -20,6 +21,7 @@ public String getenv(String name) {
2021
* @param defaultValue the default value to return
2122
* @return the string value of the variable, or the default value if the variable is not defined
2223
*/
24+
@Override
2325
public String getenv(String name, String defaultValue) {
2426
String value = System.getenv(name);
2527
return value != null ? value : defaultValue;

0 commit comments

Comments
 (0)