Skip to content

Commit

Permalink
adding more description to the tests and more coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
caelcs committed Nov 23, 2018
1 parent f3bce8b commit d155ad4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package uk.co.caeldev.builder4test;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
Expand All @@ -15,6 +16,7 @@ public void setUp() {
}

@Test
@DisplayName("Should put and retrieve a value for a field")
public void shouldPutAValue() {
//Given
Field<String> field = new Field<>();
Expand All @@ -28,6 +30,7 @@ public void shouldPutAValue() {
}

@Test
@DisplayName("Should retrieve a value for a field")
public void shouldGetAValueWhenExists() {
//Given
Field<String> field = new Field<>();
Expand All @@ -43,6 +46,7 @@ public void shouldGetAValueWhenExists() {
}

@Test
@DisplayName("Should retrieve default values when there is no value for a field")
public void shouldGetDefaultValueWhenItDoesExists() {
//Given
Field<String> field = new Field<>();
Expand All @@ -55,6 +59,7 @@ public void shouldGetDefaultValueWhenItDoesExists() {
}

@Test
@DisplayName("Should retrieve null when there is null value for a field")
public void shouldGetNullWhenItHasBeenOverrideWithNull() {
//Given
Field<String> field = new Field<>();
Expand All @@ -70,6 +75,7 @@ public void shouldGetNullWhenItHasBeenOverrideWithNull() {
}

@Test
@DisplayName("Should retrieve null when there default is null")
public void shouldGetNullWhenThereIsNoValueAndDefaultValueIsNull() {
//Given
Field<String> field = new Field<>();
Expand All @@ -82,6 +88,7 @@ public void shouldGetNullWhenThereIsNoValueAndDefaultValueIsNull() {
}

@Test
@DisplayName("Should retrieve default value declared by using field constructor")
public void shouldGetDefaultWhenItUseFieldDefaultValue() {
//Given
Field<String> field = new Field<>("defaultValue");
Expand All @@ -94,6 +101,7 @@ public void shouldGetDefaultWhenItUseFieldDefaultValue() {
}

@Test
@DisplayName("Should retrieve null when there is no default value and no value for a field")
public void shouldGetNullWhenThereIsNoDefaultValue() {
//Given
Field<String> field = new Field<>();
Expand All @@ -106,6 +114,7 @@ public void shouldGetNullWhenThereIsNoDefaultValue() {
}

@Test
@DisplayName("Should override the default value set by field constructor by default value pass as argument ")
public void shouldIgnoreDefaultValueBeenSetAtFieldInstantiation() {
//Given
Field<String> field = new Field<>("defaultValue");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package uk.co.caeldev.builder4test;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import uk.co.caeldev.builder4test.impl.Pojo;
import uk.co.caeldev.builder4test.impl.PojoBuilder;
Expand All @@ -11,6 +12,7 @@
class ElementListBuilderTest {

@Test
@DisplayName("Should build different instances of ElementListBuilder")
public void shouldBuilderDifferentBuilders() {
//When
ElementListBuilder<Pojo> pojoListBuilder = ElementListBuilder.elementListBuilder(PojoBuilder.creator);
Expand All @@ -21,7 +23,8 @@ public void shouldBuilderDifferentBuilders() {
}

@Test
public void shouldBuildEmptyList() {
@DisplayName("Should build by default a list of one element where there is no size and elements definitions")
public void shouldBuildAListOfOneElement() {
//When
List<Pojo> pojos = ElementListBuilder.elementListBuilder(PojoBuilder.creator).get();

Expand All @@ -30,6 +33,7 @@ public void shouldBuildEmptyList() {
}

@Test
@DisplayName("Should build a list of one element when there is one element definition")
public void shouldBuildListWithOneElement() {
//When
List<Pojo> pojos = ElementListBuilder.elementListBuilder(PojoBuilder.creator)
Expand All @@ -48,6 +52,7 @@ public void shouldBuildListWithOneElement() {
}

@Test
@DisplayName("Should build a list of two elements when there is two element definitions")
public void shouldBuildListWithTwoElements() {
//When
List<Pojo> pojos = ElementListBuilder.elementListBuilder(PojoBuilder.creator)
Expand Down
24 changes: 24 additions & 0 deletions src/test/java/uk/co/caeldev/builder4test/RandomLookUpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.util.Optional;
Expand All @@ -13,6 +14,7 @@ class RandomLookUpTest {


@Test
@DisplayName("Should get different random values for each field")
public void shouldLookupARandomValue() {
//Given
Field<String> field = new Field<>();
Expand All @@ -30,6 +32,7 @@ public void shouldLookupARandomValue() {
}

@Test
@DisplayName("Should get random and constant values")
public void shouldLookupARandomValueAndConstantValue() {
//Given
Field<String> field1 = new Field<>();
Expand All @@ -50,6 +53,7 @@ public void shouldLookupARandomValueAndConstantValue() {
}

@Test
@DisplayName("Should retrieve the constant value when there is a random value has well")
public void shouldLookupConstantValueOverridesRandomValueForDoubleDefinition() {
//Given
Field<String> field1 = new Field<>();
Expand All @@ -65,6 +69,7 @@ public void shouldLookupConstantValueOverridesRandomValueForDoubleDefinition() {
}

@Test
@DisplayName("Should retrieve the default value when there is no definition for that field")
public void shouldLookupForDefaultValueWhenThereIsNoValue() {
//Given
Field<String> field1 = new Field<>();
Expand All @@ -78,6 +83,7 @@ public void shouldLookupForDefaultValueWhenThereIsNoValue() {
}

@Test
@DisplayName("Should retrieve null when there is a null entry for a field")
public void shouldLookupForNullWhenThereIsNullValueSet() {
//Given
Field<String> field1 = new Field<>();
Expand All @@ -91,6 +97,7 @@ public void shouldLookupForNullWhenThereIsNullValueSet() {
}

@Test
@DisplayName("Should retrieve empty when the value is empty for a field")
public void shouldLookupForEmptyWhenThereIsEmptyValueSet() {
//Given
Field<String> field1 = new Field<>();
Expand All @@ -102,4 +109,21 @@ public void shouldLookupForEmptyWhenThereIsEmptyValueSet() {
//Then
assertThat(result1).isEmpty();
}

@Test
@DisplayName("Should retrieve the value set by using put method for a field")
public void shouldLookupForValueInsertedByUsingPut() {
//Given
Field<String> field1 = new Field<>();
RandomLookUp lookUp = new RandomLookUp(Maps.newHashMap(), Maps.newHashMap());

//And
lookUp.put(field1, "");

//When
String result1 = lookUp.get(field1, "test");

//Then
assertThat(result1).isEmpty();
}
}

0 comments on commit d155ad4

Please sign in to comment.