Skip to content

Commit

Permalink
fixed some null handling
Browse files Browse the repository at this point in the history
  • Loading branch information
sargue committed Jul 5, 2017
1 parent d9d9005 commit 3119084
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,7 @@ Mail.using(configuration)
## 1.4.0

* New [low level functions](https://github.com/sargue/mailgun/wiki/Mail-content-using-content-helpers#low-level-html) on the HTML builder.

## 1.4.1

* Fixed some null handling
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ Add the dependency to your project:

#### Gradle

`compile 'net.sargue:mailgun:1.4.0'`
`compile 'net.sargue:mailgun:1.4.1'`

#### Maven

```xml
<dependency>
<groupId>net.sargue</groupId>
<artifactId>mailgun</artifactId>
<version>1.4.0</version>
<version>1.4.1</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ apply plugin: 'maven'

group 'net.sargue'
archivesBaseName = 'mailgun'
version '1.4.0'
version '1.4.1'

sourceCompatibility = 1.7

Expand Down
8 changes: 8 additions & 0 deletions src/main/java/net/sargue/mailgun/content/Builder.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,20 @@ public Builder end() {
* @return this builder
*/
public Builder text(String s) {
// null values add no text
if (s == null) {
return this;
}
html.a(Util.escapeXml(s));
text.a(s);
return this;
}

public <T> Builder text(T value) {
// null values add no text
if (value == null) {
return this;
}
//noinspection unchecked
return text(value,
configuration.converter((Class<T>) value.getClass()));
Expand Down
20 changes: 20 additions & 0 deletions src/test/java/net/sargue/mailgun/test/HTMLContentTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -433,4 +433,24 @@ public void nestedTag() {
postHTML,
body.html());
}


@Test
public void nullStringHandling() {
Body body = Body.builder()
.text(null)
.build();
assertEquals(preHTML + postHTML, body.html());
assertEquals(postText, body.text());
}

@Test
public void nullObjectHandling() {
Object o = null;
Body body = Body.builder()
.text(o)
.build();
assertEquals(preHTML + postHTML, body.html());
assertEquals(postText, body.text());
}
}

0 comments on commit 3119084

Please sign in to comment.