package com.xebyte.offline;

import com.xebyte.core.MalwareSecurityService;
import com.xebyte.core.Response;
import com.xebyte.core.ThreadingStrategy;
import junit.framework.TestCase;

/**
 * Graceful-degradation coverage for MalwareSecurityService (previously no behavioral tests).
 * Each analysis tool must return a clean "No program loaded" error rather than throw when no
 * binary is loaded.
 */
public class MalwareSecurityServiceValidationTest extends TestCase {

    private MalwareSecurityService malware;

    @Override
    protected void setUp() {
        ThreadingStrategy ts = new NoopThreadingStrategy();
        malware = new MalwareSecurityService(ServiceFactory.stubProvider(), ts);
    }

    private static void assertNoProgram(Response r) {
        assertNotNull("method returned null instead of an error Response", r);
        assertTrue("expected 'No program loaded', got: " + r.toJson(),
                r.toJson().contains("No program loaded"));
    }

    public void testFindAntiAnalysisTechniquesDegradesGracefully() {
        assertNoProgram(malware.findAntiAnalysisTechniques());
    }

    public void testAutoDecryptStringsDegradesGracefully() {
        assertNoProgram(malware.autoDecryptStrings());
    }

    public void testAnalyzeApiCallChainsDegradesGracefully() {
        assertNoProgram(malware.analyzeAPICallChains());
    }

    public void testExtractIocsWithContextDegradesGracefully() {
        assertNoProgram(malware.extractIOCsWithContext());
    }

    public void testDetectMalwareBehaviorsDegradesGracefully() {
        assertNoProgram(malware.detectMalwareBehaviors());
    }
}
