<commit_before>package fi.helsinki.cs.tmc.cli.command;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import fi.helsinki.cs.tmc.cli.Application;

import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.io.PrintStream;

public class LoginCommandTest {

    private static String serverAddress;
    private static String username;
    private static String password;

    private Application app;
    private OutputStream os;

    public LoginCommandTest() {
    }

    @BeforeClass
    public static void setUpClass() {
        LoginCommandTest.serverAddress = System.getenv("TMC_SERVER_ADDRESS");
        LoginCommandTest.username = System.getenv("TMC_USERNAME");
        LoginCommandTest.password = System.<PASSWORD>("TMC_PASSWORD");

        assertNotNull(LoginCommandTest.serverAddress);
        assertNotNull(LoginCommandTest.username);
        assertNotNull(LoginCommandTest.password);
    }

    @Before
    public void setUp() {
        this.app = new Application();
        this.os = new ByteArrayOutputStream();

        PrintStream ps = new PrintStream(os);
        System.setOut(ps);
    }

    @Test
    public void logsInWithCorrectServerUserAndPassword() {
        String[] args = createArgs(
                LoginCommandTest.serverAddress,
                LoginCommandTest.username,
                LoginCommandTest.password);

        app.run(args);
        String output = os.toString();
        assertTrue(output.contains("Login successful!"));
    }

    @Test
    public void catches401IfCorrectServerAndWrongUsername() {
        String[] args = createArgs(
                LoginCommandTest.serverAddress,
                "",
                LoginCommandTest.password);<commit_msg>Do not leave behind a settings file from these tests<commit_after>package fi.helsinki.cs.tmc.cli.command;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import fi.helsinki.cs.tmc.cli.Application;
import fi.helsinki.cs.tmc.cli.tmcstuff.SettingsIo;

import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.io.PrintStream;

public class LoginCommandTest {

    private static String serverAddress;
    private static String username;
    private static String password;

    private Application app;
    private OutputStream os;

    public LoginCommandTest() {
    }

    @BeforeClass
    public static void setUpClass() {
        LoginCommandTest.serverAddress = System.getenv("TMC_SERVER_ADDRESS");
        LoginCommandTest.username = System.getenv("TMC_USERNAME");
        LoginCommandTest.password = System.getenv("TMC_PASSWORD");

        assertNotNull(LoginCommandTest.serverAddress);
        assertNotNull(LoginCommandTest.username);
        assertNotNull(LoginCommandTest.password);
    }

    @Before
    public void setUp() {
        // Unwanted behaviour? Will delete the real settings file atm.
        new SettingsIo().delete();

        this.app = new Application();
        this.os = new ByteArrayOutputStream();

        PrintStream ps = new PrintStream(os);
        System.setOut(ps);
    }

    @After
    public void tearDown() {
        // Unwanted behaviour? Will delete the real settings file atm.
        new SettingsIo().delete();
    }

    @Test
    public void logsInWithCorrectServerUserAndPassword() {
        String[] args = createArgs(
                LoginCommandTest.serverAddress,
                LoginCommandTest.username,
                LoginCommandTest.password);

        // Unwanted behaviour? Will create real settings file atm.
        app.run(args);

        String output = os.toString();
        assertTrue(output.contains("Login successful!"));
    }

    @Test
    public void catches401IfCorrectServerAndWrongUsername() {
        String[] args = createArgs(
                LoginCommandTest.serverAddress,
                "",
                LoginCommandTest.password);
{'fraction_non_alphanumeric': 0.08978702807357213, 'fraction_numerical': 0.001452081316553727, 'mean_word_length': 2.88075117370892, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '5527663', 'n_tokens_mistral': 1115, 'n_tokens_neox': 1070, 'n_words': 244}