package com.foxx.androidcast.network;

/*********************************************************************
 * CastSessionGateTest.java
 * Created at: Sat 16 May 2026 18:50:36 +0200
 * Updated at: Wed 20 May 2026 15:17:13 +0200 by Anton Afanasyeu <a.afanasieff@gmail.com>
 * Commit: 5d8e82d2e60a21fff3138d2a394ee4e8b4c6dcb8
 * class CastSessionGateTest
 * Contributors:
 *    - Anton Afanasyeu <a.afanasieff@gmail.com> (2 commits, 56 lines)
 *    - Cursor Agent (project assistant)
 * Digest: SHA256	7081efd30deeb38512a739c7208dfc5fb9bc1b93def217a779db76c01f68293b
**********************************************************************/
import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

public class CastSessionGateTest {

    @Test
    public void bindsFirstNonZeroSession() {
        CastSessionGate gate = new CastSessionGate();
        CastProtoHeader first = new CastProtoHeader();
        first.sessionId = 42;
        assertTrue(gate.accept(first));
        assertEquals(42, gate.getBoundSessionId());

        CastProtoHeader stale = new CastProtoHeader();
        stale.sessionId = 99;
        assertFalse(gate.accept(stale));

        CastProtoHeader same = new CastProtoHeader();
        same.sessionId = 42;
        assertTrue(gate.accept(same));
    }

    @Test
    public void zeroSessionAlwaysAccepted() {
        CastSessionGate gate = new CastSessionGate();
        CastProtoHeader zero = new CastProtoHeader();
        zero.sessionId = 0;
        assertTrue(gate.accept(zero));
        assertFalse(gate.isBound());
    }

    @Test
    public void resetAllowsRebind() {
        CastSessionGate gate = new CastSessionGate();
        CastProtoHeader a = new CastProtoHeader();
        a.sessionId = 1;
        gate.accept(a);
        gate.reset();
        CastProtoHeader b = new CastProtoHeader();
        b.sessionId = 2;
        assertTrue(gate.accept(b));
        assertEquals(2, gate.getBoundSessionId());
    }
}
