| 37571 |
amit |
1 |
package com.spice.profitmandi.web.offercircular;
|
|
|
2 |
|
|
|
3 |
import static org.junit.Assert.assertEquals;
|
|
|
4 |
|
|
|
5 |
import java.util.ArrayList;
|
|
|
6 |
import java.util.List;
|
|
|
7 |
|
|
|
8 |
import org.junit.Test;
|
|
|
9 |
|
|
|
10 |
/**
|
|
|
11 |
* Guards the EMI-tenure cell.
|
|
|
12 |
*
|
|
|
13 |
* The scheme decides what a partner may promise at the counter - no-cost EMI costs the
|
|
|
14 |
* customer nothing, low-cost EMI does not - so a lost or invented marker is a money
|
|
|
15 |
* error, not a display one.
|
|
|
16 |
*
|
|
|
17 |
* The rule the parser implements: a marker FOLLOWS the group of months it applies to.
|
|
|
18 |
*/
|
|
|
19 |
public class TenureParserTest {
|
|
|
20 |
|
|
|
21 |
private static String parse(String cell) {
|
|
|
22 |
List<String> out = new ArrayList<>();
|
|
|
23 |
for (TenureParser.Tenure t : TenureParser.parse(cell).getTenures()) {
|
|
|
24 |
out.add(t.getMonths() + ":" + t.getScheme());
|
|
|
25 |
}
|
|
|
26 |
return String.join(" ", out);
|
|
|
27 |
}
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* The regression this test exists for. "M" is the month UNIT; it used to flush the
|
|
|
31 |
* pending months as NONE, so "3m,6m LCE" tokenised to 3, M, 6, M, LCE and the LCE
|
|
|
32 |
* arrived with nothing left to attach to. 22 Sep'26 offers lost their scheme this way.
|
|
|
33 |
*/
|
|
|
34 |
@Test
|
|
|
35 |
public void monthSuffixDoesNotSwallowTheMarker() {
|
|
|
36 |
assertEquals("3:LCE 6:LCE", parse("3m,6m LCE"));
|
|
|
37 |
assertEquals("6:LCE 9:LCE", parse("6m,9m LCE"));
|
|
|
38 |
assertEquals("3:LCE 6:LCE", parse("3m & 6m LCE"));
|
|
|
39 |
assertEquals("6:LCE", parse("6m LCE"));
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
/** Two groups, two markers, month units throughout - both must land. */
|
|
|
43 |
@Test
|
|
|
44 |
public void keepsEachGroupWithItsOwnMarker() {
|
|
|
45 |
assertEquals("3:NCE 6:LCE", parse("3M (NCE), 6M & Above LCE"));
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
/** The documented shape: the marker follows its group. */
|
|
|
49 |
@Test
|
|
|
50 |
public void markerFollowsItsGroup() {
|
|
|
51 |
assertEquals("3:NCE 6:NCE 9:LCE 12:LCE 18:LCE 24:LCE",
|
|
|
52 |
parse("3,6 NCE 9,12,18,24 LCE"));
|
|
|
53 |
assertEquals("6:NCE 9:LCE 12:LCE 18:LCE 24:LCE",
|
|
|
54 |
parse("6(NCE),9,12,18,24(LCE)"));
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
/** Months with no marker anywhere still bank as NONE - unchanged by the fix. */
|
|
|
58 |
@Test
|
|
|
59 |
public void unmarkedMonthsStayUnscheme() {
|
|
|
60 |
assertEquals("3:NONE 6:NONE", parse("3M, 6M"));
|
|
|
61 |
assertEquals("3:NONE 6:NONE", parse("3,6"));
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
/** PDF line-wrap artefacts: "L CE" is one token split across a break. */
|
|
|
65 |
@Test
|
|
|
66 |
public void repairsLineWrappedMarkers() {
|
|
|
67 |
assertEquals("3:LCE 6:LCE", parse("3,6 L CE"));
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
/** A cell naming only a payment mode has no tenures to give. */
|
|
|
71 |
@Test
|
|
|
72 |
public void modeOnlyCellYieldsNothing() {
|
|
|
73 |
assertEquals("", parse("NA"));
|
|
|
74 |
assertEquals("", parse("Full Swipe"));
|
|
|
75 |
}
|
|
|
76 |
}
|