package com.oneandone.snmpman;

import org.snmp4j.smi.OctetString;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import static org.testng.Assert.assertTrue;

public class SnmpmanAgentTest {

    private Snmpman snmpman;

    @BeforeMethod
    public void startSnmpman() {
        snmpman = Snmpman.start(new File("src/test/resources/configuration/configuration.yaml"));
    }

    @Test
    public void testSnmpAgentSetupWithCommunityContext() {
        final List<OctetString> contexts = new ArrayList<>();
        final List<SnmpmanAgent> snmpmanAgents = snmpman.getAgents();
        for (final SnmpmanAgent agent : snmpmanAgents) {
            agent.registerManagedObjects();

            contexts.addAll(Arrays.asList(agent.getServer().getContexts()));
        }

        assertTrue(contexts.contains(new OctetString("9")));
        assertTrue(contexts.contains(new OctetString("42")));
    }

    @AfterMethod
    public void stopSnmpman() {
        if (snmpman != null) {
            snmpman.stop();
        }
    }
}

@@ -94,122 +94,14 @@
 ons.
-AfterMethod;%0Aimport org.testng.annotations.BeforeMethod;%0Aimport org.testng.annotations.Test;%0A%0Aimport java.io.File;
+Test;%0A
 %0Aimp
@@ -253,195 +253,37 @@
 est 
-%7B%0A%0A    private Snmpman snmpman;%0A%0A    @BeforeMethod%0A    public void startSnmpman() %7B%0A        snmpman = Snmpman.start(new File(%22src/test/resources/configuration/configuration.yaml%22));%0A    %7D
+extends AbstractSnmpmanTest %7B
 %0A%0A  
@@ -803,132 +803,7 @@
    %7D
-%0A%0A    @AfterMethod%0A    public void stopSnmpman() %7B%0A        if (snmpman != null) %7B%0A            snmpman.stop();%0A        %7D%0A    %7D
 %0A%7D%0A

Use test parent class inheritance to avoid boiler plate code.