<commit_before>package com.waytta;

import net.sf.json.JSONObject;
import org.junit.Test;
import org.junit.Before;
import org.junit.runner.RunWith;


import static java.lang.Boolean.FALSE;
import static java.lang.Boolean.TRUE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.eq;
import static org.powermock.api.mockito.PowerMockito.mock;
import static org.powermock.api.mockito.PowerMockito.when;

import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import java.util.Date;

@RunWith(PowerMockRunner.class)
@PrepareForTest({JSONObject.class})
public class SaltAPIBuilderTest {

    private static final java.lang.Integer TESTINT = (int)(new Date().getTime());
    JSONObject clientInterfaces;
    String servername = "servername";
    String authtype = "authtype";
    String target = "target";
    String targettype = "targettype";
    String function = "function";
    String mods = "mods";
    String pillarkey = "pillarkey";
    String pillarvalue = "pillarvalue";
    String credentialsId = "credentialsId";


    @Before
    public void setup(){
        clientInterfaces = mock(JSONObject.class);
    }
    
    @Test
    public void testConstructorWithAnyValueForClientInterface() {
        when(clientInterfaces.has("clientInterface")).thenReturn(TRUE);
        when(clientInterfaces.get("clientInterface")).thenReturn("JUNIT");
        SaltAPIBuilder builder = build();
        assertEquals("JUNIT", builder.getClientInterface());
        assertEquals("100%", builder.getBatchSize());
        assertFalse(builder.getBlockbuild());
        assertEquals(new Integer(10), builder.getJobPollTime());
        assertEquals("", builder.getMods());
        assertFalse(builder.getUsePillar());
        assertEquals("", builder.getPillarkey());
        assertEquals("", builder.getPillarvalue());
    }

    @Test
    public void testConstructorWithLocalBatchClientInterface() {
        when(clientInterfaces.has("clientInterface")).thenReturn(TRUE);
        when(clientInterfaces.get("clientInterface")).thenReturn("local_batch");
        when(clientInterfaces.get("batchSize")).thenReturn("JUNIT_BATCHSIZE");
        SaltAPIBuilder builder = build();
        assertEquals("local_batch", builder.getClientInterface());
        assertFalse(builder.getBlockbuild());
        assertEquals(new Integer(10), builder.getJobPollTime());
        assertEquals("", builder.getMods());
        assertFalse(builder.getUsePillar());
        assertEquals("", builder.getPillarkey());
        assertEquals("", builder.getPillarvalue());
    }

    @Test
    public void testConstructorWithUsePillarAndRunnerClientInterfaceAndUserPillar() {
        when(clientInterfaces.has("clientInterface")).thenReturn(TRUE);
        when(clientInterfaces.get("clientInterface")).thenReturn("runner");
        when(clientInterfaces.get("mods")).thenReturn("JUNIT_MODS");
        JSONObject usePillar = mock(JSONObject.class);
        when(clientInterfaces.has("usePillar")).thenReturn(TRUE);
        when(clientInterfaces.getJSONObject("usePillar")).thenReturn(usePillar);
        when(usePillar.get("pillarkey")).thenReturn("JUNIT_PILLARKEY");
        when(usePillar.get("pillarvalue")).thenReturn("JUNIT_PILLARVALUE");
        SaltAPIBuilder builder = build();
        assertEquals("runner", builder.getClientInterface());
        assertTrue(builder.getUsePillar());
        assertEquals("JUNIT_PILLARKEY", builder.getPillarkey());
        assertEquals("JUNIT_PILLARVALUE", builder.getPillarvalue());
        assertFalse(builder.getBlockbuild());
        assertEquals(new Integer(10), builder.getJobPollTime());
        assertEquals("100%", builder.getBatchSize());
    }

    @Test
    public void testConstructorWithUsePillarAndRunnerClientInterfaceButNoUserPillar() {
        when(clientInterfaces.has("clientInterface")).thenReturn(TRUE);
        when(clientInterfaces.get("clientInterface")).thenReturn("runner");
        when(clientInterfaces.get("mods")).thenReturn("JUNIT_MODS");
        JSONObject usePillar = mock(JSONObject.class);
        SaltAPIBuilder builder = build();
        assertEquals("runner", builder.getClientInterface());
        assertFalse(builder.getUsePillar());
        assertEquals("", builder.getPillarkey());
        assertEquals("", builder.getPillarvalue());
        assertFalse(builder.getBlockbuild());
        assertEquals(new Integer(10), builder.getJobPollTime());
        assertEquals("100%", builder.getBatchSize());
    }
    
    @Test
    public void testConstructorWithOutClientInterface() {
        when(clientInterfaces.has("clientInterface")).thenReturn(FALSE);
        when(clientInterfaces.getBoolean("blockBuild")).thenReturn(FALSE);
        when(clientInterfaces.getInt("jobPollTime")).thenReturn(TESTINT);
        SaltAPIBuilder builder = build();
        assertEquals("local", builder.getClientInterface());
        assertEquals("100%", builder.getBatchSize());
        assertFalse(builder.getBlockbuild());
        assertEquals(TESTINT, builder.getJobPollTime());
        assertEquals("", builder.getMods());
        assertFalse(builder.getUsePillar());
        assertEquals("", builder.getPillarkey());
        assertEquals("", builder.getPillarvalue());
    }

