Skip to content

Commit aeda936

Browse files
committed
adding integration tests
1 parent 5c44d2a commit aeda936

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

‎src/main/java/uk/co/caeldev/builder4test/EntityBuilder.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package uk.co.caeldev.builder4test;
22

3-
class EntityBuilder<K> {
3+
public class EntityBuilder<K> {
44

55
private final Lookup lookup;
66
private final Creator<K> creator;
@@ -14,12 +14,12 @@ static <T> EntityBuilder<T> entityBuilder(Creator<T> Creator) {
1414
return new EntityBuilder<>(Creator);
1515
}
1616

17-
<V> EntityBuilder<K> with(String fieldName, V value) {
17+
public <V> EntityBuilder<K> with(String fieldName, V value) {
1818
lookup.add(new Value<>(fieldName, value));
1919
return this;
2020
}
2121

22-
K get() {
22+
public K get() {
2323
creator.initializeLookup(lookup);
2424
return creator.build();
2525
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package integration;
2+
3+
import org.junit.jupiter.api.Test;
4+
import uk.co.caeldev.builder4test.Builder;
5+
import uk.co.caeldev.builder4test.Creator;
6+
import uk.co.caeldev.builder4test.impl.Pojo;
7+
8+
import static org.assertj.core.api.Assertions.assertThat;
9+
10+
public class BuilderIntegrationTest {
11+
12+
@Test
13+
public void shouldBuildPojo() {
14+
//When
15+
Pojo pojo = Builder.build().entity(getCreator()).get();
16+
17+
//Then
18+
assertThat(pojo.getName()).isEqualTo("Testname");
19+
assertThat(pojo.getValue()).isEqualTo("TestValue");
20+
}
21+
22+
@Test
23+
public void shouldBuildPojoOverridingValues() {
24+
//When
25+
Pojo pojo = Builder.build()
26+
.entity(getCreator())
27+
.with("name", "nameoverrideed")
28+
.with("value", "valueoverrided")
29+
.get();
30+
31+
//Then
32+
assertThat(pojo.getName()).isEqualTo("nameoverrideed");
33+
assertThat(pojo.getValue()).isEqualTo("valueoverrided");
34+
}
35+
36+
private Creator<Pojo> getCreator() {
37+
return new Creator<Pojo>() {
38+
@Override
39+
public Pojo build() {
40+
return new Pojo(lookup("name", "Testname"), lookup("value", "TestValue"));
41+
}
42+
};
43+
}
44+
}

0 commit comments

Comments
 (0)