<commit_before>package com.oneandone.snmpman.configuration.modifier;

import com.oneandone.snmpman.configuration.type.ModifierProperties;
import org.snmp4j.smi.Counter32;
import org.snmp4j.smi.OID;
import org.snmp4j.smi.OctetString;
import org.snmp4j.smi.Variable;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import java.util.HashMap;
import java.util.Map;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;

public class CommunityIndexCounter32ModifierTest {
    private ModifierProperties modifierProperties;
    private long context1;
    private long contextValue1;
    private long context2;
    private long contextValue2;
    private final String oid = "1.3.6.1.2.1.17.2.4.0";

    @BeforeTest
    private void setUp() throws Exception {
        context1 = 20;
        contextValue1 = 150;
        context2 = 9;
        contextValue2 = 120;
        modifierProperties = new ModifierProperties();
        modifierProperties.put(context1, contextValue1);
        modifierProperties.put(context2, contextValue2);
    }

    @Test
    public void testInit() throws Exception {
        final CommunityIndexCounter32Modifier modifier = new CommunityIndexCounter32Modifier();
        modifier.init(modifierProperties);

        final Map<Long, Long> communityIndexValues = modifier.getCommunityContextMapping();
        assertEquals(communityIndexValues.size(), 2);
        assertTrue(communityIndexValues.containsKey(context1) && communityIndexValues.containsValue(contextValue1));
        assertTrue(communityIndexValues.containsKey(context2) && communityIndexValues.containsValue(contextValue2));

        // unchanged
        modifierProperties.put("maximum", new HashMap<String, Long>() {{
            put("1.3.6", 172L);
        }});
        final CommunityIndexCounter32Modifier modifier2 = new CommunityIndexCounter32Modifier();
        modifier2.init(modifierProperties);

        final Map<Long, Long> communityIndexValues2 = modifier.getCommunityContextMapping();
        assertEquals(communityIndexValues2.size(), 2);
        assertTrue(communityIndexValues2.containsKey(context1) && communityIndexValues2.containsValue(contextValue1));
        assertTrue(communityIndexValues2.containsKey(context2) && communityIndexValues2.containsValue(contextValue2));
    }

    @Test
    public void testModify() throws Exception {
        final CommunityIndexCounter32Modifier modifier = new CommunityIndexCounter32Modifier();
        modifier.init(modifierProperties);

        final Counter32 counter32 = new Counter32(contextValue1);
        assertEquals(counter32.getValue(), contextValue1);

        final Counter32 modifiedVariable = modifier.modify(counter32);
        assertEquals(modifiedVariable.getValue(), contextValue1);

        final Counter32 modifiedVariable2 = modifier.modify(null);
        assertEquals(modifiedVariable2, new Counter32(0L));
    }

    @Test
    public void testGetVariableBindings() throws Exception {
        final CommunityIndexCounter32Modifier modifier = new CommunityIndexCounter32Modifier();
        modifier.init(modifierProperties);<commit_msg>Get rid of one non-static initializer<commit_after>package com.oneandone.snmpman.configuration.modifier;

import com.oneandone.snmpman.configuration.type.ModifierProperties;
import org.snmp4j.smi.Counter32;
import org.snmp4j.smi.OID;
import org.snmp4j.smi.OctetString;
import org.snmp4j.smi.Variable;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;

public class CommunityIndexCounter32ModifierTest {
    private ModifierProperties modifierProperties;
    private long context1;
    private long contextValue1;
    private long context2;
    private long contextValue2;
    private final String oid = "1.3.6.1.2.1.17.2.4.0";

    @BeforeTest
    private void setUp() throws Exception {
        context1 = 20;
        contextValue1 = 150;
        context2 = 9;
        contextValue2 = 120;
        modifierProperties = new ModifierProperties();
        modifierProperties.put(context1, contextValue1);
        modifierProperties.put(context2, contextValue2);
    }

    @Test
    public void testInit() throws Exception {
        final CommunityIndexCounter32Modifier modifier = new CommunityIndexCounter32Modifier();
        modifier.init(modifierProperties);

        final Map<Long, Long> communityIndexValues = modifier.getCommunityContextMapping();
        assertEquals(communityIndexValues.size(), 2);
        assertTrue(communityIndexValues.containsKey(context1) && communityIndexValues.containsValue(contextValue1));
        assertTrue(communityIndexValues.containsKey(context2) && communityIndexValues.containsValue(contextValue2));

        // unchanged
        modifierProperties.put("maximum", Collections.singletonMap("1.3.6", 172L));
        final CommunityIndexCounter32Modifier modifier2 = new CommunityIndexCounter32Modifier();
        modifier2.init(modifierProperties);

        final Map<Long, Long> communityIndexValues2 = modifier.getCommunityContextMapping();
        assertEquals(communityIndexValues2.size(), 2);
        assertTrue(communityIndexValues2.containsKey(context1) && communityIndexValues2.containsValue(contextValue1));
        assertTrue(communityIndexValues2.containsKey(context2) && communityIndexValues2.containsValue(contextValue2));
    }

    @Test
    public void testModify() throws Exception {
        final CommunityIndexCounter32Modifier modifier = new CommunityIndexCounter32Modifier();
        modifier.init(modifierProperties);

        final Counter32 counter32 = new Counter32(contextValue1);
        assertEquals(counter32.getValue(), contextValue1);

        final Counter32 modifiedVariable = modifier.modify(counter32);
        assertEquals(modifiedVariable.getValue(), contextValue1);

        final Counter32 modifiedVariable2 = modifier.modify(null);
        assertEquals(modifiedVariable2, new Counter32(0L));
    }

    @Test
    public void testGetVariableBindings() throws Exception {
        final CommunityIndexCounter32Modifier modifier = new CommunityIndexCounter32Modifier();
        modifier.init(modifierProperties);
{'fraction_non_alphanumeric': 0.08671702864337426, 'fraction_numerical': 0.03210576015108593, 'mean_word_length': 4.239076669414675, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, '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': '3442579', 'n_tokens_mistral': 1751, 'n_tokens_neox': 1646, 'n_words': 325}