    SaltAPIBuilder build() {
        return new SaltAPIBuilder(
                servername,
                authtype,
                target,
                targettype,
                function,
                clientInterfaces,
                mods,
                pillarkey,
                pillarvalue,
                credentialsId);
    }<commit_msg>Constructor coverage complete - ready to refactor<commit_after>package com.waytta;

import net.sf.json.JSONObject;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import java.util.Date;

import static java.lang.Boolean.FALSE;
import static java.lang.Boolean.TRUE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.powermock.api.mockito.PowerMockito.mock;
import static org.powermock.api.mockito.PowerMockito.when;

@RunWith(PowerMockRunner.class)
@PrepareForTest({JSONObject.class})
public class SaltAPIBuilderTest {

    private static final java.lang.Integer TESTINT = (int)(new Date().getTime());
    private static final Integer TEN = new Integer(10);
    JSONObject clientInterfaces;



    @Before
    public void setup(){
        clientInterfaces = mock(JSONObject.class);
        when(clientInterfaces.has("clientInterface")).thenReturn(TRUE);
    }
    
    @Test
    public void testConstructorWithAnyValueForClientInterface() {
        when(clientInterfaces.get("clientInterface")).thenReturn("JUNIT");
        SaltAPIBuilder builder = build();
        validateBuilder(builder, "JUNIT"); 
    }

    @Test
    public void testConstructorWithLocalBatchClientInterface() {
        when(clientInterfaces.get("clientInterface")).thenReturn("local_batch");
        when(clientInterfaces.get("batchSize")).thenReturn("JUNIT_BATCHSIZE");
        SaltAPIBuilder builder = build();
        validateBuilder(builder, "local_batch", "JUNIT_BATCHSIZE");
        
    }

    @Test
    public void testConstructorWithUsePillarAndRunnerClientInterfaceAndUserPillar() {
        when(clientInterfaces.get("clientInterface")).thenReturn("runner");
        when(clientInterfaces.get("mods")).thenReturn("JUNIT_MODS");
        JSONObject usePillar = mock(JSONObject.class);
        when(clientInterfaces.has("usePillar")).thenReturn(TRUE);
        when(clientInterfaces.getJSONObject("usePillar")).thenReturn(usePillar);
        when(usePillar.get("pillarkey")).thenReturn("JUNIT_PILLARKEY");
        when(usePillar.get("pillarvalue")).thenReturn("JUNIT_PILLARVALUE");
        SaltAPIBuilder builder = build();
        validateBuilder(builder, "runner", "JUNIT_MODS", true, "JUNIT_PILLARKEY", "JUNIT_PILLARVALUE");
    }

    @Test
    public void testConstructorWithUsePillarAndRunnerClientInterfaceButNoUserPillar() {
        when(clientInterfaces.get("clientInterface")).thenReturn("runner");
        when(clientInterfaces.get("mods")).thenReturn("JUNIT_MODS");
        
        SaltAPIBuilder builder = build();
        validateBuilder("runner", builder, "JUNIT_MODS");        
    }
    
    @Test
    public void testConstructorWithOutClientInterface() {
        when(clientInterfaces.has("clientInterface")).thenReturn(FALSE);
        when(clientInterfaces.getBoolean("blockBuild")).thenReturn(FALSE);
        when(clientInterfaces.getInt("jobPollTime")).thenReturn(TESTINT);
        SaltAPIBuilder builder = build();
        validateBuilder(builder, "local", TESTINT); 
    }


    private void validateBuilder(SaltAPIBuilder builder,
                                 String clientInterfaces,
                                 String mods, 
                                 Boolean usePillar,
                                 String pillarkey,
                                 String pillarValue){
        validateBuilder(builder, clientInterfaces, TEN, "100%", mods, usePillar, pillarkey, pillarValue );
    }
    private void validateBuilder(SaltAPIBuilder builder,
                                 String clientInterface) {
        validateBuilder( builder, clientInterface, TEN, "100%", "", false, "", "");
    }

    private void validateBuilder(String clientInterface, 
                                 SaltAPIBuilder builder,
                                 String mods) {
        validateBuilder( builder, clientInterface, TEN, "100%", mods, false, "", "");
    }

    private void validateBuilder(SaltAPIBuilder builder,
                                 String clientInterface,
                                 String batchSize) {
        validateBuilder( builder, clientInterface, TEN, batchSize, "", false, "", "");
    }

    private void validateBuilder(SaltAPIBuilder builder,
                                 String clientInterface,
                                 Integer jobPollTime) {
        validateBuilder( builder, clientInterface, jobPollTime, "100%", "", false, "", "");
    }
    
    private void validateBuilder(SaltAPIBuilder builder,
                                 String clientInterface,
                                 Integer jobPollTime,
                                 String batchSize,
                                 String mods,
                                 Boolean usePillar,
                                 String pillarkey,
                                 String pillarValue) {
        assertFalse(builder.getBlockbuild());
        assertEquals(clientInterface, builder.getClientInterface());
        assertEquals(batchSize, builder.getBatchSize());
        assertEquals(jobPollTime, builder.getJobPollTime());
        assertEquals(mods, builder.getMods());
        assertEquals(usePillar,builder.getUsePillar());
        assertEquals(pillarkey, builder.getPillarkey());
        assertEquals(pillarValue, builder.getPillarvalue());
    }
    
    SaltAPIBuilder build() {
        return new SaltAPIBuilder(
                "servername",
                "authtype",
                "target",
                "targettype",
                "function",
                clientInterfaces,
                "mods",
                "pillarkey",
                "pillarvalue",
                "credentialsId");
    }
{'fraction_non_alphanumeric': 0.11444024725274725, 'fraction_numerical': 0.0030906593406593405, 'mean_word_length': 2.970347648261759, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 19, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3131457', 'n_tokens_mistral': 3113, 'n_tokens_neox': 3035, 'n_words': 492}