Commit 413f1df0 authored by Matija Obreza's avatar Matija Obreza
Browse files

mockito in test scope, make tests pass

parent c4094c0a
......@@ -483,6 +483,7 @@
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>2.0.2-beta</version>
<scope>test</scope>
</dependency>
</dependencies>
......
package org.genesys2.unit;
import static org.junit.Assert.assertTrue;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.genesys2.server.exception.UserException;
......@@ -27,18 +29,16 @@ import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertTrue;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = AuthUserDetailsServiceTest.Config.class, initializers = PropertyPlacholderInitializer.class)
@ActiveProfiles("dev")
@DirtiesContext(classMode= DirtiesContext.ClassMode.AFTER_CLASS)
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
public class AuthUserDetailsServiceTest {
private final Log LOG = LogFactory.getLog(AuthUserDetailsServiceTest.class);
@Import({JpaDataConfig.class, HazelcastConfig.class})
@PropertySource({"classpath:application.properties", "classpath:spring/spring.properties"})
@Import({ JpaDataConfig.class, HazelcastConfig.class })
@PropertySource({ "classpath:application.properties", "classpath:spring/spring.properties" })
public static class Config {
@Bean
......@@ -80,8 +80,10 @@ public class AuthUserDetailsServiceTest {
UserDetails userDetails = userDetailsService.loadUserByUsername(user.getEmail());
assertTrue(userDetails != null);
assertTrue(userDetails.getPassword().equals(user.getPassword()));
userService.removeUser(user);
} catch (UserException e) {
e.printStackTrace();
org.junit.Assert.fail(e.getMessage());
}
LOG.info("Test loadUserByUsernameTest passed!");
......
......@@ -31,6 +31,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import static org.junit.Assert.assertTrue;
......@@ -87,21 +88,8 @@ public class ContentSanitizerTest {
String articleBody = "<script></script><h2><small>Genesys account</small><br />Verify your email address</h2><p>You can already use your Genesys account. We need to confirm your email account before granting you access to all Genesys features.</p><p><a href=\"{0}/profile/{1}/validate\" rel=\"nofollow\">Verify {2}</a></p><h2>Validation key: {3}</h2><p>If you didn&#39;t make this request, <a href=\"{0}/profile/{1}/cancel\" rel=\"nofollow\">click here to cancel</a>.</p><p>Thanks,<br />Genesys team</p>";
String expectedBody = "<h2><small>Genesys account</small><br />Verify your email address</h2><p>You can already use your Genesys account. We need to confirm your email account before granting you access to all Genesys features.</p><p><a href=\"{0}/profile/{1}/validate\" rel=\"nofollow\">Verify {2}</a></p><h2>Validation key: {3}</h2><p>If you didn&#39;t make this request, <a href=\"{0}/profile/{1}/cancel\" rel=\"nofollow\">click here to cancel</a>.</p><p>Thanks,<br />Genesys team</p>";
Article article = new Article();
article.setBody(articleBody);
ClassPK classPK = new ClassPK();
classPK.setClassName(Article.class.getName());
classPkRepository.save(classPK);
article.setClassPk(classPK);
article.setLang("en");
article.setSlug("smtp.email-verification");
List<Article> articles = new ArrayList<>();
articles.add(article);
contentService.save(articles);
contentService.createGlobalArticle("smtp.email-verification", Locale.ENGLISH, "Test title", articleBody);
contentSanitizer.sanitizeAll();
......
......@@ -210,10 +210,11 @@ public class EmailVerificationServiceTest {
@Test
public void sendPasswordResetEmailTest() {
LOG.info("Start test-method sendPasswordResetEmailTest");
User user=userService.listUsers(new PageRequest(0, 1)).getContent().get(0);
Mockito.doNothing().when(eMailService).sendMail("title for twoArticle", "<h1>Tho BOdy of twoArticle</h1", "salexandrbasov@gmail.com");
emailVerificationService.sendPasswordResetEmail(userService.listUsers(new PageRequest(0, 1)).getContent().get(0));
Mockito.verify(eMailService).sendMail("title for twoArticle", "<h1>Tho BOdy of twoArticle</h1", "salexandrbasov@gmail.com");
Mockito.doNothing().when(eMailService).sendMail("title for twoArticle", "<h1>Tho BOdy of twoArticle</h1", user.getEmail());
emailVerificationService.sendPasswordResetEmail(user);
Mockito.verify(eMailService).sendMail("title for twoArticle", "<h1>Tho BOdy of twoArticle</h1", user.getEmail());
LOG.info("Test sendPasswordResetEmailTest passed!");
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment