<commit_before>package de.meggsimum.w3w;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import java.util.UUID;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeNotNull;

/**
 * Unit test for {@linkplain What3Words}
 *
 * @author <NAME>, meggsimum
 */
public class What3WordsTest {

    /**
     * The api is read from command line arguments or can also be entered here manually.
     */
    private String apiKey = null;
    /**
     * Name of the system property hodling the API key for W3W.
     */
    public static final String API_KEY_PROPERTY = "W3W_API_KEY";

    @Rule
    public ExpectedException expectedException = ExpectedException.none();

    /**
     * Checks if the API key is either hard coded or passed via system properties.
     * Only if this precondition is true, the tests are executed.
     */
    @Before
    public void beforeMethod() {
        // Try to read the API key from system properties only in case it was not hard coded.
        if (apiKey == null) {
            apiKey = System.getProperty(API_KEY_PROPERTY);
        }
        assumeNotNull(apiKey);
    }

    /**
     * Tests the words -> position API wrapper
     */<commit_msg>add a fallback for environment variable to read API key<commit_after>package de.meggsimum.w3w;

import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import java.util.UUID;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeNotNull;

/**
 * Unit test for {@linkplain What3Words}
 *
 * @author <NAME>, meggsimum
 */
public class What3WordsTest {

    /**
     * The api key is read from command line arguments or can also be entered here manually.
     */
    private String apiKey = null;
    /**
     * Name of the system property hodling the API key for W3W.
     */
    public static final String API_KEY_PROPERTY = "W3W_API_KEY";

    @Rule
    public ExpectedException expectedException = ExpectedException.none();

    /**
     * Checks if the API key is either hard coded or passed via system properties.
     * Only if this precondition is true, the tests are executed.
     */
    @Before
    public void beforeMethod() {
        // Try to read the API key from system properties only in case it was not hard coded.
        if (apiKey == null) {
            apiKey = System.getProperty(API_KEY_PROPERTY);
        }
        // Fall back to environment variable in case API key was not provided as property
        if(apiKey == null) {
            apiKey = System.getenv(API_KEY_PROPERTY);
        }
        assumeNotNull(apiKey);
    }

    /**
     * Tests the words -> position API wrapper
     */
{'fraction_non_alphanumeric': 0.08617657404150546, 'fraction_numerical': 0.0035174111853675696, 'mean_word_length': 2.7176470588235295, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4115582', 'n_tokens_mistral': 810, 'n_tokens_neox': 800, 'n_words': 288}