Skip to content

Commit

Permalink
Provide a default Application
Browse files Browse the repository at this point in the history
In case the user don't care :)

Fixes #7
  • Loading branch information
jcgay committed Aug 16, 2017
1 parent 4e227b4 commit 8ee5e65
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Get a notifier:
.initNotifier();
```

The `application` is not mandatory, you'll get a default one if it's not set.

Then send notification:

```java
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.util.Properties;
import java.util.Set;

import static com.google.common.base.Preconditions.checkNotNull;
import static org.slf4j.LoggerFactory.getLogger;

/**
Expand Down Expand Up @@ -38,9 +39,13 @@ public class SendNotification {
private final NotifierProvider provider;

private ConfigurationReader configuration;
private Application application;
private ChosenNotifiers chosenNotifiers;
private Properties additionalConfiguration;
private Application application = Application.builder()
.id("application/x-vnd-jcgay.send-notification-default")
.name("Send Notification (Default)")
.icon(Icon.create(SendNotification.class.getResource("/brochure5.png"), "send-notification"))
.build();

SendNotification(ConfigurationReader configuration, OperatingSystem currentOs) {
this(configuration, new NotifierProvider(currentOs));
Expand Down Expand Up @@ -87,7 +92,7 @@ public Notifier initNotifier() {
* @return fluent builder.
*/
public SendNotification setApplication(Application application) {
this.application = application;
this.application = checkNotNull(application);
return this;
}

Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,24 @@ class SendNotificationSpec extends Specification {
then:
PushbulletNotifier.isInstance(result)
}

def "should get a default Application when none is set"() {
when:
def result = sendNotification
.setChosenNotifier('systemtray')
.chooseNotifier()

then:
result.application.name == 'Send Notification (Default)'
result.application.id == 'application/x-vnd-jcgay.send-notification-default'
result.application.icon.id == 'send-notification'
}

def 'should fail when trying to set a null application'() {
when:
sendNotification.setApplication(null).chooseNotifier()

then:
thrown(NullPointerException)
}
}

0 comments on commit 8ee5e65

Please sign in to comment.