Skip to content

Instantly share code, notes, and snippets.

@sudarshan89
sudarshan89 / .block
Created October 26, 2020 00:31
roughViz Line Demo
license: mit
@sudarshan89
sudarshan89 / .block
Last active October 24, 2020 23:19
roughViz Line Demo
license: mit
@sudarshan89
sudarshan89 / MuleInvokeComponent.xml
Last active July 5, 2018 08:15
Mule invoke component passing parameters example
...
<flow name="greetingFlow" >
...
<invoke object-ref="greetingService" method="sayHello"
methodArguments="#[message.inboundProperties.'http.query.params'.name]"
doc:name="Invoke Component"/>
</flow>
Stock stock = spy(Stock.class);
doReturn(100.00).when(stock).getPrice(); // Mock implementation
doReturn(200).when(stock).getQuantity(); // Mock implementation
// All other method call will use the real implementations
@sudarshan89
sudarshan89 / UseMock.java
Created June 26, 2018 07:58
Using a mock for partial mocking
Stock stock = mock(Stock.class);
when(stock.getPrice()).thenReturn(100.00); // Mock implementation
when(stock.getQuantity()).thenReturn(200); // Mock implementation
when(stock.getValue()).thenCallRealMethod(); // Real implementation
@sudarshan89
sudarshan89 / Stock.java
Created June 26, 2018 07:47
Sample class for partial mocking post
public class Stock {
private final double price;
private final int quantity;
Stock(double price, int quantity) {
this.price = price;
this.quantity = quantity;
}
public double getPrice() {
@sudarshan89
sudarshan89 / Book.java
Last active June 9, 2018 22:31
Modelling the "when" in your code - lendBook events snippet
public void lend(bookId, memberId) {
{
// check preconditions and other logic
availableCopies - ;
domainEventBus.raise(new BookIssuedEvent(bookId, memberId));
}
}
@sudarshan89
sudarshan89 / IssueBook.java
Created June 9, 2018 22:28
Modelling the "when" in your code - issueBook events snippet
issueBook(IssueBooksCommand bookIssueCommand) {
Book book = bookRepository.geBookWithUid(bookId);
book.lend(member.getId(), booksAlreadyWithMember);
bookRepository.lend(book);
}
@sudarshan89
sudarshan89 / IssueBook.java
Last active June 9, 2018 22:27
Modelling the "when" in your code - issueBook naive snippet
issueBook(IssueBooksCommand bookIssueCommand) {
Book book = bookRepository.geBookWithUid(bookId);
book.lend(member.getId(), booksAlreadyWithMember);
bookRepository.lend(book);
// Action performed after a book has been issued
emailService.notifyMember(member, book);
// Action performed after a book has been issued
recordIntoBookLending(member, book);
}
#%RAML 1.0
title: Sanford Events
baseUri: http://api.samplehost.com/{version}
version: v1
types:
EventNotification:
type: object
properties:
eventId:
type: string