Skip to content

Commit

Permalink
#1298 unit tests for PlatformInvoiceEmailNotification
Browse files Browse the repository at this point in the history
  • Loading branch information
amihaiemil committed Oct 31, 2022
1 parent 0b7ba13 commit 3b333e2
Show file tree
Hide file tree
Showing 2 changed files with 162 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
/**
* Copyright (c) 2020-2022, Self XDSD Contributors
* All rights reserved.
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"),
* to read the Software only. Permission is hereby NOT GRANTED to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software.
* <p>
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package com.selfxdsd.core;

import com.selfxdsd.api.EmailNotification;
Expand Down Expand Up @@ -36,8 +58,8 @@ public String toName() {

@Override
public String subject() {
return "New Platform Invoice "
+ "(ID: " + this.platformInvoice.id() + ")";
return "New Platform Invoice created "
+ "(Id: " + this.platformInvoice.id() + ")";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/**
* Copyright (c) 2020-2022, Self XDSD Contributors
* All rights reserved.
* <p>
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"),
* to read the Software only. Permission is hereby NOT GRANTED to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software.
* <p>
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package com.selfxdsd.core;

import com.selfxdsd.api.PlatformInvoice;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.mockito.Mockito;

import java.time.LocalDateTime;

/**
* Unit tests for {@link PlatformInvoiceEmailNotification}.
* @author Mihai Andronache ([email protected])
* @version $Id$
* @since 0.0.99
*/
public final class PlatformInvoiceEmailNotificationTestCase {

/**
* It can return the "to" e-mail address.
*/
@Test
public void returnsToEmailAddress() {
MatcherAssert.assertThat(
new PlatformInvoiceEmailNotification(
Mockito.mock(PlatformInvoice.class)
).to(),
Matchers.equalTo("[email protected]")
);
}

/**
* It can return the "to" name.
*/
@Test
public void returnsToName() {
MatcherAssert.assertThat(
new PlatformInvoiceEmailNotification(
Mockito.mock(PlatformInvoice.class)
).toName(),
Matchers.equalTo("Self XDSD Admin")
);
}

/**
* It can return the "from" e-mail address.
*/
@Test
public void returnsFromEmailAddress() {
MatcherAssert.assertThat(
new PlatformInvoiceEmailNotification(
Mockito.mock(PlatformInvoice.class)
).from(),
Matchers.equalTo("[email protected]")
);
}

/**
* It can return the "from" name.
*/
@Test
public void returnsFromName() {
MatcherAssert.assertThat(
new PlatformInvoiceEmailNotification(
Mockito.mock(PlatformInvoice.class)
).fromName(),
Matchers.equalTo("Self XDSD")
);
}

/**
* It can return the type.
*/
@Test
public void returnsType() {
MatcherAssert.assertThat(
new PlatformInvoiceEmailNotification(
Mockito.mock(PlatformInvoice.class)
).type(),
Matchers.equalTo("PlatformInvoide Mail Notification")
);
}

/**
* It can return the subject.
*/
@Test
public void returnsSubject() {
final PlatformInvoice invoice = Mockito.mock(PlatformInvoice.class);
Mockito.when(invoice.id()).thenReturn(15);
MatcherAssert.assertThat(
new PlatformInvoiceEmailNotification(invoice).subject(),
Matchers.equalTo("New Platform Invoice created (Id: 15)")
);
}

/**
* It can return the body.
*/
@Test
public void returnsBody() {
final LocalDateTime createdAt = LocalDateTime.now();
final PlatformInvoice invoice = Mockito.mock(PlatformInvoice.class);
Mockito.when(invoice.id()).thenReturn(15);
Mockito.when(invoice.createdAt()).thenReturn(createdAt);

MatcherAssert.assertThat(
new PlatformInvoiceEmailNotification(invoice).body(),
Matchers.equalTo(
"New platform invoice (id is 15) registered at "
+ createdAt + "."
)
);
}

}

2 comments on commit 3b333e2

@zoeself
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amihaiemil I've opened the Issues [#1301, #1302] for the newly added to-dos.

The to-dos may have been added in an earlier commit, but I've found them just now.

@zoeself
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@amihaiemil I've closed the Issues [#1298] since their to-dos disappeared from the code.

The to-dos may have been removed in an earlier commit, but I've found it just now.

Please sign in to comment.