Skip to content

Commit

Permalink
Used Mockito for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
SherifWaly committed Mar 10, 2017
1 parent f410001 commit 142ef59
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/test/java/com/amihaiemil/camel/CachedYamlLineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.mockito.Mockito;

/**
* Unit Tests for {@link CachedYamlLine}.
Expand All @@ -56,24 +57,26 @@ public void knowsNumber() {
*/
@Test
public void cachesTrimmedValue() {
YamlLine line = new CachedYamlLine(
new RtYamlLine(" this line ", 12)
);
String cached = line.trimmed();
MatcherAssert.assertThat(cached, Matchers.is("this line"));

//Same String object is returned.
MatcherAssert.assertThat(cached == line.trimmed(), Matchers.is(true));
YamlLine mock = Mockito.mock(YamlLine.class);
Mockito.when(mock.trimmed())
.thenReturn("this line")
.thenThrow(new RuntimeException());
YamlLine line = new CachedYamlLine(mock);
MatcherAssert.assertThat(line.trimmed(), Matchers.is("this line"));
MatcherAssert.assertThat(line.trimmed(), Matchers.is("this line"));
}

/**
* CachedIndentedLine caches indentation value and doesn't recalculate it.
*/
@Test
public void cachesIndentationValue() {
YamlLine line = new CachedYamlLine(
new RtYamlLine(" this line", 12)
);
MatcherAssert.assertThat(line.indentation(), Matchers.is(12));
YamlLine mock = Mockito.mock(YamlLine.class);
Mockito.when(mock.indentation())
.thenReturn(12)
.thenThrow(new RuntimeException());
YamlLine cachedLine = new CachedYamlLine(mock);
MatcherAssert.assertThat(cachedLine.indentation(), Matchers.is(12));
MatcherAssert.assertThat(cachedLine.indentation(), Matchers.is(12));
}
}

0 comments on commit 142ef59

Please sign in to comment.