Skip to content

Instantly share code, notes, and snippets.

View lovewithmind's full-sized avatar
🎯
Focusing

Loveneesh Singh lovewithmind

🎯
Focusing
View GitHub Profile
@lovewithmind
lovewithmind / PersonTestLombok.java
Last active June 12, 2021 09:11
Lombok builder
class PersonTest {
@Test
public void shouldReturnFalseForInCorrectEmail() {
Person person = PersonTestData.defaultBuilder()
.email("abc123")
.build();
boolean isValidEmail = person.isValidEmail();
assertFalse(isValidEmail);
}
@lovewithmind
lovewithmind / PersonBuilder.java
Last active June 14, 2021 17:59
Person data builder
class PersonTest {
@Test
public void shouldReturnFalseForInCorrectEmail() {
Person person = PersonBuilder.defaultBuilder()
.email("99999")
.build();
boolean isValidEmail = person.isValidEmail();
assertFalse(isValidEmail);
}
@lovewithmind
lovewithmind / PersonTest.java
Created June 12, 2021 08:09
Using utility class to build person
class PersonTest {
@Test
public void shouldReturnTrueForCorrectEmail() {
Person person = TestUtil.aPerson(
"John",
"john@gmail.com",
"888888",
"888888"
);
@lovewithmind
lovewithmind / PersonTest.java
Created June 12, 2021 07:51
Person data test
class PersonTest {
@Test
public void shouldReturnTrueForCorrectEmail() {
Person person = new Person(1,
"John",
"john@gmail.com",
"888888",
"888888",
null,
null);
@lovewithmind
lovewithmind / Address.java
Created June 12, 2021 07:31
Address data class
public class Address{
private final String addressLine1;
private final String AddressLine2;
private final Integer postalCode;
Address(final String addressLine1,
final String addressLine2,
final Integer postalCode) {
this.addressLine1 = addressLine1;
this.AddressLine2 = addressLine2;
@lovewithmind
lovewithmind / Person.java
Last active June 12, 2021 07:30
Person data class
public class Person {
private final Integer identificationNumber;
private final String name;
private final String email;
private final String phoneNumber;
private final String mobileNumber;
private final Address homeAddress;
private final Address officeAddress;
public Person(final Integer identificationNumber,
@Test
fun `should throw Exception for mono`(){
val monoError = Mono.error<Exception>(Exception())
StepVerifier.create(mono)
.expectError(Exception::class.java)
.verify()
}
@Test
fun `should consume thrown exception from flux`() {
@Test
fun `should throw exception while fetching person data`(){
val personService = PersonService()
assertThatThrownBy{
personService.getPerson("name")
}.isInstanceOf(PersonNotFound::class.java)
.hasMessage("No person found in the database")
}
@lovewithmind
lovewithmind / StepVerifier.kt
Last active May 7, 2020 21:06
Using StepVerifier to test async Publisher
@Test
fun `should return person data given name of the person`(){
val monoPerson = PersonManager.getProfile("PersonX")
val expectedResult = Person(name = "PersonX", age = 18)
StepVerifier.create(monoPerson)
.expectNext(expectedResult)
.verifyComplete()
}
@lovewithmind
lovewithmind / ReactiveBlockTestExample.kt
Last active May 5, 2020 19:49
This is an example of reactive test with block
@Test
fun `should return person data given name of the person`(){
val monoPerson = PersonManager.getProfile("PersonX")
val expectedResult = Person(name = "PersonX", age = 18)
assertThat(monoPerson.block()).isEqual(expectedResult)
}
@Test
fun `should return list of person data`(){
val fluxList = PersonManager.getAllProfile()