name:
src/test/java/io/protobase/f7/formulas/text/CONCATTest.java
-rw-r--r--
2308
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 CONCATTest extends TestFormula {
15 @Test
16 public void testApply() {
17 assertThat(CONCAT.SELF.apply(null, 10.0, 10.0)).isEqualTo("1010");
18 assertThat(CONCAT.SELF.apply(null, "One", "Two")).isEqualTo("OneTwo");
19 assertThat(CONCAT.SELF.apply(null, 44182.1, "Two")).isEqualTo("44182.1Two");
20 assertThat(CONCAT.SELF.apply(null, true, false)).isEqualTo("TRUEFALSE");
21 assertThat(CONCAT.SELF.apply(null, "", "")).isEqualTo("");
22 }
23
24 @Test
25 public void testApply_grid() {
26 assertThat(CONCAT.SELF.apply(null,
27 Grid.builder().add(0, 0, "Hello").add(0, 1, "I am not invited to the concat party...").build(),
28 Grid.builder().add(0, 0, "There").add(0, 1, "Neither am I....").build()
29 )).isEqualTo("HelloThere");
30 assertThat(CONCAT.SELF.apply(null,
31 Grid.builder().add(0, 0, "Hello").build(),
32 Grid.builder().add(0, 0, "There").build()
33 )).isEqualTo("HelloThere");
34 }
35
36 @Test
37 public void test_lookup() {
38 CONCAT F = new CONCAT(lookup, collateralLookup);
39 when(collateralLookup.apply(A1, M22_RANGE)).thenReturn("One");
40 when(collateralLookup.apply(A1, G19_RANGE)).thenReturn("Two");
41 assertThat(F.apply(A1, M22_RANGE, G19_RANGE)).isEqualTo("OneTwo");
42 verify(collateralLookup).apply(A1, M22_RANGE);
43 verify(collateralLookup).apply(A1, G19_RANGE);
44 verifyNoMoreInteractions(collateralLookup);
45 }
46
47 @Test
48 public void testApply_errorsPassThrough() {
49 assertThat(CONCAT.SELF.apply(null, "One", new ValueException())).isEqualTo(new ValueException());
50 assertThat(CONCAT.SELF.apply(null, new ValueException(), "Two")).isEqualTo(new ValueException());
51 }
52
53 @Test
54 public void testApply_argumentsMismatch() {
55 assertThat(CONCAT.SELF.apply(null, "Too few")).isEqualTo(new NAException());
56 assertThat(CONCAT.SELF.apply(null, "A", "B", "Too many")).isEqualTo(new NAException());
57 }
58}