Introduction to Singleton Pattern Design pattern in a simple meaning, is a way to design reusable object-oriented code. We can think of ways to design our classes, interfaces, enums and their members so that the code is reusable but flexible. There are 23 most important design patterns, pioneered by the book Design Patterns: Elements of…
Installing Gradle Build Tool manually Until now, we let Idea handle all the gradle setup things, and maybe we should do this. Anyway, we should know that we can handle all these ourselves without the help from IDE’s. Note that to install Gradle we must have Java JDK pre-installed. Then go to this link: https://gradle.org/releases/…
Introduction to Gradle Build Tool Because our examples here are very simple, our code does not have any external dependencies, our tests’s dependencies are all downloaded to our project manually. But in real world, the coding process and test process are executed a lot of times. The tests would be run times after times. Our…
Installing Mockito framework The Mockito framework can be downloaded at maven: https://repo1.maven.org/maven2/org/mockito/mockito-core/3.11.2/mockito-core-3.11.2.jar Because Mockito has three dependencies, we also download three other libraries. The Byte Buddy: https://repo1.maven.org/maven2/net/bytebuddy/byte-buddy/1.11.5/byte-buddy-1.11.5.jar The Byte Buddy Agent: https://repo1.maven.org/maven2/net/bytebuddy/byte-buddy-agent/1.11.5/byte-buddy-agent-1.11.5.jar And the Objenesis library: https://repo1.maven.org/maven2/org/objenesis/objenesis/3.2/objenesis-3.2.jar Download all these files and copy to the lib folder in our project (the same folder with the…
Introduction to Test Driven Development Suppose that we want to test a class, MyCalculator. That class will have, for now, a constructor that receives an int. This value will be a variable of the MyCalculator class. The the class has: – mul method: receive an int parameter and modify MyCalculator’s variable to the multiplication of…
JUnit Basics In this section we will cover some basics of JUnit. In main package we still use the MySum.java: @DisplayName We add this annotation to create a custom name for the class or the method in our test: Run the test and we can see the change in the Test Results page. assertAll In…
Introduction to Java Unit Test Unit test is the testing of an individual component of the application. It is the first level of code testing. The purpose of unit test is to validate each individual code components with its performance. In Java, we almost use JUnit framework for unit test. The first thing we need…
Introduction to Dependency Injection Dependency Injection (or DI) is the injection of dependencies when they are required instead of initialization of dependencies inside the clients. We reuse the code in the previous example. The abtract class Employee: The TeamLeader.java: Now look at the addEmployee() method. The Employee object is passed (injected) to the method at…
Introduction to Design Principles Design principles are general guidelines that were proven good coding practices. They can be applied to almost all programming languages, not just Java. The most famous of all are: – Single Responsibility Principle (S) – Open-Closed Principle (O) – Liskov Substitution Principle (L) – Interface Segregation Principle (I) – Dependency Inversion…
Java Test for JDBC Don’t try to hack or to do something unusual, this is just some basic Java tests for JDBC, to see what we learned until now. Please try to finish these tests without using an IDE. After choosing your options (radio buttons) please press Check button to see the result. Note that…