name:
src/test/java/io/protobase/f7/formulas/text/TTest.java
-rw-r--r--
1601
1package io.protobase.f7.formulas.text;
2
3import io.protobase.f7.errors.NAException;
4import io.protobase.f7.errors.ValueException;
5import io.protobase.f7.models.Grid;
6import io.protobase.f7.testutils.TestFormula;
7import org.junit.Test;
8
9import static com.google.common.truth.Truth.assertThat;
10import static org.mockito.Mockito.verify;
11import static org.mockito.Mockito.verifyNoMoreInteractions;
12import static org.mockito.Mockito.when;
13
14public class TTest extends TestFormula {
15 @Test
16 public void testApply() {
17 assertThat(T.SELF.apply(null, 10.0)).isEqualTo("");
18 assertThat(T.SELF.apply(null, true)).isEqualTo("");
19 assertThat(T.SELF.apply(null, false)).isEqualTo("");
20 assertThat(T.SELF.apply(null, "ReturnMe")).isEqualTo("ReturnMe");
21 }
22
23 @Test
24 public void testApply_grid() {
25 assertThat(T.SELF.apply(null,
26 Grid.builder().add(0, 0, "Hello").add(0, 1, "I am ignored.").build()
27 )).isEqualTo("Hello");
28 }
29
30 @Test
31 public void test_lookup() {
32 T F = new T(lookup, collateralLookup);
33 when(collateralLookup.apply(A1, M22_RANGE)).thenReturn("Hello");
34 assertThat(F.apply(A1, M22_RANGE)).isEqualTo("Hello");
35 verify(collateralLookup).apply(A1, M22_RANGE);
36 verifyNoMoreInteractions(collateralLookup);
37 }
38
39 @Test
40 public void testApply_errorsPassThrough() {
41 assertThat(T.SELF.apply(null, new ValueException())).isEqualTo(new ValueException());
42 }
43
44 @Test
45 public void testApply_argumentsMismatch() {
46 assertThat(T.SELF.apply(null)).isEqualTo(new NAException());
47 assertThat(T.SELF.apply(null, "A", "B")).isEqualTo(new NAException());
48 }
49}