<commit_before>/**
 * Copyright (c) 2010-2020 Contributors to the openHAB project
 *
 * See the NOTICE file(s) distributed with this work for additional
 * information.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0
 *
 * SPDX-License-Identifier: EPL-2.0
 */
package org.openhab.binding.danfossairunit.internal;

import static org.junit.jupiter.api.Assertions.*;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.jupiter.api.Test;
import org.openhab.core.library.types.OnOffType;

/**
 * @author <NAME> - Initial contribution
 */
@NonNullByDefault
public class ValueCacheTest {

    @Test
    public void updateValueNotInCache() {
        ValueCache valueCache = new ValueCache(10000);
        assertTrue(valueCache.updateValue("channel", OnOffType.ON));
    }

    @Test
    public void updateValueInCacheUnchangedWithinCacheDuration() {
        ValueCache valueCache = new ValueCache(10000);
        assertTrue(valueCache.updateValue("channel", OnOffType.ON));
        assertFalse(valueCache.updateValue("channel", OnOffType.ON));
    }

    @Test
    public void updateValueInCacheChangedWithinCacheDuration() {
        ValueCache valueCache = new ValueCache(10000);
        assertTrue(valueCache.updateValue("channel", OnOffType.ON));
        assertTrue(valueCache.updateValue("channel", OnOffType.OFF));
    }

    @Test
    public void updateValueInCacheUnchangedButCacheDurationExpired() throws InterruptedException {
        ValueCache valueCache = new ValueCache(1);
        assertTrue(valueCache.updateValue("channel", OnOffType.ON));
        Thread.sleep(2);
        assertTrue(valueCache.updateValue("channel", OnOffType.ON));
    }

    @Test
    public void updateValueMultipleCacheUpdatesButNotReportedAsToUpdate() throws InterruptedException {
        ValueCache valueCache = new ValueCache(60);
        assertTrue(valueCache.updateValue("channel", OnOffType.ON));
        Thread.sleep(30);
        assertFalse(valueCache.updateValue("channel", OnOffType.ON));
        Thread.sleep(35);
        assertTrue(valueCache.updateValue("channel", OnOffType.ON));
    }
}
<commit_msg>[danfossairunit] Try to make tests more stable (#9473)<commit_after>/**
 * Copyright (c) 2010-2020 Contributors to the openHAB project
 *
 * See the NOTICE file(s) distributed with this work for additional
 * information.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License 2.0 which is available at
 * http://www.eclipse.org/legal/epl-2.0
 *
 * SPDX-License-Identifier: EPL-2.0
 */
package org.openhab.binding.danfossairunit.internal;

import static org.junit.jupiter.api.Assertions.*;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.junit.jupiter.api.Test;
import org.openhab.core.library.types.OnOffType;
import org.openhab.core.test.java.JavaTest;

/**
 * @author <NAME> - Initial contribution
 */
@NonNullByDefault
public class ValueCacheTest extends JavaTest {

    @Test
    public void updateValueNotInCache() {
        ValueCache valueCache = new ValueCache(10000);
        assertTrue(valueCache.updateValue("channel", OnOffType.ON));
    }

    @Test
    public void updateValueInCacheUnchangedWithinCacheDuration() {
        ValueCache valueCache = new ValueCache(10000);
        assertTrue(valueCache.updateValue("channel", OnOffType.ON));
        assertFalse(valueCache.updateValue("channel", OnOffType.ON));
    }

    @Test
    public void updateValueInCacheChangedWithinCacheDuration() {
        ValueCache valueCache = new ValueCache(10000);
        assertTrue(valueCache.updateValue("channel", OnOffType.ON));
        assertTrue(valueCache.updateValue("channel", OnOffType.OFF));
    }

    @Test
    public void updateValueInCacheUnchangedButCacheDurationExpired() {
        ValueCache valueCache = new ValueCache(1);
        assertTrue(valueCache.updateValue("channel", OnOffType.ON));
        waitForAssert(() -> assertTrue(valueCache.updateValue("channel", OnOffType.ON)));
    }

    @Test
    public void updateValueMultipleCacheUpdatesButNotReportedAsToUpdate() {
        ValueCache valueCache = new ValueCache(100);
        assertTrue(valueCache.updateValue("channel", OnOffType.ON));
        waitForAssert(() -> assertFalse(valueCache.updateValue("channel", OnOffType.ON)));
        waitForAssert(() -> assertTrue(valueCache.updateValue("channel", OnOffType.ON)));
    }
}

{'fraction_non_alphanumeric': 0.10836459942617524, 'fraction_numerical': 0.016331935555065107, 'mean_word_length': 4.046770601336303, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1095942', 'n_tokens_mistral': 1309, 'n_tokens_neox': 1262, 'n_words': 269}