<commit_before>package net.dean.jraw.test

import com.winterbe.expekt.should
import net.dean.jraw.http.HttpRequest
import net.dean.jraw.http.SimpleHttpLogger
import net.dean.jraw.http.oauth.OAuthHelper
import net.dean.jraw.test.util.CredentialsUtil
import net.dean.jraw.test.util.TestConfig.reddit
import net.dean.jraw.test.util.newOkHttpAdapter
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.describe
import org.jetbrains.spek.api.dsl.it
import java.io.ByteArrayOutputStream
import java.io.PrintStream
import java.util.*

class RedditClientTest : Spek({
    describe("requestStub") {
        it("should provide a builder with the default settings") {
            val request = reddit.requestStub().build()
            request.url.should.equal("https://oauth.reddit.com/")
            request.headers.get("Authorization").should.match(Regex("^bearer [A-Za-z0-9_\\-]+"))
        }
    }

    it("shouldn't log HTTP requests when logHttp=false") {
        val baos = ByteArrayOutputStream()
        val reddit = OAuthHelper.script(CredentialsUtil.script, newOkHttpAdapter())

        // Give the RedditClient our logger
        reddit.logger = SimpleHttpLogger(PrintStream(baos))
        reddit.logHttp = false

        // Make a request, which would trigger writing to the BAOS if logHttp is being ignored
        reddit.request(HttpRequest.Builder()
            .url("https://httpbin.org/get")
            .build())

        baos.size().should.equal(0)
    }

    describe("subreddit") {
        it("should return a Subreddit") {
            val pics = reddit.subreddit("pics")
            pics.name.should.equal("pics")

            // Test Date deserialization
            // See /r/pics.json --> created_utc
            pics.created.should.be.above(Date(1201132800))
        }
    }

    describe("randomSubreddit") {
        it("should return a random subreddit") {
            val random = reddit.randomSubreddit()<commit_msg>Remove unnecessary variable<commit_after>package net.dean.jraw.test

import com.winterbe.expekt.should
import net.dean.jraw.http.HttpRequest
import net.dean.jraw.http.SimpleHttpLogger
import net.dean.jraw.http.oauth.OAuthHelper
import net.dean.jraw.test.util.CredentialsUtil
import net.dean.jraw.test.util.TestConfig.reddit
import net.dean.jraw.test.util.newOkHttpAdapter
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.describe
import org.jetbrains.spek.api.dsl.it
import java.io.ByteArrayOutputStream
import java.io.PrintStream
import java.util.*

class RedditClientTest : Spek({
    describe("requestStub") {
        it("should provide a builder with the default settings") {
            val request = reddit.requestStub().build()
            request.url.should.equal("https://oauth.reddit.com/")
            request.headers.get("Authorization").should.match(Regex("^bearer [A-Za-z0-9_\\-]+"))
        }
    }

    it("shouldn't log HTTP requests when logHttp=false") {
        val baos = ByteArrayOutputStream()
        val reddit = OAuthHelper.script(CredentialsUtil.script, newOkHttpAdapter())

        // Give the RedditClient our logger
        reddit.logger = SimpleHttpLogger(PrintStream(baos))
        reddit.logHttp = false

        // Make a request, which would trigger writing to the BAOS if logHttp is being ignored
        reddit.request(HttpRequest.Builder()
            .url("https://httpbin.org/get")
            .build())

        baos.size().should.equal(0)
    }

    describe("subreddit") {
        it("should return a Subreddit") {
            val pics = reddit.subreddit("pics")
            pics.name.should.equal("pics")

            // Test Date deserialization
            // See /r/pics.json --> created_utc
            pics.created.should.be.above(Date(1201132800))
        }
    }

    describe("randomSubreddit") {
        it("should return a random subreddit") {
            // Just make sure it deserializes
            reddit.randomSubreddit()
{'fraction_non_alphanumeric': 0.11813812294459904, 'fraction_numerical': 0.0065772830761447005, 'mean_word_length': 2.7231638418079096, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 4, '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': '7389186', 'n_tokens_mistral': 1210, 'n_tokens_neox': 1205, 'n_words': 228}