Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

package com.spice.profitmandi.web.offercircular;

import static org.junit.Assert.assertEquals;

import java.util.ArrayList;
import java.util.List;

import org.junit.Test;

/**
 * Guards the EMI-tenure cell.
 *
 * The scheme decides what a partner may promise at the counter - no-cost EMI costs the
 * customer nothing, low-cost EMI does not - so a lost or invented marker is a money
 * error, not a display one.
 *
 * The rule the parser implements: a marker FOLLOWS the group of months it applies to.
 */
public class TenureParserTest {

    private static String parse(String cell) {
        List<String> out = new ArrayList<>();
        for (TenureParser.Tenure t : TenureParser.parse(cell).getTenures()) {
            out.add(t.getMonths() + ":" + t.getScheme());
        }
        return String.join(" ", out);
    }

    /**
     * The regression this test exists for. "M" is the month UNIT; it used to flush the
     * pending months as NONE, so "3m,6m LCE" tokenised to 3, M, 6, M, LCE and the LCE
     * arrived with nothing left to attach to. 22 Sep'26 offers lost their scheme this way.
     */
    @Test
    public void monthSuffixDoesNotSwallowTheMarker() {
        assertEquals("3:LCE 6:LCE", parse("3m,6m LCE"));
        assertEquals("6:LCE 9:LCE", parse("6m,9m LCE"));
        assertEquals("3:LCE 6:LCE", parse("3m & 6m LCE"));
        assertEquals("6:LCE", parse("6m LCE"));
    }

    /** Two groups, two markers, month units throughout - both must land. */
    @Test
    public void keepsEachGroupWithItsOwnMarker() {
        assertEquals("3:NCE 6:LCE", parse("3M (NCE), 6M & Above LCE"));
    }

    /** The documented shape: the marker follows its group. */
    @Test
    public void markerFollowsItsGroup() {
        assertEquals("3:NCE 6:NCE 9:LCE 12:LCE 18:LCE 24:LCE",
                parse("3,6 NCE 9,12,18,24 LCE"));
        assertEquals("6:NCE 9:LCE 12:LCE 18:LCE 24:LCE",
                parse("6(NCE),9,12,18,24(LCE)"));
    }

    /** Months with no marker anywhere still bank as NONE - unchanged by the fix. */
    @Test
    public void unmarkedMonthsStayUnscheme() {
        assertEquals("3:NONE 6:NONE", parse("3M, 6M"));
        assertEquals("3:NONE 6:NONE", parse("3,6"));
    }

    /** PDF line-wrap artefacts: "L CE" is one token split across a break. */
    @Test
    public void repairsLineWrappedMarkers() {
        assertEquals("3:LCE 6:LCE", parse("3,6 L CE"));
    }

    /** A cell naming only a payment mode has no tenures to give. */
    @Test
    public void modeOnlyCellYieldsNothing() {
        assertEquals("", parse("NA"));
        assertEquals("", parse("Full Swipe"));
    }
}