diff --git a/spring-security-modules/spring-security-x509/spring-security-x509-basic-auth/src/main/resources/application.properties b/spring-security-modules/spring-security-x509/spring-security-x509-basic-auth/src/main/resources/application.properties
index f293d6712d..53dfe9976a 100644
--- a/spring-security-modules/spring-security-x509/spring-security-x509-basic-auth/src/main/resources/application.properties
+++ b/spring-security-modules/spring-security-x509/spring-security-x509-basic-auth/src/main/resources/application.properties
@@ -1,8 +1,8 @@
-server.ssl.key-store=../keystore/keystore.jks
+server.ssl.key-store=keystore/keystore.jks
server.ssl.key-store-password=changeit
server.ssl.key-alias=localhost
server.ssl.key-password=changeit
server.ssl.enabled=true
server.port=8443
-security.user.name=Admin
-security.user.password=admin
\ No newline at end of file
+spring.security.user.name=Admin
+spring.security.user.password=admin
\ No newline at end of file
diff --git a/spring-security-modules/spring-security-x509/spring-security-x509-basic-auth/src/test/java/org/baeldung/SpringContextTest.java b/spring-security-modules/spring-security-x509/spring-security-x509-basic-auth/src/test/java/com/baeldung/SpringContextTest.java
similarity index 95%
rename from spring-security-modules/spring-security-x509/spring-security-x509-basic-auth/src/test/java/org/baeldung/SpringContextTest.java
rename to spring-security-modules/spring-security-x509/spring-security-x509-basic-auth/src/test/java/com/baeldung/SpringContextTest.java
index 5c65dd3e8a..1c89f706ab 100644
--- a/spring-security-modules/spring-security-x509/spring-security-x509-basic-auth/src/test/java/org/baeldung/SpringContextTest.java
+++ b/spring-security-modules/spring-security-x509/spring-security-x509-basic-auth/src/test/java/com/baeldung/SpringContextTest.java
@@ -1,4 +1,4 @@
-package org.baeldung;
+package com.baeldung;
import org.junit.Test;
import org.junit.runner.RunWith;
diff --git a/spring-security-modules/spring-security-x509/spring-security-x509-client-auth/src/main/resources/application.properties b/spring-security-modules/spring-security-x509/spring-security-x509-client-auth/src/main/resources/application.properties
index 174eba9f98..743c9c4582 100644
--- a/spring-security-modules/spring-security-x509/spring-security-x509-client-auth/src/main/resources/application.properties
+++ b/spring-security-modules/spring-security-x509/spring-security-x509-client-auth/src/main/resources/application.properties
@@ -4,8 +4,8 @@ server.ssl.key-alias=localhost
server.ssl.key-password=changeit
server.ssl.enabled=true
server.port=8443
-security.user.name=Admin
-security.user.password=admin
+spring.security.user.name=Admin
+spring.security.user.password=admin
server.ssl.trust-store=../keystore/truststore.jks
server.ssl.trust-store-password=changeit
server.ssl.client-auth=need
\ No newline at end of file
diff --git a/spring-security-modules/spring-security-x509/spring-security-x509-client-auth/src/test/java/org/baeldung/SpringContextTest.java b/spring-security-modules/spring-security-x509/spring-security-x509-client-auth/src/test/java/com/baeldung/SpringContextTest.java
similarity index 95%
rename from spring-security-modules/spring-security-x509/spring-security-x509-client-auth/src/test/java/org/baeldung/SpringContextTest.java
rename to spring-security-modules/spring-security-x509/spring-security-x509-client-auth/src/test/java/com/baeldung/SpringContextTest.java
index 5c65dd3e8a..1c89f706ab 100644
--- a/spring-security-modules/spring-security-x509/spring-security-x509-client-auth/src/test/java/org/baeldung/SpringContextTest.java
+++ b/spring-security-modules/spring-security-x509/spring-security-x509-client-auth/src/test/java/com/baeldung/SpringContextTest.java
@@ -1,4 +1,4 @@
-package org.baeldung;
+package com.baeldung;
import org.junit.Test;
import org.junit.runner.RunWith;
diff --git a/spring-thymeleaf-3/README.md b/spring-thymeleaf-3/README.md
new file mode 100644
index 0000000000..e1ddd727d7
--- /dev/null
+++ b/spring-thymeleaf-3/README.md
@@ -0,0 +1,5 @@
+## Spring Thymeleaf 3
+
+This module contains articles about Spring with Thymeleaf
+
+## Relevant Articles:
\ No newline at end of file
diff --git a/spring-thymeleaf-3/pom.xml b/spring-thymeleaf-3/pom.xml
new file mode 100644
index 0000000000..7677e50d79
--- /dev/null
+++ b/spring-thymeleaf-3/pom.xml
@@ -0,0 +1,78 @@
+
+
+ 4.0.0
+ spring-thymeleaf-3
+ spring-thymeleaf-3
+ war
+
+
+ com.baeldung
+ parent-boot-2
+ 0.0.1-SNAPSHOT
+ ../parent-boot-2
+
+
+
+
+ org.springframework.boot
+ spring-boot-starter-web
+
+
+ org.springframework.boot
+ spring-boot-starter-thymeleaf
+
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ test
+
+
+
+
+
+
+ org.springframework.boot
+ spring-boot-maven-plugin
+
+ com.baeldung.thymeleaf.cssandjs.CssAndJsApplication
+ JAR
+
+
+
+ org.apache.maven.plugins
+ maven-war-plugin
+
+
+
+ org.apache.tomcat.maven
+ tomcat7-maven-plugin
+ ${tomcat7-maven-plugin.version}
+
+
+ tomcat-run
+
+ exec-war-only
+
+ package
+
+ /
+ false
+ webapp.jar
+ utf-8
+
+
+
+
+
+ spring-thymeleaf-3
+
+
+
+ 1.8
+ 1.8
+ 2.2
+
+
+
diff --git a/spring-boot-modules/spring-boot-client/src/main/java/org/baeldung/boot/Application.java b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/Application.java
similarity index 50%
rename from spring-boot-modules/spring-boot-client/src/main/java/org/baeldung/boot/Application.java
rename to spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/Application.java
index c1b6558b26..2ccca82497 100644
--- a/spring-boot-modules/spring-boot-client/src/main/java/org/baeldung/boot/Application.java
+++ b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/Application.java
@@ -1,14 +1,11 @@
-package org.baeldung.boot;
+package com.baeldung.thymeleaf;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.context.ApplicationContext;
@SpringBootApplication
public class Application {
- private static ApplicationContext applicationContext;
-
public static void main(String[] args) {
- applicationContext = SpringApplication.run(Application.class, args);
+ SpringApplication.run(Application.class, args);
}
}
diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsApplication.java b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsApplication.java
new file mode 100644
index 0000000000..fc6c142b8b
--- /dev/null
+++ b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsApplication.java
@@ -0,0 +1,11 @@
+package com.baeldung.thymeleaf.cssandjs;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class CssAndJsApplication {
+ public static void main(String[] args) {
+ SpringApplication.run(CssAndJsApplication.class, args);
+ }
+}
diff --git a/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsController.java b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsController.java
new file mode 100644
index 0000000000..b56a7b468e
--- /dev/null
+++ b/spring-thymeleaf-3/src/main/java/com/baeldung/thymeleaf/cssandjs/CssAndJsController.java
@@ -0,0 +1,15 @@
+package com.baeldung.thymeleaf.cssandjs;
+
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.GetMapping;
+
+@Controller
+public class CssAndJsController {
+
+ @GetMapping("/styled-page")
+ public String getStyledPage(Model model) {
+ model.addAttribute("name", "Baeldung Reader");
+ return "cssandjs/styledPage";
+ }
+}
diff --git a/spring-thymeleaf-3/src/main/resources/static/js/cssandjs/actions.js b/spring-thymeleaf-3/src/main/resources/static/js/cssandjs/actions.js
new file mode 100644
index 0000000000..e192e6358e
--- /dev/null
+++ b/spring-thymeleaf-3/src/main/resources/static/js/cssandjs/actions.js
@@ -0,0 +1,7 @@
+function showAlert() {
+ alert("The button was clicked!");
+}
+
+function showName(name) {
+ alert("Here's the name: " + name);
+}
\ No newline at end of file
diff --git a/spring-thymeleaf-3/src/main/resources/static/styles/cssandjs/main.css b/spring-thymeleaf-3/src/main/resources/static/styles/cssandjs/main.css
new file mode 100644
index 0000000000..1f57b4616a
--- /dev/null
+++ b/spring-thymeleaf-3/src/main/resources/static/styles/cssandjs/main.css
@@ -0,0 +1,18 @@
+h2 {
+ font-family: sans-serif;
+ font-size: 1.5em;
+ text-transform: uppercase;
+}
+
+strong {
+ font-weight: 700;
+ background-color: yellow;
+}
+
+p {
+ font-family: sans-serif;
+}
+
+label {
+ font-weight: 600;
+}
\ No newline at end of file
diff --git a/spring-thymeleaf-3/src/main/resources/templates/cssandjs/styledPage.html b/spring-thymeleaf-3/src/main/resources/templates/cssandjs/styledPage.html
new file mode 100644
index 0000000000..12e4fc9227
--- /dev/null
+++ b/spring-thymeleaf-3/src/main/resources/templates/cssandjs/styledPage.html
@@ -0,0 +1,20 @@
+
+
+
+
+ Add CSS and JS to Thymeleaf
+
+
+
+
+
+ Carefully Styled Heading
+
+ This is text on which we want to apply very special styling.
+
+
+
+
+
\ No newline at end of file
diff --git a/spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/ApplicationIntegrationTest.java b/spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/ApplicationIntegrationTest.java
new file mode 100644
index 0000000000..b7cfa140f0
--- /dev/null
+++ b/spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/ApplicationIntegrationTest.java
@@ -0,0 +1,13 @@
+package com.baeldung.thymeleaf;
+
+import org.junit.Test;
+import org.springframework.boot.test.context.SpringBootTest;
+
+@SpringBootTest
+public class ApplicationIntegrationTest {
+
+ @Test
+ public void contextLoads() {
+
+ }
+}
diff --git a/spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/cssandjs/CssAndJsControllerIntegrationTest.java b/spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/cssandjs/CssAndJsControllerIntegrationTest.java
new file mode 100644
index 0000000000..365608bd2a
--- /dev/null
+++ b/spring-thymeleaf-3/src/test/java/com/baeldung/thymeleaf/cssandjs/CssAndJsControllerIntegrationTest.java
@@ -0,0 +1,41 @@
+package com.baeldung.thymeleaf.cssandjs;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
+import org.springframework.test.web.servlet.setup.MockMvcBuilders;
+import org.springframework.web.context.WebApplicationContext;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@WebAppConfiguration
+@ContextConfiguration(classes = CssAndJsApplication.class)
+public class CssAndJsControllerIntegrationTest {
+ @Autowired
+ private WebApplicationContext context;
+
+ private MockMvc mockMvc;
+
+ @Before
+ public void setup() {
+ this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context).build();
+ }
+
+ @Test
+ public void whenCalledGetStyledPage_thenReturnContent() throws Exception {
+ this.mockMvc.perform(MockMvcRequestBuilders.get("/styled-page"))
+ .andExpect(status().isOk())
+ .andExpect(view().name("cssandjs/styledPage"))
+ .andExpect(content().string(containsString("Carefully Styled Heading")));
+ }
+}
diff --git a/testing-modules/junit5-migration/README.md b/testing-modules/junit5-migration/README.md
index 84e540b466..5cc9db8bd3 100644
--- a/testing-modules/junit5-migration/README.md
+++ b/testing-modules/junit5-migration/README.md
@@ -5,6 +5,6 @@ This module contains articles about migrating to JUnit 5.
The code for the JUnit 4 - JUnit 5 E-book is in `com.baeldung.junit4` and `com.baeldung.junit5`.
### Relevant Articles:
-- [JUnit 5 Migration](https://www.baeldung.com/junit-5-migration)
+
- [A Quick JUnit vs TestNG Comparison](https://www.baeldung.com/junit-vs-testng)
- [Assertions in JUnit 4 and JUnit 5](https://www.baeldung.com/junit-assertions)
diff --git a/testing-modules/mockito-2/README.md b/testing-modules/mockito-2/README.md
index d7069949e4..064366dfd5 100644
--- a/testing-modules/mockito-2/README.md
+++ b/testing-modules/mockito-2/README.md
@@ -3,6 +3,4 @@
- [Mockito’s Java 8 Features](https://www.baeldung.com/mockito-2-java-8)
- [Lazy Verification with Mockito 2](https://www.baeldung.com/mockito-2-lazy-verification)
- [Mockito Strict Stubbing and The UnnecessaryStubbingException](https://www.baeldung.com/mockito-unnecessary-stubbing-exception)
-- [Quick Guide to BDDMockito](https://www.baeldung.com/bdd-mockito)
-- [Mockito – Using Spies](https://www.baeldung.com/mockito-spy)
- [Mockito and Fluent APIs](https://www.baeldung.com/mockito-fluent-apis)
diff --git a/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/additionalanswers/Book.java b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/additionalanswers/Book.java
new file mode 100644
index 0000000000..fa021f8cba
--- /dev/null
+++ b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/additionalanswers/Book.java
@@ -0,0 +1,58 @@
+package com.baeldung.mockito.additionalanswers;
+
+public class Book {
+
+ private Long bookId;
+
+ private String title;
+
+ private String author;
+
+ private int numberOfPages;
+
+ public Book(String title, String author, int numberOfPages) {
+ this.title = title;
+ this.author = author;
+ this.numberOfPages = numberOfPages;
+ }
+
+ public Book(Long bookId, String title, String author, int numberOfPages) {
+ this.bookId = bookId;
+ this.title = title;
+ this.author = author;
+ this.numberOfPages = numberOfPages;
+ }
+
+ public Long getBookId() {
+ return bookId;
+ }
+
+ public void setBookId(Long bookId) {
+ this.bookId = bookId;
+ }
+
+ public String getTitle() {
+ return title;
+ }
+
+ public void setTitle(String title) {
+ this.title = title;
+ }
+
+ public String getAuthor() {
+ return author;
+ }
+
+ public void setAuthor(String author) {
+ this.author = author;
+ }
+
+ public int getNumberOfPages() {
+ return numberOfPages;
+ }
+
+ public void setNumberOfPages(int numberOfPages) {
+ this.numberOfPages = numberOfPages;
+ }
+}
+
diff --git a/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/additionalanswers/BookRepository.java b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/additionalanswers/BookRepository.java
new file mode 100644
index 0000000000..78187e3f01
--- /dev/null
+++ b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/additionalanswers/BookRepository.java
@@ -0,0 +1,17 @@
+package com.baeldung.mockito.additionalanswers;
+
+public class BookRepository {
+ public Book getByBookId(Long bookId) {
+ return new Book(bookId, "To Kill a Mocking Bird", "Harper Lee", 256);
+ }
+
+ public Book save(Book book) {
+ return new Book(book.getBookId(), book.getTitle(), book.getAuthor(), book.getNumberOfPages());
+ }
+
+ public Book checkIfEquals(Book bookOne, Book bookTwo, Book bookThree) {
+ if (bookOne.equals(bookTwo) && bookTwo.equals(bookThree) && bookThree.equals(bookOne)) {
+ return bookOne;
+ } else return bookTwo;
+ }
+}
diff --git a/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/additionalanswers/BookService.java b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/additionalanswers/BookService.java
new file mode 100644
index 0000000000..92c01f8a70
--- /dev/null
+++ b/testing-modules/mockito-2/src/main/java/com/baeldung/mockito/additionalanswers/BookService.java
@@ -0,0 +1,22 @@
+package com.baeldung.mockito.additionalanswers;
+
+public class BookService {
+ private final BookRepository bookRepository;
+
+ public BookService(BookRepository bookRepository) {
+ this.bookRepository = bookRepository;
+ }
+
+ public Book getByBookId(Long id) {
+ return bookRepository.getByBookId(id);
+ }
+
+ public Book save(Book book) {
+ return bookRepository.save(book);
+ }
+
+ public Book checkifEquals(Book book1, Book book2, Book book3) {
+ return bookRepository.checkIfEquals(book1, book2, book3);
+ }
+}
+
diff --git a/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/additionalanswers/BookServiceUnitTest.java b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/additionalanswers/BookServiceUnitTest.java
new file mode 100644
index 0000000000..c9527ec0ec
--- /dev/null
+++ b/testing-modules/mockito-2/src/test/java/com/baeldung/mockito/additionalanswers/BookServiceUnitTest.java
@@ -0,0 +1,68 @@
+package com.baeldung.mockito.additionalanswers;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.AdditionalAnswers;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+import static org.junit.Assert.assertEquals;
+import static org.mockito.ArgumentMatchers.any;
+
+@RunWith(MockitoJUnitRunner.class)
+public class BookServiceUnitTest {
+ @InjectMocks
+ private BookService bookService;
+
+ @Mock
+ private BookRepository bookRepository;
+
+ @Test
+ public void givenSaveMethodMocked_whenSaveInvoked_ThenReturnFirstArgument_UnitTest() {
+ Book book = new Book("To Kill a Mocking Bird", "Harper Lee", 256);
+ Mockito.when(bookRepository.save(any(Book.class))).then(AdditionalAnswers.returnsFirstArg());
+
+ Book savedBook = bookService.save(book);
+
+ assertEquals(savedBook, book);
+ }
+
+ @Test
+ public void givenCheckifEqualsMethodMocked_whenCheckifEqualsInvoked_ThenReturnSecondArgument_UnitTest() {
+ Book book1 = new Book(1L, "The Stranger", "Albert Camus", 456);
+ Book book2 = new Book(2L, "Animal Farm", "George Orwell", 300);
+ Book book3 = new Book(3L, "Romeo and Juliet", "William Shakespeare", 200);
+
+ Mockito.when(bookRepository.checkIfEquals(any(Book.class), any(Book.class), any(Book.class))).then(AdditionalAnswers.returnsSecondArg());
+
+ Book secondBook = bookService.checkifEquals(book1, book2, book3);
+
+ assertEquals(secondBook, book2);
+ }
+
+ @Test
+ public void givenCheckifEqualsMethodMocked_whenCheckifEqualsInvoked_ThenReturnLastArgument_UnitTest() {
+ Book book1 = new Book(1L, "The Stranger", "Albert Camus", 456);
+ Book book2 = new Book(2L, "Animal Farm", "George Orwell", 300);
+ Book book3 = new Book(3L, "Romeo and Juliet", "William Shakespeare", 200);
+
+ Mockito.when(bookRepository.checkIfEquals(any(Book.class), any(Book.class), any(Book.class))).then(AdditionalAnswers.returnsLastArg());
+
+ Book lastBook = bookService.checkifEquals(book1, book2, book3);
+ assertEquals(lastBook, book3);
+ }
+
+ @Test
+ public void givenCheckifEqualsMethodMocked_whenCheckifEqualsInvoked_ThenReturnArgumentAtIndex_UnitTest() {
+ Book book1 = new Book(1L, "The Stranger", "Albert Camus", 456);
+ Book book2 = new Book(2L, "Animal Farm", "George Orwell", 300);
+ Book book3 = new Book(3L, "Romeo and Juliet", "William Shakespeare", 200);
+
+ Mockito.when(bookRepository.checkIfEquals(any(Book.class), any(Book.class), any(Book.class))).then(AdditionalAnswers.returnsArgAt(1));
+
+ Book bookOnIndex = bookService.checkifEquals(book1, book2, book3);
+
+ assertEquals(bookOnIndex, book2);
+ }
+}
diff --git a/testing-modules/mocks/src/main/java/com/baeldung/jmockit/ExpectationsCollaborator.java b/testing-modules/mocks/src/main/java/com/baeldung/jmockit/ExpectationsCollaborator.java
index 799e7721e0..1aafa28a6a 100644
--- a/testing-modules/mocks/src/main/java/com/baeldung/jmockit/ExpectationsCollaborator.java
+++ b/testing-modules/mocks/src/main/java/com/baeldung/jmockit/ExpectationsCollaborator.java
@@ -15,5 +15,5 @@ public interface ExpectationsCollaborator {
void methodForArgThat(Object o);
String methodReturnsString();
int methodReturnsInt();
- Object methodForDelegate(int i);
+ int methodForDelegate(int i);
}
diff --git a/testing-modules/mocks/src/test/java/com/baeldung/jmockit/ExpectationsIntegrationTest.java b/testing-modules/mocks/src/test/java/com/baeldung/jmockit/ExpectationsIntegrationTest.java
index 8b0c3ab4ec..1ff90111d1 100644
--- a/testing-modules/mocks/src/test/java/com/baeldung/jmockit/ExpectationsIntegrationTest.java
+++ b/testing-modules/mocks/src/test/java/com/baeldung/jmockit/ExpectationsIntegrationTest.java
@@ -1,21 +1,21 @@
package com.baeldung.jmockit;
-import com.baeldung.jmockit.ExpectationsCollaborator;
-import com.baeldung.jmockit.Model;
-import mockit.Delegate;
-import mockit.Expectations;
-import mockit.Mocked;
-import mockit.Verifications;
-import mockit.integration.junit4.JMockit;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.List;
+
import org.hamcrest.BaseMatcher;
import org.hamcrest.Description;
import org.junit.Test;
import org.junit.runner.RunWith;
-import java.util.ArrayList;
-import java.util.List;
-
-import static org.junit.Assert.assertEquals;
+import mockit.Delegate;
+import mockit.Expectations;
+import mockit.Mocked;
+import mockit.Verifications;
+import mockit.integration.junit4.JMockit;
@RunWith(JMockit.class)
@SuppressWarnings("unchecked")
@@ -112,17 +112,16 @@ public class ExpectationsIntegrationTest {
result = "foo";
result = new Exception();
result = "bar";
- mock.methodReturnsInt();
- result = new int[]{1, 2, 3};
- mock.methodReturnsString();
returns("foo", "bar");
mock.methodReturnsInt();
+ result = new int[]{1, 2, 3};
result = 1;
}};
assertEquals("Should return foo", "foo", mock.methodReturnsString());
try {
mock.methodReturnsString();
+ fail("Shouldn't reach here");
} catch (Exception e) {
// NOOP
}
@@ -134,13 +133,14 @@ public class ExpectationsIntegrationTest {
assertEquals("Should return bar", "bar", mock.methodReturnsString());
assertEquals("Should return 1", 1, mock.methodReturnsInt());
}
-
+
@Test
public void testDelegate(@Mocked ExpectationsCollaborator mock) {
new Expectations() {{
mock.methodForDelegate(anyInt);
- result = new Delegate() {
- public int delegate(int i) throws Exception {
+
+ result = new Delegate() {
+ int delegate(int i) throws Exception {
if (i < 3) {
return 5;
} else {
@@ -153,6 +153,7 @@ public class ExpectationsIntegrationTest {
assertEquals("Should return 5", 5, mock.methodForDelegate(1));
try {
mock.methodForDelegate(3);
+ fail("Shouldn't reach here");
} catch (Exception e) {
}
}