Tags
In My Opinion
My opinion in nutshell
Spring XML Autowiring
What is Autowiring ? It allow us to automatically wiring interfaces to the write implementation and help us to reduce some manual coding. How it works? To auto wire below service class, we can use different types of auto wiring customer service public class CustomerServiceImplementation implements CustomerService { private CustomerRepository customerRepository; public CustomerServiceImplementation(CustomerRepository customerRepository) { this.customerRepository = customerRepository; } @Override public List<Customer> findAll() { return customerRepository.findAll(); } } byType it allow beans to auto wired if there is only one type of beans exist in the container.
setter injection vs constructor injection in Spring
What is setter injection? In spring you can inject the concrete dependencies with setters. Example applicationContext.xml <bean name="customerRepo" class="com.inadram.repo.hibernateRepositoryImplementation"/> <bean name="customerService" class="com.inadram.service.CustomerServiceImplementation"> <property name="customerRepository" ref="customerRepo"/> </bean> Therefore your customer service class can accept customer repository as an injection with setters customer service public class CustomerServiceImplementation implements CustomerService { private CustomerRepository customerRepository; public void setCustomerRepository(CustomerRepository customerRepository) { this.customerRepository = customerRepository; } @Override public List<Customer> findAll() { return customerRepository.
Spring example?
We have a simple interface driven application below that we tries to move it to spring framework. Old Code Customer DTO Customer Data Transfer Object contains firstName and lastName variables and their setters and getters. public class Customer { private String firstName; private String lastName; public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.
What is spring?
Spring is a framework to reduce Enterprise Java Development complexity. it is Plain Old Java Object based which means that any code you written in spring can write without it as well ! It is a lightweight and unobtrusive framework in compare with older J2EE if you using it in a right way. It support AOP framework (Aspect oriented programming) Structure The architecture of spring is based on design patterns which can help us to use best practices without having too much in dept knowledge about them.
Sinon mock by example
What is sinon mock ? Mocks are fake methods with pre programmed behaviour and expectation. it replacing the system under test object with a test specific object to verify that it has been used correctly or not.(xUnit test pattern) When I should use sinon mock ? Mock should being used for method under the tests. you can used mock to check the unit under test get used as your expectation or not.
sinon stub by example
What is Stub ? “stubs replace the real object with a test specific object that feed the desire indirect inputs into the system under test”. (xUnit test pattern) stubs function has pre-programmed behaviour. they support all the spies functionalities as well. When to use Stub? stubs do not proxy the original method , they have an API for controlling the behaviour . Use stubs when you want to control the method behaviour, for instance force a method to throwing an exception to check the error handling functionalities.
sinon spy by example
What is Sinon Spy ? According to the xUnit patterns definition, test spy is designed to act as an observation point by recording the method calls made to it by the SUT (system under test) as it is exercised. How Sinon Spy works? You need to make test spy first to allow it observe the execution of your desire method and then assert your expectation with actual calls. Examples of the Sinon Spy I am trying to write different test cases for code below (order by easy to hard).
Ruby fundamental by example – everything is an object
Last week, I have attended a ruby cucumber training course which was running by Chris Parson and I have found it really useful. Some basic definition Class: A template that describes an object. It is a type of object and it defines methods. Variable: a container for a value and it hold a reference to an object. Method: block of code that expose a behavior and it manipulates the objects.
setup sinon with jsTestDriver by example
What is sinon ? it help us to write stand alone test cases in javascript. it help us to spy, stub or mock methods or objects. How to get it ? you can download the library from sinonjs.org. How to set it up? All you need to do is put the downloaded file in your project and reference to it. What is JsTestDriver? it is test framework that help you to run unit test.
String functions in JavaScript by example
You can capture the substring that has your desired pattern on a large string with expressions in JavaScript. Some key point \w will match with any word character \d will match with any decimal digit [] Is used to match with set of characteristics {0} Is used to quantify a match i.e. {3} will match the first three characters. () Make capturing group \ will escape special character Match all with groups var someText = "this is some <italic> important </italic> html text with some numbers such as 1, 3 and 6"; var expression = /<italic> (.
←
Newer Posts
Older Posts
→