Minor refactorings and code style changes. 1) Removed several use of raw types 2) Removed unnecessary throws clauses 3) Used lambda expressions wherever applicable 4) Used apt assertion methods for readability 5) Use of try with resources wherever applicable 6) Corrected incorrect order of assertXXX arguments
This commit is contained in:
@ -171,11 +171,11 @@ public class SimpleFluentIterable<E> implements FluentIterable<E> {
|
|||||||
/**
|
/**
|
||||||
* @return a FluentIterable from a given iterable. Calls the SimpleFluentIterable constructor.
|
* @return a FluentIterable from a given iterable. Calls the SimpleFluentIterable constructor.
|
||||||
*/
|
*/
|
||||||
public static final <E> FluentIterable<E> from(Iterable<E> iterable) {
|
public static <E> FluentIterable<E> from(Iterable<E> iterable) {
|
||||||
return new SimpleFluentIterable<>(iterable);
|
return new SimpleFluentIterable<>(iterable);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final <E> FluentIterable<E> fromCopyOf(Iterable<E> iterable) {
|
public static <E> FluentIterable<E> fromCopyOf(Iterable<E> iterable) {
|
||||||
List<E> copy = FluentIterable.copyToList(iterable);
|
List<E> copy = FluentIterable.copyToList(iterable);
|
||||||
return new SimpleFluentIterable<>(copy);
|
return new SimpleFluentIterable<>(copy);
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ public class FrontController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Command getCommand(String request) {
|
private Command getCommand(String request) {
|
||||||
Class commandClass = getCommandClass(request);
|
Class<?> commandClass = getCommandClass(request);
|
||||||
try {
|
try {
|
||||||
return (Command) commandClass.newInstance();
|
return (Command) commandClass.newInstance();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -44,8 +44,8 @@ public class FrontController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Class getCommandClass(String request) {
|
private static Class<?> getCommandClass(String request) {
|
||||||
Class result;
|
Class<?> result;
|
||||||
try {
|
try {
|
||||||
result = Class.forName("com.iluwatar.front.controller." + request + "Command");
|
result = Class.forName("com.iluwatar.front.controller." + request + "Command");
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
|
@ -34,7 +34,7 @@ import static org.junit.jupiter.api.Assertions.assertSame;
|
|||||||
public class ApplicationExceptionTest {
|
public class ApplicationExceptionTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCause() throws Exception {
|
public void testCause() {
|
||||||
final Exception cause = new Exception();
|
final Exception cause = new Exception();
|
||||||
assertSame(cause, new ApplicationException(cause).getCause());
|
assertSame(cause, new ApplicationException(cause).getCause());
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ public class GuardedQueueTest {
|
|||||||
GuardedQueue g = new GuardedQueue();
|
GuardedQueue g = new GuardedQueue();
|
||||||
ExecutorService executorService = Executors.newFixedThreadPool(2);
|
ExecutorService executorService = Executors.newFixedThreadPool(2);
|
||||||
executorService.submit(() -> value = g.get());
|
executorService.submit(() -> value = g.get());
|
||||||
executorService.submit(() -> g.put(Integer.valueOf(10)));
|
executorService.submit(() -> g.put(10));
|
||||||
executorService.shutdown();
|
executorService.shutdown();
|
||||||
try {
|
try {
|
||||||
executorService.awaitTermination(30, TimeUnit.SECONDS);
|
executorService.awaitTermination(30, TimeUnit.SECONDS);
|
||||||
|
@ -34,7 +34,7 @@ import java.util.concurrent.ExecutionException;
|
|||||||
public class AppTest {
|
public class AppTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() throws InterruptedException, ExecutionException {
|
public void test() {
|
||||||
App.main(null);
|
App.main(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.halfsynchalfasync;
|
package com.iluwatar.halfsynchalfasync;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.mockito.InOrder;
|
import org.mockito.InOrder;
|
||||||
|
|
||||||
@ -44,11 +45,17 @@ import static org.mockito.Mockito.when;
|
|||||||
* @author Jeroen Meulemeester
|
* @author Jeroen Meulemeester
|
||||||
*/
|
*/
|
||||||
public class AsynchronousServiceTest {
|
public class AsynchronousServiceTest {
|
||||||
|
private AsynchronousService service;
|
||||||
|
private AsyncTask<Object> task;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void setUp() {
|
||||||
|
service = new AsynchronousService(new LinkedBlockingQueue<>());
|
||||||
|
task = mock(AsyncTask.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPerfectExecution() throws Exception {
|
public void testPerfectExecution() throws Exception {
|
||||||
final AsynchronousService service = new AsynchronousService(new LinkedBlockingQueue<>());
|
|
||||||
final AsyncTask<Object> task = mock(AsyncTask.class);
|
|
||||||
final Object result = new Object();
|
final Object result = new Object();
|
||||||
when(task.call()).thenReturn(result);
|
when(task.call()).thenReturn(result);
|
||||||
service.execute(task);
|
service.execute(task);
|
||||||
@ -65,8 +72,6 @@ public class AsynchronousServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCallException() throws Exception {
|
public void testCallException() throws Exception {
|
||||||
final AsynchronousService service = new AsynchronousService(new LinkedBlockingQueue<>());
|
|
||||||
final AsyncTask<Object> task = mock(AsyncTask.class);
|
|
||||||
final IOException exception = new IOException();
|
final IOException exception = new IOException();
|
||||||
when(task.call()).thenThrow(exception);
|
when(task.call()).thenThrow(exception);
|
||||||
service.execute(task);
|
service.execute(task);
|
||||||
@ -82,9 +87,7 @@ public class AsynchronousServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPreCallException() throws Exception {
|
public void testPreCallException() {
|
||||||
final AsynchronousService service = new AsynchronousService(new LinkedBlockingQueue<>());
|
|
||||||
final AsyncTask<Object> task = mock(AsyncTask.class);
|
|
||||||
final IllegalStateException exception = new IllegalStateException();
|
final IllegalStateException exception = new IllegalStateException();
|
||||||
doThrow(exception).when(task).onPreCall();
|
doThrow(exception).when(task).onPreCall();
|
||||||
service.execute(task);
|
service.execute(task);
|
||||||
|
@ -22,9 +22,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.intercepting.filter;
|
package com.iluwatar.intercepting.filter;
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
|
||||||
import java.awt.GridLayout;
|
|
||||||
|
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
@ -33,6 +30,9 @@ import javax.swing.JRootPane;
|
|||||||
import javax.swing.JTextArea;
|
import javax.swing.JTextArea;
|
||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
|
import javax.swing.WindowConstants;
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.GridLayout;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Client class is responsible for handling the input and running them through filters inside the
|
* The Client class is responsible for handling the input and running them through filters inside the
|
||||||
@ -60,7 +60,7 @@ public class Client extends JFrame { // NOSONAR
|
|||||||
*/
|
*/
|
||||||
public Client() {
|
public Client() {
|
||||||
super("Client System");
|
super("Client System");
|
||||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||||
setSize(300, 300);
|
setSize(300, 300);
|
||||||
jl = new JLabel("RUNNING...");
|
jl = new JLabel("RUNNING...");
|
||||||
jtFields = new JTextField[3];
|
jtFields = new JTextField[3];
|
||||||
|
@ -22,11 +22,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.intercepting.filter;
|
package com.iluwatar.intercepting.filter;
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
|
||||||
import java.awt.Dimension;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
|
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
@ -34,7 +29,12 @@ import javax.swing.JRootPane;
|
|||||||
import javax.swing.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.JTable;
|
import javax.swing.JTable;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
|
import javax.swing.WindowConstants;
|
||||||
import javax.swing.table.DefaultTableModel;
|
import javax.swing.table.DefaultTableModel;
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Dimension;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is where the requests are displayed after being validated by filters.
|
* This is where the requests are displayed after being validated by filters.
|
||||||
@ -47,7 +47,6 @@ public class Target extends JFrame { //NOSONAR
|
|||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private JTable jt;
|
private JTable jt;
|
||||||
private JScrollPane jsp;
|
|
||||||
private DefaultTableModel dtm;
|
private DefaultTableModel dtm;
|
||||||
private JButton del;
|
private JButton del;
|
||||||
|
|
||||||
@ -56,7 +55,7 @@ public class Target extends JFrame { //NOSONAR
|
|||||||
*/
|
*/
|
||||||
public Target() {
|
public Target() {
|
||||||
super("Order System");
|
super("Order System");
|
||||||
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
|
||||||
setSize(640, 480);
|
setSize(640, 480);
|
||||||
dtm =
|
dtm =
|
||||||
new DefaultTableModel(new Object[] {"Name", "Contact Number", "Address", "Deposit Number",
|
new DefaultTableModel(new Object[] {"Name", "Contact Number", "Address", "Deposit Number",
|
||||||
@ -73,7 +72,7 @@ public class Target extends JFrame { //NOSONAR
|
|||||||
bot.setLayout(new BorderLayout());
|
bot.setLayout(new BorderLayout());
|
||||||
bot.add(del, BorderLayout.EAST);
|
bot.add(del, BorderLayout.EAST);
|
||||||
add(bot, BorderLayout.SOUTH);
|
add(bot, BorderLayout.SOUTH);
|
||||||
jsp = new JScrollPane(jt);
|
JScrollPane jsp = new JScrollPane(jt);
|
||||||
jsp.setPreferredSize(new Dimension(500, 250));
|
jsp.setPreferredSize(new Dimension(500, 250));
|
||||||
add(jsp, BorderLayout.CENTER);
|
add(jsp, BorderLayout.CENTER);
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ import static org.mockito.Mockito.when;
|
|||||||
public class FilterManagerTest {
|
public class FilterManagerTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFilterRequest() throws Exception {
|
public void testFilterRequest() {
|
||||||
final Target target = mock(Target.class);
|
final Target target = mock(Target.class);
|
||||||
final FilterManager filterManager = new FilterManager();
|
final FilterManager filterManager = new FilterManager();
|
||||||
assertEquals("RUNNING...", filterManager.filterRequest(mock(Order.class)));
|
assertEquals("RUNNING...", filterManager.filterRequest(mock(Order.class)));
|
||||||
@ -48,7 +48,7 @@ public class FilterManagerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddFilter() throws Exception {
|
public void testAddFilter() {
|
||||||
final Target target = mock(Target.class);
|
final Target target = mock(Target.class);
|
||||||
final FilterManager filterManager = new FilterManager();
|
final FilterManager filterManager = new FilterManager();
|
||||||
|
|
||||||
|
@ -89,7 +89,7 @@ public class FilterTest {
|
|||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("getTestData")
|
@MethodSource("getTestData")
|
||||||
public void testExecute(Filter filter, Order order, String expectedResult) throws Exception {
|
public void testExecute(Filter filter, Order order, String expectedResult) {
|
||||||
final String result = filter.execute(order);
|
final String result = filter.execute(order);
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertEquals(expectedResult, result.trim());
|
assertEquals(expectedResult, result.trim());
|
||||||
@ -97,7 +97,7 @@ public class FilterTest {
|
|||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("getTestData")
|
@MethodSource("getTestData")
|
||||||
public void testNext(Filter filter) throws Exception {
|
public void testNext(Filter filter) {
|
||||||
assertNull(filter.getNext());
|
assertNull(filter.getNext());
|
||||||
assertSame(filter, filter.getLast());
|
assertSame(filter, filter.getLast());
|
||||||
}
|
}
|
||||||
|
@ -36,35 +36,35 @@ public class OrderTest {
|
|||||||
private static final String EXPECTED_VALUE = "test";
|
private static final String EXPECTED_VALUE = "test";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetName() throws Exception {
|
public void testSetName() {
|
||||||
final Order order = new Order();
|
final Order order = new Order();
|
||||||
order.setName(EXPECTED_VALUE);
|
order.setName(EXPECTED_VALUE);
|
||||||
assertEquals(EXPECTED_VALUE, order.getName());
|
assertEquals(EXPECTED_VALUE, order.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetContactNumber() throws Exception {
|
public void testSetContactNumber() {
|
||||||
final Order order = new Order();
|
final Order order = new Order();
|
||||||
order.setContactNumber(EXPECTED_VALUE);
|
order.setContactNumber(EXPECTED_VALUE);
|
||||||
assertEquals(EXPECTED_VALUE, order.getContactNumber());
|
assertEquals(EXPECTED_VALUE, order.getContactNumber());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetAddress() throws Exception {
|
public void testSetAddress() {
|
||||||
final Order order = new Order();
|
final Order order = new Order();
|
||||||
order.setAddress(EXPECTED_VALUE);
|
order.setAddress(EXPECTED_VALUE);
|
||||||
assertEquals(EXPECTED_VALUE, order.getAddress());
|
assertEquals(EXPECTED_VALUE, order.getAddress());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetDepositNumber() throws Exception {
|
public void testSetDepositNumber() {
|
||||||
final Order order = new Order();
|
final Order order = new Order();
|
||||||
order.setDepositNumber(EXPECTED_VALUE);
|
order.setDepositNumber(EXPECTED_VALUE);
|
||||||
assertEquals(EXPECTED_VALUE, order.getDepositNumber());
|
assertEquals(EXPECTED_VALUE, order.getDepositNumber());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetOrder() throws Exception {
|
public void testSetOrder() {
|
||||||
final Order order = new Order();
|
final Order order = new Order();
|
||||||
order.setOrderItem(EXPECTED_VALUE);
|
order.setOrderItem(EXPECTED_VALUE);
|
||||||
assertEquals(EXPECTED_VALUE, order.getOrderItem());
|
assertEquals(EXPECTED_VALUE, order.getOrderItem());
|
||||||
|
@ -50,49 +50,49 @@ class BstIteratorTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nextForEmptyTree() {
|
void nextForEmptyTree() {
|
||||||
BstIterator iter = new BstIterator<>(emptyRoot);
|
BstIterator<Integer> iter = new BstIterator<>(emptyRoot);
|
||||||
assertThrows(NoSuchElementException.class, iter::next,
|
assertThrows(NoSuchElementException.class, iter::next,
|
||||||
"next() should throw an IllegalStateException if hasNext() is false.");
|
"next() should throw an IllegalStateException if hasNext() is false.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nextOverEntirePopulatedTree() {
|
void nextOverEntirePopulatedTree() {
|
||||||
BstIterator iter = new BstIterator<>(nonEmptyRoot);
|
BstIterator<Integer> iter = new BstIterator<>(nonEmptyRoot);
|
||||||
assertEquals(1, iter.next().getVal(), "First Node is 1.");
|
assertEquals(Integer.valueOf(1), iter.next().getVal(), "First Node is 1.");
|
||||||
assertEquals(3, iter.next().getVal(), "Second Node is 3.");
|
assertEquals(Integer.valueOf(3), iter.next().getVal(), "Second Node is 3.");
|
||||||
assertEquals(4, iter.next().getVal(), "Third Node is 4.");
|
assertEquals(Integer.valueOf(4), iter.next().getVal(), "Third Node is 4.");
|
||||||
assertEquals(5, iter.next().getVal(), "Fourth Node is 5.");
|
assertEquals(Integer.valueOf(5), iter.next().getVal(), "Fourth Node is 5.");
|
||||||
assertEquals(6, iter.next().getVal(), "Fifth Node is 6.");
|
assertEquals(Integer.valueOf(6), iter.next().getVal(), "Fifth Node is 6.");
|
||||||
assertEquals(7, iter.next().getVal(), "Sixth Node is 7.");
|
assertEquals(Integer.valueOf(7), iter.next().getVal(), "Sixth Node is 7.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void hasNextForEmptyTree() {
|
void hasNextForEmptyTree() {
|
||||||
BstIterator iter = new BstIterator<>(emptyRoot);
|
BstIterator<Integer> iter = new BstIterator<>(emptyRoot);
|
||||||
assertFalse(iter.hasNext(), "hasNext() should return false for empty tree.");
|
assertFalse(iter.hasNext(), "hasNext() should return false for empty tree.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void hasNextForPopulatedTree() {
|
void hasNextForPopulatedTree() {
|
||||||
BstIterator iter = new BstIterator<>(nonEmptyRoot);
|
BstIterator<Integer> iter = new BstIterator<>(nonEmptyRoot);
|
||||||
assertTrue(iter.hasNext(), "hasNext() should return true for populated tree.");
|
assertTrue(iter.hasNext(), "hasNext() should return true for populated tree.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void nextAndHasNextOverEntirePopulatedTree() {
|
void nextAndHasNextOverEntirePopulatedTree() {
|
||||||
BstIterator iter = new BstIterator<>(nonEmptyRoot);
|
BstIterator<Integer> iter = new BstIterator<>(nonEmptyRoot);
|
||||||
assertTrue(iter.hasNext(), "Iterator hasNext() should be true.");
|
assertTrue(iter.hasNext(), "Iterator hasNext() should be true.");
|
||||||
assertEquals(1, iter.next().getVal(), "First Node is 1.");
|
assertEquals(Integer.valueOf(1), iter.next().getVal(), "First Node is 1.");
|
||||||
assertTrue(iter.hasNext(), "Iterator hasNext() should be true.");
|
assertTrue(iter.hasNext(), "Iterator hasNext() should be true.");
|
||||||
assertEquals(3, iter.next().getVal(), "Second Node is 3.");
|
assertEquals(Integer.valueOf(3), iter.next().getVal(), "Second Node is 3.");
|
||||||
assertTrue(iter.hasNext(), "Iterator hasNext() should be true.");
|
assertTrue(iter.hasNext(), "Iterator hasNext() should be true.");
|
||||||
assertEquals(4, iter.next().getVal(), "Third Node is 4.");
|
assertEquals(Integer.valueOf(4), iter.next().getVal(), "Third Node is 4.");
|
||||||
assertTrue(iter.hasNext(), "Iterator hasNext() should be true.");
|
assertTrue(iter.hasNext(), "Iterator hasNext() should be true.");
|
||||||
assertEquals(5, iter.next().getVal(), "Fourth Node is 5.");
|
assertEquals(Integer.valueOf(5), iter.next().getVal(), "Fourth Node is 5.");
|
||||||
assertTrue(iter.hasNext(), "Iterator hasNext() should be true.");
|
assertTrue(iter.hasNext(), "Iterator hasNext() should be true.");
|
||||||
assertEquals(6, iter.next().getVal(), "Fifth Node is 6.");
|
assertEquals(Integer.valueOf(6), iter.next().getVal(), "Fifth Node is 6.");
|
||||||
assertTrue(iter.hasNext(), "Iterator hasNext() should be true.");
|
assertTrue(iter.hasNext(), "Iterator hasNext() should be true.");
|
||||||
assertEquals(7, iter.next().getVal(), "Sixth Node is 7.");
|
assertEquals(Integer.valueOf(7), iter.next().getVal(), "Sixth Node is 7.");
|
||||||
assertFalse(iter.hasNext(), "Iterator hasNext() should be false, end of tree.");
|
assertFalse(iter.hasNext(), "Iterator hasNext() should be false, end of tree.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,6 +41,6 @@ public class CakeViewImpl implements View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void render() {
|
public void render() {
|
||||||
cakeBakingService.getAllCakes().stream().forEach(cake -> LOGGER.info(cake.toString()));
|
cakeBakingService.getAllCakes().forEach(cake -> LOGGER.info(cake.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,14 +35,14 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
|||||||
public class CakeBakingExceptionTest {
|
public class CakeBakingExceptionTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructor() throws Exception {
|
public void testConstructor() {
|
||||||
final CakeBakingException exception = new CakeBakingException();
|
final CakeBakingException exception = new CakeBakingException();
|
||||||
assertNull(exception.getMessage());
|
assertNull(exception.getMessage());
|
||||||
assertNull(exception.getCause());
|
assertNull(exception.getCause());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorWithMessage() throws Exception {
|
public void testConstructorWithMessage() {
|
||||||
final String expectedMessage = "message";
|
final String expectedMessage = "message";
|
||||||
final CakeBakingException exception = new CakeBakingException(expectedMessage);
|
final CakeBakingException exception = new CakeBakingException(expectedMessage);
|
||||||
assertEquals(expectedMessage, exception.getMessage());
|
assertEquals(expectedMessage, exception.getMessage());
|
||||||
|
@ -42,7 +42,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||||||
public class CakeBakingServiceImplTest {
|
public class CakeBakingServiceImplTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLayers() throws CakeBakingException {
|
public void testLayers() {
|
||||||
final CakeBakingServiceImpl service = new CakeBakingServiceImpl();
|
final CakeBakingServiceImpl service = new CakeBakingServiceImpl();
|
||||||
|
|
||||||
final List<CakeLayerInfo> initialLayers = service.getAvailableLayers();
|
final List<CakeLayerInfo> initialLayers = service.getAvailableLayers();
|
||||||
@ -65,7 +65,7 @@ public class CakeBakingServiceImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToppings() throws CakeBakingException {
|
public void testToppings() {
|
||||||
final CakeBakingServiceImpl service = new CakeBakingServiceImpl();
|
final CakeBakingServiceImpl service = new CakeBakingServiceImpl();
|
||||||
|
|
||||||
final List<CakeToppingInfo> initialToppings = service.getAvailableToppings();
|
final List<CakeToppingInfo> initialToppings = service.getAvailableToppings();
|
||||||
@ -125,7 +125,7 @@ public class CakeBakingServiceImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBakeCakeMissingTopping() throws CakeBakingException {
|
public void testBakeCakeMissingTopping() {
|
||||||
final CakeBakingServiceImpl service = new CakeBakingServiceImpl();
|
final CakeBakingServiceImpl service = new CakeBakingServiceImpl();
|
||||||
|
|
||||||
final CakeLayerInfo layer1 = new CakeLayerInfo("Layer1", 1000);
|
final CakeLayerInfo layer1 = new CakeLayerInfo("Layer1", 1000);
|
||||||
@ -140,7 +140,7 @@ public class CakeBakingServiceImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBakeCakeMissingLayer() throws CakeBakingException {
|
public void testBakeCakeMissingLayer() {
|
||||||
final CakeBakingServiceImpl service = new CakeBakingServiceImpl();
|
final CakeBakingServiceImpl service = new CakeBakingServiceImpl();
|
||||||
|
|
||||||
final List<CakeInfo> initialCakes = service.getAllCakes();
|
final List<CakeInfo> initialCakes = service.getAllCakes();
|
||||||
|
@ -44,7 +44,7 @@ public class CakeTest {
|
|||||||
final Cake cake = new Cake();
|
final Cake cake = new Cake();
|
||||||
assertNull(cake.getId());
|
assertNull(cake.getId());
|
||||||
|
|
||||||
final Long expectedId = Long.valueOf(1234L);
|
final Long expectedId = 1234L;
|
||||||
cake.setId(expectedId);
|
cake.setId(expectedId);
|
||||||
assertEquals(expectedId, cake.getId());
|
assertEquals(expectedId, cake.getId());
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@ public class Java8Holder {
|
|||||||
|
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(Java8Holder.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(Java8Holder.class);
|
||||||
|
|
||||||
private Supplier<Heavy> heavy = () -> createAndCacheHeavy();
|
private Supplier<Heavy> heavy = this::createAndCacheHeavy;
|
||||||
|
|
||||||
public Java8Holder() {
|
public Java8Holder() {
|
||||||
LOGGER.info("Java8Holder created");
|
LOGGER.info("Java8Holder created");
|
||||||
|
@ -27,6 +27,7 @@ import java.io.FileReader;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Module pattern can be considered a Creational pattern and a Structural pattern. It manages
|
* The Module pattern can be considered a Creational pattern and a Structural pattern. It manages
|
||||||
@ -88,7 +89,7 @@ public final class FileLoggerModuleTest {
|
|||||||
fileLoggerModule.prepare();
|
fileLoggerModule.prepare();
|
||||||
|
|
||||||
/* Test if nothing is printed in file */
|
/* Test if nothing is printed in file */
|
||||||
assertEquals(readFirstLine(OUTPUT_FILE), null);
|
assertNull(readFirstLine(OUTPUT_FILE));
|
||||||
|
|
||||||
/* Unprepare to cleanup the modules */
|
/* Unprepare to cleanup the modules */
|
||||||
fileLoggerModule.unprepare();
|
fileLoggerModule.unprepare();
|
||||||
@ -113,7 +114,7 @@ public final class FileLoggerModuleTest {
|
|||||||
fileLoggerModule.printErrorString(ERROR);
|
fileLoggerModule.printErrorString(ERROR);
|
||||||
|
|
||||||
/* Test if 'Message' is printed in file */
|
/* Test if 'Message' is printed in file */
|
||||||
assertEquals(readFirstLine(ERROR_FILE), ERROR);
|
assertEquals(ERROR, readFirstLine(ERROR_FILE));
|
||||||
|
|
||||||
/* Unprepare to cleanup the modules */
|
/* Unprepare to cleanup the modules */
|
||||||
fileLoggerModule.unprepare();
|
fileLoggerModule.unprepare();
|
||||||
@ -135,7 +136,7 @@ public final class FileLoggerModuleTest {
|
|||||||
fileLoggerModule.prepare();
|
fileLoggerModule.prepare();
|
||||||
|
|
||||||
/* Test if nothing is printed in file */
|
/* Test if nothing is printed in file */
|
||||||
assertEquals(readFirstLine(ERROR_FILE), null);
|
assertNull(readFirstLine(ERROR_FILE));
|
||||||
|
|
||||||
/* Unprepare to cleanup the modules */
|
/* Unprepare to cleanup the modules */
|
||||||
fileLoggerModule.unprepare();
|
fileLoggerModule.unprepare();
|
||||||
@ -150,11 +151,7 @@ public final class FileLoggerModuleTest {
|
|||||||
private static final String readFirstLine(final String file) {
|
private static final String readFirstLine(final String file) {
|
||||||
|
|
||||||
String firstLine = null;
|
String firstLine = null;
|
||||||
BufferedReader bufferedReader = null;
|
try (BufferedReader bufferedReader = new BufferedReader(new FileReader(file))) {
|
||||||
try {
|
|
||||||
|
|
||||||
/* Create a buffered reader */
|
|
||||||
bufferedReader = new BufferedReader(new FileReader(file));
|
|
||||||
|
|
||||||
while (bufferedReader.ready()) {
|
while (bufferedReader.ready()) {
|
||||||
|
|
||||||
@ -166,15 +163,6 @@ public final class FileLoggerModuleTest {
|
|||||||
|
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
LOGGER.error("ModuleTest::readFirstLine()", e);
|
LOGGER.error("ModuleTest::readFirstLine()", e);
|
||||||
} finally {
|
|
||||||
|
|
||||||
if (bufferedReader != null) {
|
|
||||||
try {
|
|
||||||
bufferedReader.close();
|
|
||||||
} catch (final IOException e) {
|
|
||||||
LOGGER.error("ModuleTest::readFirstLine()", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return firstLine;
|
return firstLine;
|
||||||
|
@ -34,33 +34,33 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public class LoadBalancer {
|
public class LoadBalancer {
|
||||||
private static List<Server> servers = new ArrayList<>();
|
private static final List<Server> SERVERS = new ArrayList<>();
|
||||||
private static int lastServedId;
|
private static int lastServedId;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
int id = 0;
|
int id = 0;
|
||||||
servers.add(new Server("localhost", 8081, ++id));
|
SERVERS.add(new Server("localhost", 8081, ++id));
|
||||||
servers.add(new Server("localhost", 8080, ++id));
|
SERVERS.add(new Server("localhost", 8080, ++id));
|
||||||
servers.add(new Server("localhost", 8082, ++id));
|
SERVERS.add(new Server("localhost", 8082, ++id));
|
||||||
servers.add(new Server("localhost", 8083, ++id));
|
SERVERS.add(new Server("localhost", 8083, ++id));
|
||||||
servers.add(new Server("localhost", 8084, ++id));
|
SERVERS.add(new Server("localhost", 8084, ++id));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add new server
|
* Add new server
|
||||||
*/
|
*/
|
||||||
public final void addServer(Server server) {
|
public final void addServer(Server server) {
|
||||||
synchronized (servers) {
|
synchronized (SERVERS) {
|
||||||
servers.add(server);
|
SERVERS.add(server);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final int getNoOfServers() {
|
public final int getNoOfServers() {
|
||||||
return servers.size();
|
return SERVERS.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getLastServedId() {
|
public int getLastServedId() {
|
||||||
return lastServedId;
|
return lastServedId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,10 +68,10 @@ public class LoadBalancer {
|
|||||||
* Handle request
|
* Handle request
|
||||||
*/
|
*/
|
||||||
public synchronized void serverRequest(Request request) {
|
public synchronized void serverRequest(Request request) {
|
||||||
if (lastServedId >= servers.size()) {
|
if (lastServedId >= SERVERS.size()) {
|
||||||
lastServedId = 0;
|
lastServedId = 0;
|
||||||
}
|
}
|
||||||
Server server = servers.get(lastServedId++);
|
Server server = SERVERS.get(lastServedId++);
|
||||||
server.serve(request);
|
server.serve(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ package com.iluwatar.monostate;
|
|||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
import static org.mockito.Matchers.any;
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Mockito.doNothing;
|
import static org.mockito.Mockito.doNothing;
|
||||||
@ -47,9 +48,9 @@ public class LoadBalancerTest {
|
|||||||
final LoadBalancer secondBalancer = new LoadBalancer();
|
final LoadBalancer secondBalancer = new LoadBalancer();
|
||||||
firstBalancer.addServer(new Server("localhost", 8085, 6));
|
firstBalancer.addServer(new Server("localhost", 8085, 6));
|
||||||
// Both should have the same number of servers.
|
// Both should have the same number of servers.
|
||||||
assertTrue(firstBalancer.getNoOfServers() == secondBalancer.getNoOfServers());
|
assertEquals(firstBalancer.getNoOfServers(), secondBalancer.getNoOfServers());
|
||||||
// Both Should have the same LastServedId
|
// Both Should have the same LastServedId
|
||||||
assertTrue(firstBalancer.getLastServedId() == secondBalancer.getLastServedId());
|
assertEquals(firstBalancer.getLastServedId(), secondBalancer.getLastServedId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -45,27 +45,27 @@ public class MuteTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void muteShouldRunTheCheckedRunnableAndNotThrowAnyExceptionIfCheckedRunnableDoesNotThrowAnyException() {
|
public void muteShouldRunTheCheckedRunnableAndNotThrowAnyExceptionIfCheckedRunnableDoesNotThrowAnyException() {
|
||||||
Mute.mute(() -> methodNotThrowingAnyException());
|
Mute.mute(this::methodNotThrowingAnyException);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void muteShouldRethrowUnexpectedExceptionAsAssertionError() throws Exception {
|
public void muteShouldRethrowUnexpectedExceptionAsAssertionError() {
|
||||||
assertThrows(AssertionError.class, () -> {
|
assertThrows(AssertionError.class, () -> {
|
||||||
Mute.mute(() -> methodThrowingException());
|
Mute.mute(this::methodThrowingException);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void loggedMuteShouldRunTheCheckedRunnableAndNotThrowAnyExceptionIfCheckedRunnableDoesNotThrowAnyException() {
|
public void loggedMuteShouldRunTheCheckedRunnableAndNotThrowAnyExceptionIfCheckedRunnableDoesNotThrowAnyException() {
|
||||||
Mute.loggedMute(() -> methodNotThrowingAnyException());
|
Mute.loggedMute(this::methodNotThrowingAnyException);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void loggedMuteShouldLogExceptionTraceBeforeSwallowingIt() throws IOException {
|
public void loggedMuteShouldLogExceptionTraceBeforeSwallowingIt() {
|
||||||
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
ByteArrayOutputStream stream = new ByteArrayOutputStream();
|
||||||
System.setErr(new PrintStream(stream));
|
System.setErr(new PrintStream(stream));
|
||||||
|
|
||||||
Mute.loggedMute(() -> methodThrowingException());
|
Mute.loggedMute(this::methodThrowingException);
|
||||||
|
|
||||||
assertTrue(new String(stream.toByteArray()).contains(MESSAGE));
|
assertTrue(new String(stream.toByteArray()).contains(MESSAGE));
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ public class NullNodeTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWalk() throws Exception {
|
public void testWalk() {
|
||||||
NullNode.getInstance().walk();
|
NullNode.getInstance().walk();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ public class TreeTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetLeft() throws Exception {
|
public void testGetLeft() {
|
||||||
final Node level1 = TREE_ROOT.getLeft();
|
final Node level1 = TREE_ROOT.getLeft();
|
||||||
assertNotNull(level1);
|
assertNotNull(level1);
|
||||||
assertEquals("level1_a", level1.getName());
|
assertEquals("level1_a", level1.getName());
|
||||||
@ -130,7 +130,7 @@ public class TreeTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetRight() throws Exception {
|
public void testGetRight() {
|
||||||
final Node level1 = TREE_ROOT.getRight();
|
final Node level1 = TREE_ROOT.getRight();
|
||||||
assertNotNull(level1);
|
assertNotNull(level1);
|
||||||
assertEquals("level1_b", level1.getName());
|
assertEquals("level1_b", level1.getName());
|
||||||
|
@ -59,7 +59,7 @@ public class King implements Royalty {
|
|||||||
*/
|
*/
|
||||||
public void flirt(Queen queen) {
|
public void flirt(Queen queen) {
|
||||||
boolean flirtStatus = queen.getFlirted(this);
|
boolean flirtStatus = queen.getFlirted(this);
|
||||||
if (flirtStatus == false) {
|
if (!flirtStatus) {
|
||||||
this.makeUnhappy();
|
this.makeUnhappy();
|
||||||
} else {
|
} else {
|
||||||
this.makeHappy();
|
this.makeHappy();
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.object.pool;
|
package com.iluwatar.object.pool;
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* Oliphaunts are expensive to create
|
* Oliphaunts are expensive to create
|
||||||
@ -29,7 +31,7 @@ package com.iluwatar.object.pool;
|
|||||||
*/
|
*/
|
||||||
public class Oliphaunt {
|
public class Oliphaunt {
|
||||||
|
|
||||||
private static int counter = 1;
|
private static AtomicInteger counter = new AtomicInteger(0);
|
||||||
|
|
||||||
private final int id;
|
private final int id;
|
||||||
|
|
||||||
@ -37,7 +39,7 @@ public class Oliphaunt {
|
|||||||
* Constructor
|
* Constructor
|
||||||
*/
|
*/
|
||||||
public Oliphaunt() {
|
public Oliphaunt() {
|
||||||
id = counter++;
|
id = counter.incrementAndGet();
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
@ -49,23 +49,23 @@ public class OliphauntPoolTest {
|
|||||||
public void testSubsequentCheckinCheckout() {
|
public void testSubsequentCheckinCheckout() {
|
||||||
assertTimeout(ofMillis(5000), () -> {
|
assertTimeout(ofMillis(5000), () -> {
|
||||||
final OliphauntPool pool = new OliphauntPool();
|
final OliphauntPool pool = new OliphauntPool();
|
||||||
assertEquals(pool.toString(), "Pool available=0 inUse=0");
|
assertEquals("Pool available=0 inUse=0", pool.toString());
|
||||||
|
|
||||||
final Oliphaunt expectedOliphaunt = pool.checkOut();
|
final Oliphaunt expectedOliphaunt = pool.checkOut();
|
||||||
assertEquals(pool.toString(), "Pool available=0 inUse=1");
|
assertEquals("Pool available=0 inUse=1", pool.toString());
|
||||||
|
|
||||||
pool.checkIn(expectedOliphaunt);
|
pool.checkIn(expectedOliphaunt);
|
||||||
assertEquals(pool.toString(), "Pool available=1 inUse=0");
|
assertEquals("Pool available=1 inUse=0", pool.toString());
|
||||||
|
|
||||||
for (int i = 0; i < 100; i++) {
|
for (int i = 0; i < 100; i++) {
|
||||||
final Oliphaunt oliphaunt = pool.checkOut();
|
final Oliphaunt oliphaunt = pool.checkOut();
|
||||||
assertEquals(pool.toString(), "Pool available=0 inUse=1");
|
assertEquals("Pool available=0 inUse=1", pool.toString());
|
||||||
assertSame(expectedOliphaunt, oliphaunt);
|
assertSame(expectedOliphaunt, oliphaunt);
|
||||||
assertEquals(expectedOliphaunt.getId(), oliphaunt.getId());
|
assertEquals(expectedOliphaunt.getId(), oliphaunt.getId());
|
||||||
assertEquals(expectedOliphaunt.toString(), oliphaunt.toString());
|
assertEquals(expectedOliphaunt.toString(), oliphaunt.toString());
|
||||||
|
|
||||||
pool.checkIn(oliphaunt);
|
pool.checkIn(oliphaunt);
|
||||||
assertEquals(pool.toString(), "Pool available=1 inUse=0");
|
assertEquals("Pool available=1 inUse=0", pool.toString());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||||||
* @author Jeroen Meulemeester
|
* @author Jeroen Meulemeester
|
||||||
*/
|
*/
|
||||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||||
public abstract class ObserverTest<O extends Observer> {
|
public abstract class ObserverTest<O extends Observer<?, ?, WeatherType>> {
|
||||||
|
|
||||||
private InMemoryAppender appender;
|
private InMemoryAppender appender;
|
||||||
|
|
||||||
|
@ -36,38 +36,34 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
|
|||||||
public class PoisonMessageTest {
|
public class PoisonMessageTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAddHeader() throws Exception {
|
public void testAddHeader() {
|
||||||
assertThrows(UnsupportedOperationException.class, () -> {
|
assertThrows(UnsupportedOperationException.class, () -> {
|
||||||
POISON_PILL.addHeader(Headers.SENDER, "sender");
|
POISON_PILL.addHeader(Headers.SENDER, "sender");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetHeader() throws Exception {
|
public void testGetHeader() {
|
||||||
assertThrows(UnsupportedOperationException.class, () -> {
|
assertThrows(UnsupportedOperationException.class, () -> {
|
||||||
POISON_PILL.getHeader(Headers.SENDER);
|
POISON_PILL.getHeader(Headers.SENDER);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetHeaders() throws Exception {
|
public void testGetHeaders() {
|
||||||
assertThrows(UnsupportedOperationException.class, () -> {
|
assertThrows(UnsupportedOperationException.class, POISON_PILL::getHeaders);
|
||||||
POISON_PILL.getHeaders();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetBody() throws Exception {
|
public void testSetBody() {
|
||||||
assertThrows(UnsupportedOperationException.class, () -> {
|
assertThrows(UnsupportedOperationException.class, () -> {
|
||||||
POISON_PILL.setBody("Test message.");
|
POISON_PILL.setBody("Test message.");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetBody() throws Exception {
|
public void testGetBody() {
|
||||||
assertThrows(UnsupportedOperationException.class, () -> {
|
assertThrows(UnsupportedOperationException.class, POISON_PILL::getBody);
|
||||||
POISON_PILL.getBody();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
|||||||
public class ProducerTest {
|
public class ProducerTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testProduce() throws Exception {
|
public void testProduce() {
|
||||||
assertTimeout(ofMillis(6000), () -> {
|
assertTimeout(ofMillis(6000), () -> {
|
||||||
final ItemQueue queue = mock(ItemQueue.class);
|
final ItemQueue queue = mock(ItemQueue.class);
|
||||||
final Producer producer = new Producer("producer", queue);
|
final Producer producer = new Producer("producer", queue);
|
||||||
|
@ -155,19 +155,15 @@ public class App {
|
|||||||
* This is an async method and does not wait until the file is downloaded.
|
* This is an async method and does not wait until the file is downloaded.
|
||||||
*/
|
*/
|
||||||
private Promise<String> download(String urlString) {
|
private Promise<String> download(String urlString) {
|
||||||
Promise<String> downloadPromise = new Promise<String>()
|
return new Promise<String>()
|
||||||
.fulfillInAsync(
|
.fulfillInAsync(
|
||||||
() -> {
|
() -> Utility.downloadFile(urlString), executor)
|
||||||
return Utility.downloadFile(urlString);
|
|
||||||
}, executor)
|
|
||||||
.onError(
|
.onError(
|
||||||
throwable -> {
|
throwable -> {
|
||||||
throwable.printStackTrace();
|
throwable.printStackTrace();
|
||||||
taskCompleted();
|
taskCompleted();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
return downloadPromise;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void stop() throws InterruptedException {
|
private void stop() throws InterruptedException {
|
||||||
|
@ -111,7 +111,7 @@ public class Utility {
|
|||||||
* Downloads the contents from the given urlString, and stores it in a temporary directory.
|
* Downloads the contents from the given urlString, and stores it in a temporary directory.
|
||||||
* @return the absolute path of the file downloaded.
|
* @return the absolute path of the file downloaded.
|
||||||
*/
|
*/
|
||||||
public static String downloadFile(String urlString) throws MalformedURLException, IOException {
|
public static String downloadFile(String urlString) throws IOException {
|
||||||
LOGGER.info("Downloading contents from url: {}", urlString);
|
LOGGER.info("Downloading contents from url: {}", urlString);
|
||||||
URL url = new URL(urlString);
|
URL url = new URL(urlString);
|
||||||
File file = File.createTempFile("promise_pattern", null);
|
File file = File.createTempFile("promise_pattern", null);
|
||||||
|
@ -76,12 +76,8 @@ public class PromiseTest {
|
|||||||
private void testWaitingForeverForPromiseToBeFulfilled()
|
private void testWaitingForeverForPromiseToBeFulfilled()
|
||||||
throws InterruptedException, TimeoutException {
|
throws InterruptedException, TimeoutException {
|
||||||
Promise<Integer> promise = new Promise<>();
|
Promise<Integer> promise = new Promise<>();
|
||||||
promise.fulfillInAsync(new Callable<Integer>() {
|
promise.fulfillInAsync(() -> {
|
||||||
|
throw new RuntimeException("Barf!");
|
||||||
@Override
|
|
||||||
public Integer call() throws Exception {
|
|
||||||
throw new RuntimeException("Barf!");
|
|
||||||
}
|
|
||||||
}, executor);
|
}, executor);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -104,12 +100,8 @@ public class PromiseTest {
|
|||||||
private void testWaitingSomeTimeForPromiseToBeFulfilled()
|
private void testWaitingSomeTimeForPromiseToBeFulfilled()
|
||||||
throws InterruptedException, TimeoutException {
|
throws InterruptedException, TimeoutException {
|
||||||
Promise<Integer> promise = new Promise<>();
|
Promise<Integer> promise = new Promise<>();
|
||||||
promise.fulfillInAsync(new Callable<Integer>() {
|
promise.fulfillInAsync(() -> {
|
||||||
|
throw new RuntimeException("Barf!");
|
||||||
@Override
|
|
||||||
public Integer call() throws Exception {
|
|
||||||
throw new RuntimeException("Barf!");
|
|
||||||
}
|
|
||||||
}, executor);
|
}, executor);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -150,12 +142,8 @@ public class PromiseTest {
|
|||||||
throws InterruptedException, ExecutionException, TimeoutException {
|
throws InterruptedException, ExecutionException, TimeoutException {
|
||||||
Promise<Void> dependentPromise = promise
|
Promise<Void> dependentPromise = promise
|
||||||
.fulfillInAsync(new NumberCrunchingTask(), executor)
|
.fulfillInAsync(new NumberCrunchingTask(), executor)
|
||||||
.thenAccept(new Consumer<Integer>() {
|
.thenAccept(value -> {
|
||||||
|
throw new RuntimeException("Barf!");
|
||||||
@Override
|
|
||||||
public void accept(Integer value) {
|
|
||||||
throw new RuntimeException("Barf!");
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -198,12 +186,8 @@ public class PromiseTest {
|
|||||||
throws InterruptedException, ExecutionException, TimeoutException {
|
throws InterruptedException, ExecutionException, TimeoutException {
|
||||||
Promise<String> dependentPromise = promise
|
Promise<String> dependentPromise = promise
|
||||||
.fulfillInAsync(new NumberCrunchingTask(), executor)
|
.fulfillInAsync(new NumberCrunchingTask(), executor)
|
||||||
.thenApply(new Function<Integer, String>() {
|
.thenApply(value -> {
|
||||||
|
throw new RuntimeException("Barf!");
|
||||||
@Override
|
|
||||||
public String apply(Integer value) {
|
|
||||||
throw new RuntimeException("Barf!");
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -73,7 +73,7 @@ public class CharacterTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testToString() throws Exception {
|
public void testToString() {
|
||||||
final Character prototype = new Character();
|
final Character prototype = new Character();
|
||||||
prototype.set(Stats.ARMOR, 1);
|
prototype.set(Stats.ARMOR, 1);
|
||||||
prototype.set(Stats.AGILITY, 2);
|
prototype.set(Stats.AGILITY, 2);
|
||||||
@ -91,7 +91,7 @@ public class CharacterTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testName() throws Exception {
|
public void testName() {
|
||||||
final Character prototype = new Character();
|
final Character prototype = new Character();
|
||||||
prototype.set(Stats.ARMOR, 1);
|
prototype.set(Stats.ARMOR, 1);
|
||||||
prototype.set(Stats.INTELLECT, 2);
|
prototype.set(Stats.INTELLECT, 2);
|
||||||
@ -107,7 +107,7 @@ public class CharacterTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testType() throws Exception {
|
public void testType() {
|
||||||
final Character prototype = new Character();
|
final Character prototype = new Character();
|
||||||
prototype.set(Stats.ARMOR, 1);
|
prototype.set(Stats.ARMOR, 1);
|
||||||
prototype.set(Stats.INTELLECT, 2);
|
prototype.set(Stats.INTELLECT, 2);
|
||||||
|
@ -40,7 +40,7 @@ public class ElfBeast extends Beast {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Beast copy() throws CloneNotSupportedException {
|
public Beast copy() {
|
||||||
return new ElfBeast(this);
|
return new ElfBeast(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,7 @@ public class ElfMage extends Mage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ElfMage copy() throws CloneNotSupportedException {
|
public ElfMage copy() {
|
||||||
return new ElfMage(this);
|
return new ElfMage(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ public class ElfWarlord extends Warlord {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ElfWarlord copy() throws CloneNotSupportedException {
|
public ElfWarlord copy() {
|
||||||
return new ElfWarlord(this);
|
return new ElfWarlord(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ public class OrcBeast extends Beast {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Beast copy() throws CloneNotSupportedException {
|
public Beast copy() {
|
||||||
return new OrcBeast(this);
|
return new OrcBeast(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ public class OrcMage extends Mage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OrcMage copy() throws CloneNotSupportedException {
|
public OrcMage copy() {
|
||||||
return new OrcMage(this);
|
return new OrcMage(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ public class OrcWarlord extends Warlord {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public OrcWarlord copy() throws CloneNotSupportedException {
|
public OrcWarlord copy() {
|
||||||
return new OrcWarlord(this);
|
return new OrcWarlord(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,8 +110,6 @@ public class App {
|
|||||||
LOGGER.info("Executor was shut down and Exiting.");
|
LOGGER.info("Executor was shut down and Exiting.");
|
||||||
executor.shutdownNow();
|
executor.shutdownNow();
|
||||||
}
|
}
|
||||||
} catch (InterruptedException ie) {
|
|
||||||
LOGGER.error(ie.getMessage());
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error(e.getMessage());
|
LOGGER.error(e.getMessage());
|
||||||
}
|
}
|
||||||
|
@ -58,8 +58,6 @@ public class ServiceExecutor implements Runnable {
|
|||||||
|
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
}
|
}
|
||||||
} catch (InterruptedException ie) {
|
|
||||||
LOGGER.error(ie.getMessage());
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error(e.getMessage());
|
LOGGER.error(e.getMessage());
|
||||||
}
|
}
|
||||||
|
@ -80,8 +80,6 @@ public class TaskGenerator implements Task, Runnable {
|
|||||||
// Make the current thread to sleep after every Message submission.
|
// Make the current thread to sleep after every Message submission.
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
}
|
}
|
||||||
} catch (InterruptedException ie) {
|
|
||||||
LOGGER.error(ie.getMessage());
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.error(e.getMessage());
|
LOGGER.error(e.getMessage());
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,7 @@ public class MessageQueueTest {
|
|||||||
msgQueue.submitMsg(new Message("MessageQueue Test"));
|
msgQueue.submitMsg(new Message("MessageQueue Test"));
|
||||||
|
|
||||||
// retrieve message
|
// retrieve message
|
||||||
assertEquals(msgQueue.retrieveMsg().getMsg(), "MessageQueue Test");
|
assertEquals("MessageQueue Test", msgQueue.retrieveMsg().getMsg());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -39,6 +39,6 @@ public class MessageTest {
|
|||||||
// Parameterized constructor test.
|
// Parameterized constructor test.
|
||||||
String testMsg = "Message Test";
|
String testMsg = "Message Test";
|
||||||
Message msg = new Message(testMsg);
|
Message msg = new Message(testMsg);
|
||||||
assertEquals(msg.getMsg(), testMsg);
|
assertEquals(testMsg, msg.getMsg());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,14 +22,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.iluwatar.repository;
|
package com.iluwatar.repository;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@ -38,6 +30,13 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
|
|||||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import javax.sql.DataSource;
|
||||||
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This case is Just for test the Annotation Based configuration
|
* This case is Just for test the Annotation Based configuration
|
||||||
*
|
*
|
||||||
@ -70,7 +69,7 @@ public class AppConfigTest {
|
|||||||
result = resultSet.getString(1);
|
result = resultSet.getString(1);
|
||||||
|
|
||||||
}
|
}
|
||||||
assertTrue(result.equals(expected));
|
assertEquals(expected, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ import java.io.IOException;
|
|||||||
*/
|
*/
|
||||||
public class AppTest {
|
public class AppTest {
|
||||||
@Test
|
@Test
|
||||||
public void test() throws IOException {
|
public void test() {
|
||||||
String[] args = {};
|
String[] args = {};
|
||||||
App.main(args);
|
App.main(args);
|
||||||
}
|
}
|
||||||
|
@ -109,9 +109,7 @@ public class RepositoryTest {
|
|||||||
List<Person> persons = repository.findAll(new PersonSpecifications.AgeBetweenSpec(20, 40));
|
List<Person> persons = repository.findAll(new PersonSpecifications.AgeBetweenSpec(20, 40));
|
||||||
|
|
||||||
assertEquals(3, persons.size());
|
assertEquals(3, persons.size());
|
||||||
assertTrue(persons.stream().allMatch((item) -> {
|
assertTrue(persons.stream().allMatch(item -> item.getAge() > 20 && item.getAge() < 40));
|
||||||
return item.getAge() > 20 && item.getAge() < 40;
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -53,7 +53,7 @@ public class FindCustomerTest {
|
|||||||
* @throws Exception the expected exception
|
* @throws Exception the expected exception
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void oneException() throws Exception {
|
public void oneException() {
|
||||||
assertThrows(BusinessException.class, () -> {
|
assertThrows(BusinessException.class, () -> {
|
||||||
new FindCustomer("123", new BusinessException("test")).perform();
|
new FindCustomer("123", new BusinessException("test")).perform();
|
||||||
});
|
});
|
||||||
|
@ -40,7 +40,7 @@ public class RetryTest {
|
|||||||
* Should contain all errors thrown.
|
* Should contain all errors thrown.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void errors() throws Exception {
|
public void errors() {
|
||||||
final BusinessException e = new BusinessException("unhandled");
|
final BusinessException e = new BusinessException("unhandled");
|
||||||
final Retry<String> retry = new Retry<>(
|
final Retry<String> retry = new Retry<>(
|
||||||
() -> { throw e; },
|
() -> { throw e; },
|
||||||
|
@ -31,7 +31,7 @@ import java.io.IOException;
|
|||||||
*/
|
*/
|
||||||
public class AppTest {
|
public class AppTest {
|
||||||
@Test
|
@Test
|
||||||
public void test() throws IOException {
|
public void test() {
|
||||||
String[] args = {};
|
String[] args = {};
|
||||||
App.main(args);
|
App.main(args);
|
||||||
}
|
}
|
||||||
|
@ -37,16 +37,16 @@ public class FruitBowlTest {
|
|||||||
public void fruitBowlTest() {
|
public void fruitBowlTest() {
|
||||||
FruitBowl fbowl = new FruitBowl();
|
FruitBowl fbowl = new FruitBowl();
|
||||||
|
|
||||||
assertEquals(fbowl.countFruit(), 0);
|
assertEquals(0, fbowl.countFruit());
|
||||||
|
|
||||||
for (int i = 1; i <= 10; i++) {
|
for (int i = 1; i <= 10; i++) {
|
||||||
fbowl.put(new Fruit(Fruit.FruitType.LEMON));
|
fbowl.put(new Fruit(Fruit.FruitType.LEMON));
|
||||||
assertEquals(fbowl.countFruit(), i);
|
assertEquals(i, fbowl.countFruit());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 9; i >= 0; i--) {
|
for (int i = 9; i >= 0; i--) {
|
||||||
assertNotNull(fbowl.take());
|
assertNotNull(fbowl.take());
|
||||||
assertEquals(fbowl.countFruit(), i);
|
assertEquals(i, fbowl.countFruit());
|
||||||
}
|
}
|
||||||
|
|
||||||
assertNull(fbowl.take());
|
assertNull(fbowl.take());
|
||||||
|
@ -36,12 +36,12 @@ public class SemaphoreTest {
|
|||||||
public void acquireReleaseTest() {
|
public void acquireReleaseTest() {
|
||||||
Semaphore sphore = new Semaphore(3);
|
Semaphore sphore = new Semaphore(3);
|
||||||
|
|
||||||
assertEquals(sphore.getAvailableLicenses(), 3);
|
assertEquals(3, sphore.getAvailableLicenses());
|
||||||
|
|
||||||
for (int i = 2; i >= 0; i--) {
|
for (int i = 2; i >= 0; i--) {
|
||||||
try {
|
try {
|
||||||
sphore.acquire();
|
sphore.acquire();
|
||||||
assertEquals(sphore.getAvailableLicenses(), i);
|
assertEquals(i, sphore.getAvailableLicenses());
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
fail(e.toString());
|
fail(e.toString());
|
||||||
}
|
}
|
||||||
@ -49,10 +49,10 @@ public class SemaphoreTest {
|
|||||||
|
|
||||||
for (int i = 1; i <= 3; i++) {
|
for (int i = 1; i <= 3; i++) {
|
||||||
sphore.release();
|
sphore.release();
|
||||||
assertEquals(sphore.getAvailableLicenses(), i);
|
assertEquals(i, sphore.getAvailableLicenses());
|
||||||
}
|
}
|
||||||
|
|
||||||
sphore.release();
|
sphore.release();
|
||||||
assertEquals(sphore.getAvailableLicenses(), 3);
|
assertEquals(3, sphore.getAvailableLicenses());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||||||
public class QueenTest {
|
public class QueenTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNotFlirtyUncomplemented() throws Exception {
|
public void testNotFlirtyUncomplemented() {
|
||||||
final Queen queen = new Queen();
|
final Queen queen = new Queen();
|
||||||
queen.setFlirtiness(false);
|
queen.setFlirtiness(false);
|
||||||
queen.changeMood();
|
queen.changeMood();
|
||||||
@ -44,7 +44,7 @@ public class QueenTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testNotFlirtyComplemented() throws Exception {
|
public void testNotFlirtyComplemented() {
|
||||||
final Queen queen = new Queen();
|
final Queen queen = new Queen();
|
||||||
queen.setFlirtiness(false);
|
queen.setFlirtiness(false);
|
||||||
queen.receiveCompliments();
|
queen.receiveCompliments();
|
||||||
@ -53,14 +53,14 @@ public class QueenTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFlirtyUncomplemented() throws Exception {
|
public void testFlirtyUncomplemented() {
|
||||||
final Queen queen = new Queen();
|
final Queen queen = new Queen();
|
||||||
queen.changeMood();
|
queen.changeMood();
|
||||||
assertFalse(queen.getMood());
|
assertFalse(queen.getMood());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFlirtyComplemented() throws Exception {
|
public void testFlirtyComplemented() {
|
||||||
final Queen queen = new Queen();
|
final Queen queen = new Queen();
|
||||||
queen.receiveCompliments();
|
queen.receiveCompliments();
|
||||||
queen.changeMood();
|
queen.changeMood();
|
||||||
|
@ -41,7 +41,7 @@ import static org.mockito.Mockito.when;
|
|||||||
public class ServantTest {
|
public class ServantTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFeed() throws Exception {
|
public void testFeed() {
|
||||||
final Royalty royalty = mock(Royalty.class);
|
final Royalty royalty = mock(Royalty.class);
|
||||||
final Servant servant = new Servant("test");
|
final Servant servant = new Servant("test");
|
||||||
servant.feed(royalty);
|
servant.feed(royalty);
|
||||||
@ -50,7 +50,7 @@ public class ServantTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGiveWine() throws Exception {
|
public void testGiveWine() {
|
||||||
final Royalty royalty = mock(Royalty.class);
|
final Royalty royalty = mock(Royalty.class);
|
||||||
final Servant servant = new Servant("test");
|
final Servant servant = new Servant("test");
|
||||||
servant.giveWine(royalty);
|
servant.giveWine(royalty);
|
||||||
@ -59,7 +59,7 @@ public class ServantTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGiveCompliments() throws Exception {
|
public void testGiveCompliments() {
|
||||||
final Royalty royalty = mock(Royalty.class);
|
final Royalty royalty = mock(Royalty.class);
|
||||||
final Servant servant = new Servant("test");
|
final Servant servant = new Servant("test");
|
||||||
servant.giveCompliments(royalty);
|
servant.giveCompliments(royalty);
|
||||||
@ -68,7 +68,7 @@ public class ServantTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCheckIfYouWillBeHanged() throws Exception {
|
public void testCheckIfYouWillBeHanged() {
|
||||||
final Royalty goodMoodRoyalty = mock(Royalty.class);
|
final Royalty goodMoodRoyalty = mock(Royalty.class);
|
||||||
when(goodMoodRoyalty.getMood()).thenReturn(true);
|
when(goodMoodRoyalty.getMood()).thenReturn(true);
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ import org.apache.log4j.Logger;
|
|||||||
* find person from persons collection
|
* find person from persons collection
|
||||||
* Created by dheeraj.mummar on 3/5/18.
|
* Created by dheeraj.mummar on 3/5/18.
|
||||||
*/
|
*/
|
||||||
public class FindPersonApiHandler extends AbstractDynamoDbHandler
|
public class FindPersonApiHandler extends AbstractDynamoDbHandler<Person>
|
||||||
implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
|
implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
|
||||||
|
|
||||||
private static final Logger LOG = Logger.getLogger(FindPersonApiHandler.class);
|
private static final Logger LOG = Logger.getLogger(FindPersonApiHandler.class);
|
||||||
|
@ -35,7 +35,7 @@ import java.io.IOException;
|
|||||||
* save person into persons collection
|
* save person into persons collection
|
||||||
* Created by dheeraj.mummar on 3/4/18.
|
* Created by dheeraj.mummar on 3/4/18.
|
||||||
*/
|
*/
|
||||||
public class SavePersonApiHandler extends AbstractDynamoDbHandler
|
public class SavePersonApiHandler extends AbstractDynamoDbHandler<Person>
|
||||||
implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
|
implements RequestHandler<APIGatewayProxyRequestEvent, APIGatewayProxyResponseEvent> {
|
||||||
|
|
||||||
private static final Logger LOG = Logger.getLogger(SavePersonApiHandler.class);
|
private static final Logger LOG = Logger.getLogger(SavePersonApiHandler.class);
|
||||||
|
@ -1,50 +0,0 @@
|
|||||||
<?xml version="1.0"?>
|
|
||||||
<!--
|
|
||||||
|
|
||||||
The MIT License
|
|
||||||
Copyright (c) 2014-2016 Ilkka Seppälä
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||
|
|
||||||
-->
|
|
||||||
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<parent>
|
|
||||||
<groupId>com.iluwatar</groupId>
|
|
||||||
<artifactId>java-design-patterns</artifactId>
|
|
||||||
<version>1.0-SNAPSHOT</version>
|
|
||||||
</parent>
|
|
||||||
<artifactId>dao</artifactId>
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.hibernate</groupId>
|
|
||||||
<artifactId>hibernate-core</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.h2database</groupId>
|
|
||||||
<artifactId>h2</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>junit</groupId>
|
|
||||||
<artifactId>junit</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
</project>
|
|
@ -38,10 +38,9 @@ public class SpellDaoImpl extends DaoBaseImpl<Spell> implements SpellDao {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Spell findByName(String name) {
|
public Spell findByName(String name) {
|
||||||
Session session = getSessionFactory().openSession();
|
|
||||||
Transaction tx = null;
|
Transaction tx = null;
|
||||||
Spell result = null;
|
Spell result = null;
|
||||||
try {
|
try (Session session = getSessionFactory().openSession()) {
|
||||||
tx = session.beginTransaction();
|
tx = session.beginTransaction();
|
||||||
Criteria criteria = session.createCriteria(persistentClass);
|
Criteria criteria = session.createCriteria(persistentClass);
|
||||||
criteria.add(Restrictions.eq("name", name));
|
criteria.add(Restrictions.eq("name", name));
|
||||||
@ -52,8 +51,6 @@ public class SpellDaoImpl extends DaoBaseImpl<Spell> implements SpellDao {
|
|||||||
tx.rollback();
|
tx.rollback();
|
||||||
}
|
}
|
||||||
throw e;
|
throw e;
|
||||||
} finally {
|
|
||||||
session.close();
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -40,7 +40,7 @@ public class AppTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@AfterEach
|
@AfterEach
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() {
|
||||||
HibernateUtil.dropSession();
|
HibernateUtil.dropSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ public abstract class BaseDaoTest<E extends BaseEntity, D extends DaoBaseImpl<E>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
public void setUp() throws Exception {
|
public void setUp() {
|
||||||
for (int i = 0; i < INITIAL_COUNT; i++) {
|
for (int i = 0; i < INITIAL_COUNT; i++) {
|
||||||
final String className = dao.persistentClass.getSimpleName();
|
final String className = dao.persistentClass.getSimpleName();
|
||||||
final String entityName = String.format("%s%d", className, ID_GENERATOR.incrementAndGet());
|
final String entityName = String.format("%s%d", className, ID_GENERATOR.incrementAndGet());
|
||||||
@ -85,7 +85,7 @@ public abstract class BaseDaoTest<E extends BaseEntity, D extends DaoBaseImpl<E>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@AfterEach
|
@AfterEach
|
||||||
public void tearDown() throws Exception {
|
public void tearDown() {
|
||||||
HibernateUtil.dropSession();
|
HibernateUtil.dropSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +94,7 @@ public abstract class BaseDaoTest<E extends BaseEntity, D extends DaoBaseImpl<E>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFind() throws Exception {
|
public void testFind() {
|
||||||
final List<E> all = this.dao.findAll();
|
final List<E> all = this.dao.findAll();
|
||||||
for (final E entity : all) {
|
for (final E entity : all) {
|
||||||
final E byId = this.dao.find(entity.getId());
|
final E byId = this.dao.find(entity.getId());
|
||||||
@ -104,7 +104,7 @@ public abstract class BaseDaoTest<E extends BaseEntity, D extends DaoBaseImpl<E>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDelete() throws Exception {
|
public void testDelete() {
|
||||||
final List<E> originalEntities = this.dao.findAll();
|
final List<E> originalEntities = this.dao.findAll();
|
||||||
this.dao.delete(originalEntities.get(1));
|
this.dao.delete(originalEntities.get(1));
|
||||||
this.dao.delete(originalEntities.get(2));
|
this.dao.delete(originalEntities.get(2));
|
||||||
@ -115,24 +115,24 @@ public abstract class BaseDaoTest<E extends BaseEntity, D extends DaoBaseImpl<E>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFindAll() throws Exception {
|
public void testFindAll() {
|
||||||
final List<E> all = this.dao.findAll();
|
final List<E> all = this.dao.findAll();
|
||||||
assertNotNull(all);
|
assertNotNull(all);
|
||||||
assertEquals(INITIAL_COUNT, all.size());
|
assertEquals(INITIAL_COUNT, all.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetId() throws Exception {
|
public void testSetId() {
|
||||||
final E entity = this.factory.apply("name");
|
final E entity = this.factory.apply("name");
|
||||||
assertNull(entity.getId());
|
assertNull(entity.getId());
|
||||||
|
|
||||||
final Long expectedId = Long.valueOf(1);
|
final Long expectedId = 1L;
|
||||||
entity.setId(expectedId);
|
entity.setId(expectedId);
|
||||||
assertEquals(expectedId, entity.getId());
|
assertEquals(expectedId, entity.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetName() throws Exception {
|
public void testSetName() {
|
||||||
final E entity = this.factory.apply("name");
|
final E entity = this.factory.apply("name");
|
||||||
assertEquals("name", entity.getName());
|
assertEquals("name", entity.getName());
|
||||||
assertEquals("name", entity.toString());
|
assertEquals("name", entity.toString());
|
||||||
|
@ -51,7 +51,7 @@ import static org.mockito.Mockito.when;
|
|||||||
public class MagicServiceImplTest {
|
public class MagicServiceImplTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFindAllWizards() throws Exception {
|
public void testFindAllWizards() {
|
||||||
final WizardDao wizardDao = mock(WizardDao.class);
|
final WizardDao wizardDao = mock(WizardDao.class);
|
||||||
final SpellbookDao spellbookDao = mock(SpellbookDao.class);
|
final SpellbookDao spellbookDao = mock(SpellbookDao.class);
|
||||||
final SpellDao spellDao = mock(SpellDao.class);
|
final SpellDao spellDao = mock(SpellDao.class);
|
||||||
|
@ -42,7 +42,7 @@ public class SpellDaoImplTest extends BaseDaoTest<Spell, SpellDaoImpl> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFindByName() throws Exception {
|
public void testFindByName() {
|
||||||
final SpellDaoImpl dao = getDao();
|
final SpellDaoImpl dao = getDao();
|
||||||
final List<Spell> allSpells = dao.findAll();
|
final List<Spell> allSpells = dao.findAll();
|
||||||
for (final Spell spell : allSpells) {
|
for (final Spell spell : allSpells) {
|
||||||
|
@ -42,7 +42,7 @@ public class SpellbookDaoImplTest extends BaseDaoTest<Spellbook, SpellbookDaoImp
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFindByName() throws Exception {
|
public void testFindByName() {
|
||||||
final SpellbookDaoImpl dao = getDao();
|
final SpellbookDaoImpl dao = getDao();
|
||||||
final List<Spellbook> allBooks = dao.findAll();
|
final List<Spellbook> allBooks = dao.findAll();
|
||||||
for (final Spellbook book : allBooks) {
|
for (final Spellbook book : allBooks) {
|
||||||
|
@ -42,7 +42,7 @@ public class WizardDaoImplTest extends BaseDaoTest<Wizard, WizardDaoImpl> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFindByName() throws Exception {
|
public void testFindByName() {
|
||||||
final WizardDaoImpl dao = getDao();
|
final WizardDaoImpl dao = getDao();
|
||||||
final List<Wizard> allWizards = dao.findAll();
|
final List<Wizard> allWizards = dao.findAll();
|
||||||
for (final Wizard spell : allWizards) {
|
for (final Wizard spell : allWizards) {
|
||||||
|
@ -70,18 +70,18 @@ public class App {
|
|||||||
List<Creature> walkingCreatures =
|
List<Creature> walkingCreatures =
|
||||||
creatures.stream().filter(new MovementSelector(Movement.WALKING))
|
creatures.stream().filter(new MovementSelector(Movement.WALKING))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
walkingCreatures.stream().forEach(c -> LOGGER.info(c.toString()));
|
walkingCreatures.forEach(c -> LOGGER.info(c.toString()));
|
||||||
// find all dark creatures
|
// find all dark creatures
|
||||||
LOGGER.info("Find all dark creatures");
|
LOGGER.info("Find all dark creatures");
|
||||||
List<Creature> darkCreatures =
|
List<Creature> darkCreatures =
|
||||||
creatures.stream().filter(new ColorSelector(Color.DARK)).collect(Collectors.toList());
|
creatures.stream().filter(new ColorSelector(Color.DARK)).collect(Collectors.toList());
|
||||||
darkCreatures.stream().forEach(c -> LOGGER.info(c.toString()));
|
darkCreatures.forEach(c -> LOGGER.info(c.toString()));
|
||||||
// find all red and flying creatures
|
// find all red and flying creatures
|
||||||
LOGGER.info("Find all red and flying creatures");
|
LOGGER.info("Find all red and flying creatures");
|
||||||
List<Creature> redAndFlyingCreatures =
|
List<Creature> redAndFlyingCreatures =
|
||||||
creatures.stream()
|
creatures.stream()
|
||||||
.filter(new ColorSelector(Color.RED).and(new MovementSelector(Movement.FLYING)))
|
.filter(new ColorSelector(Color.RED).and(new MovementSelector(Movement.FLYING)))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
redAndFlyingCreatures.stream().forEach(c -> LOGGER.info(c.toString()));
|
redAndFlyingCreatures.forEach(c -> LOGGER.info(c.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,33 +57,33 @@ public class CreatureTest {
|
|||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("dataProvider")
|
@MethodSource("dataProvider")
|
||||||
public void testGetName(Creature testedCreature, String name) throws Exception {
|
public void testGetName(Creature testedCreature, String name) {
|
||||||
assertEquals(name, testedCreature.getName());
|
assertEquals(name, testedCreature.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("dataProvider")
|
@MethodSource("dataProvider")
|
||||||
public void testGetSize(Creature testedCreature, String name, Size size) throws Exception {
|
public void testGetSize(Creature testedCreature, String name, Size size) {
|
||||||
assertEquals(size, testedCreature.getSize());
|
assertEquals(size, testedCreature.getSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("dataProvider")
|
@MethodSource("dataProvider")
|
||||||
public void testGetMovement(Creature testedCreature, String name, Size size, Movement movement) throws Exception {
|
public void testGetMovement(Creature testedCreature, String name, Size size, Movement movement) {
|
||||||
assertEquals(movement, testedCreature.getMovement());
|
assertEquals(movement, testedCreature.getMovement());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("dataProvider")
|
@MethodSource("dataProvider")
|
||||||
public void testGetColor(Creature testedCreature, String name, Size size, Movement movement,
|
public void testGetColor(Creature testedCreature, String name, Size size, Movement movement,
|
||||||
Color color) throws Exception {
|
Color color) {
|
||||||
assertEquals(color, testedCreature.getColor());
|
assertEquals(color, testedCreature.getColor());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ParameterizedTest
|
@ParameterizedTest
|
||||||
@MethodSource("dataProvider")
|
@MethodSource("dataProvider")
|
||||||
public void testToString(Creature testedCreature, String name, Size size, Movement movement,
|
public void testToString(Creature testedCreature, String name, Size size, Movement movement,
|
||||||
Color color) throws Exception {
|
Color color) {
|
||||||
final String toString = testedCreature.toString();
|
final String toString = testedCreature.toString();
|
||||||
assertNotNull(toString);
|
assertNotNull(toString);
|
||||||
assertEquals(
|
assertEquals(
|
||||||
|
@ -105,7 +105,7 @@ public class DateFormatCallableTestIncorrectDateFormat {
|
|||||||
* same exception
|
* same exception
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testExecptions() {
|
public void testExceptions() {
|
||||||
assertEquals(expectedExceptions, result.getExceptionList());
|
assertEquals(expectedExceptions, result.getExceptionList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,7 +24,9 @@ package com.iluwatar.tolerantreader;
|
|||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Date: 12/30/15 - 18:35 PM
|
* Date: 12/30/15 - 18:35 PM
|
||||||
@ -43,9 +45,9 @@ public class RainbowFishV2Test {
|
|||||||
assertEquals(1, fish.getAge());
|
assertEquals(1, fish.getAge());
|
||||||
assertEquals(2, fish.getLengthMeters());
|
assertEquals(2, fish.getLengthMeters());
|
||||||
assertEquals(3, fish.getWeightTons());
|
assertEquals(3, fish.getWeightTons());
|
||||||
assertEquals(false, fish.getSleeping());
|
assertFalse(fish.getSleeping());
|
||||||
assertEquals(true, fish.getHungry());
|
assertTrue(fish.getHungry());
|
||||||
assertEquals(false, fish.getAngry());
|
assertFalse(fish.getAngry());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -36,7 +36,7 @@ public class TrampolineAppTest {
|
|||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testTrampolineWithFactorialFunction() throws IOException {
|
public void testTrampolineWithFactorialFunction() {
|
||||||
int result = TrampolineApp.loop(10, 1).result();
|
int result = TrampolineApp.loop(10, 1).result();
|
||||||
assertEquals("Be equal", 3628800, result);
|
assertEquals("Be equal", 3628800, result);
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ public class BallThreadTest {
|
|||||||
* Verify if the {@link BallThread} can be resumed
|
* Verify if the {@link BallThread} can be resumed
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testResume() throws Exception {
|
public void testResume() {
|
||||||
assertTimeout(ofMillis(5000), () -> {
|
assertTimeout(ofMillis(5000), () -> {
|
||||||
final BallThread ballThread = new BallThread();
|
final BallThread ballThread = new BallThread();
|
||||||
|
|
||||||
@ -102,7 +102,7 @@ public class BallThreadTest {
|
|||||||
* Verify if the {@link BallThread} is interruptible
|
* Verify if the {@link BallThread} is interruptible
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testInterrupt() throws Exception {
|
public void testInterrupt() {
|
||||||
assertTimeout(ofMillis(5000), () -> {
|
assertTimeout(ofMillis(5000), () -> {
|
||||||
final BallThread ballThread = new BallThread();
|
final BallThread ballThread = new BallThread();
|
||||||
final UncaughtExceptionHandler exceptionHandler = mock(UncaughtExceptionHandler.class);
|
final UncaughtExceptionHandler exceptionHandler = mock(UncaughtExceptionHandler.class);
|
||||||
|
@ -33,7 +33,7 @@ import java.io.IOException;
|
|||||||
*/
|
*/
|
||||||
public class AppTest {
|
public class AppTest {
|
||||||
@Test
|
@Test
|
||||||
public void test() throws IOException {
|
public void test() {
|
||||||
String[] args = {};
|
String[] args = {};
|
||||||
App.main(args);
|
App.main(args);
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ public class StudentRepositoryTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldSaveNewStudentWithoutWritingToDb() throws Exception {
|
public void shouldSaveNewStudentWithoutWritingToDb() {
|
||||||
studentRepository.registerNew(student1);
|
studentRepository.registerNew(student1);
|
||||||
studentRepository.registerNew(student2);
|
studentRepository.registerNew(student2);
|
||||||
|
|
||||||
@ -67,7 +67,7 @@ public class StudentRepositoryTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldSaveDeletedStudentWithoutWritingToDb() throws Exception {
|
public void shouldSaveDeletedStudentWithoutWritingToDb() {
|
||||||
studentRepository.registerDeleted(student1);
|
studentRepository.registerDeleted(student1);
|
||||||
studentRepository.registerDeleted(student2);
|
studentRepository.registerDeleted(student2);
|
||||||
|
|
||||||
@ -76,7 +76,7 @@ public class StudentRepositoryTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldSaveModifiedStudentWithoutWritingToDb() throws Exception {
|
public void shouldSaveModifiedStudentWithoutWritingToDb() {
|
||||||
studentRepository.registerModified(student1);
|
studentRepository.registerModified(student1);
|
||||||
studentRepository.registerModified(student2);
|
studentRepository.registerModified(student2);
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ public class StudentRepositoryTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldSaveAllLocalChangesToDb() throws Exception {
|
public void shouldSaveAllLocalChangesToDb() {
|
||||||
context.put(IUnitOfWork.INSERT, Collections.singletonList(student1));
|
context.put(IUnitOfWork.INSERT, Collections.singletonList(student1));
|
||||||
context.put(IUnitOfWork.MODIFY, Collections.singletonList(student1));
|
context.put(IUnitOfWork.MODIFY, Collections.singletonList(student1));
|
||||||
context.put(IUnitOfWork.DELETE, Collections.singletonList(student1));
|
context.put(IUnitOfWork.DELETE, Collections.singletonList(student1));
|
||||||
@ -98,7 +98,7 @@ public class StudentRepositoryTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldNotWriteToDbIfContextIsNull() throws Exception {
|
public void shouldNotWriteToDbIfContextIsNull() {
|
||||||
StudentRepository studentRepository = new StudentRepository(null, studentDatabase);
|
StudentRepository studentRepository = new StudentRepository(null, studentDatabase);
|
||||||
|
|
||||||
studentRepository.commit();
|
studentRepository.commit();
|
||||||
@ -107,7 +107,7 @@ public class StudentRepositoryTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldNotWriteToDbIfNothingToCommit() throws Exception {
|
public void shouldNotWriteToDbIfNothingToCommit() {
|
||||||
StudentRepository studentRepository = new StudentRepository(new HashMap<>(), studentDatabase);
|
StudentRepository studentRepository = new StudentRepository(new HashMap<>(), studentDatabase);
|
||||||
|
|
||||||
studentRepository.commit();
|
studentRepository.commit();
|
||||||
@ -116,7 +116,7 @@ public class StudentRepositoryTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldNotInsertToDbIfNoRegisteredStudentsToBeCommitted() throws Exception {
|
public void shouldNotInsertToDbIfNoRegisteredStudentsToBeCommitted() {
|
||||||
context.put(IUnitOfWork.MODIFY, Collections.singletonList(student1));
|
context.put(IUnitOfWork.MODIFY, Collections.singletonList(student1));
|
||||||
context.put(IUnitOfWork.DELETE, Collections.singletonList(student1));
|
context.put(IUnitOfWork.DELETE, Collections.singletonList(student1));
|
||||||
|
|
||||||
@ -126,7 +126,7 @@ public class StudentRepositoryTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldNotModifyToDbIfNotRegisteredStudentsToBeCommitted() throws Exception {
|
public void shouldNotModifyToDbIfNotRegisteredStudentsToBeCommitted() {
|
||||||
context.put(IUnitOfWork.INSERT, Collections.singletonList(student1));
|
context.put(IUnitOfWork.INSERT, Collections.singletonList(student1));
|
||||||
context.put(IUnitOfWork.DELETE, Collections.singletonList(student1));
|
context.put(IUnitOfWork.DELETE, Collections.singletonList(student1));
|
||||||
|
|
||||||
@ -136,7 +136,7 @@ public class StudentRepositoryTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldNotDeleteFromDbIfNotRegisteredStudentsToBeCommitted() throws Exception {
|
public void shouldNotDeleteFromDbIfNotRegisteredStudentsToBeCommitted() {
|
||||||
context.put(IUnitOfWork.INSERT, Collections.singletonList(student1));
|
context.put(IUnitOfWork.INSERT, Collections.singletonList(student1));
|
||||||
context.put(IUnitOfWork.MODIFY, Collections.singletonList(student1));
|
context.put(IUnitOfWork.MODIFY, Collections.singletonList(student1));
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ public abstract class UnitTest<U extends Unit> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAccept() throws Exception {
|
public void testAccept() {
|
||||||
final Unit[] children = new Unit[5];
|
final Unit[] children = new Unit[5];
|
||||||
Arrays.setAll(children, (i) -> mock(Unit.class));
|
Arrays.setAll(children, (i) -> mock(Unit.class));
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user