    @Test
    public void testOverwritingWithFarIvIndex() {

        final byte[] data = MeshParserUtils.toByteArray("0102EE6C0EFF5298ECFF000000025E5AA7B268B5E044");
        final SecureNetworkBeacon snb = new SecureNetworkBeacon(data);
        final IvIndex ivIndex = new IvIndex(0, false, Calendar.getInstance());
        final Calendar currentTime = Calendar.getInstance();

        final Calendar ninetySixHoursAgo = (Calendar) currentTime.clone();
        ninetySixHoursAgo.add(Calendar.HOUR, -96);
        final Calendar almostNinetySixHoursAgo = (Calendar) ninetySixHoursAgo.clone();
        almostNinetySixHoursAgo.add(Calendar.SECOND, 10);
        final Calendar moreThanNinetySixHoursAgo = (Calendar) ninetySixHoursAgo.clone();
        moreThanNinetySixHoursAgo.add(Calendar.SECOND, -10);

        final Calendar twoHundredEightyEightHoursAgo = (Calendar) currentTime.clone();
        twoHundredEightyEightHoursAgo.add(Calendar.HOUR, -288);
        final Calendar almostTwoHundredEightyEightHoursAgo = (Calendar) twoHundredEightyEightHoursAgo.clone();
        almostTwoHundredEightyEightHoursAgo.add(Calendar.SECOND, 10);
        final Calendar moreThanTwoHundredEightyEightHoursAgo = (Calendar) twoHundredEightyEightHoursAgo.clone();
        moreThanTwoHundredEightyEightHoursAgo.add(Calendar.SECOND, -10);

        // 3 * 96 = 288 hours are required to pass since last IV Index update
        // for the IV Index to change from 0 (normal operation) to 2 (update active).
        // The following tests check if SNB cannot be updated before that.
        final boolean result0 = snb.canOverwrite(ivIndex, almostNinetySixHoursAgo,
                false, false, false);

        final boolean result1 = snb.canOverwrite(ivIndex, ninetySixHoursAgo,
                false, false, false);

        final boolean result2 = snb.canOverwrite(ivIndex, moreThanNinetySixHoursAgo,
                false, false, false);

        final boolean result3 = snb.canOverwrite(ivIndex, almostTwoHundredEightyEightHoursAgo,
                false, false, false);

        // 3 * 96 = 288 hours have passed. IV Index can be updated
        // from 0 (normal operation) to 2 (update active) using IV Recovery
        // procedure.
        final boolean result4 = snb.canOverwrite(ivIndex, twoHundredEightyEightHoursAgo,
                false, false, false);

        // Even more time has passed.
        final boolean result5 = snb.canOverwrite(ivIndex, moreThanTwoHundredEightyEightHoursAgo,
                false, false, false);

        assertFalse(result0);
        assertFalse(result1);
        assertFalse(result2);
        assertFalse(result3);
        assertTrue(result4);
        assertTrue(result5);
    }