package org.jonnyzzz;

import com.sun.istack.internal.NotNull;
import org.jonnyzzz.stack.StackLine;
import org.junit.Assert;
import org.junit.Test;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.concurrent.atomic.AtomicReference;

/**
 * Unit test for simple App.
 */
public class AppTest {

    @Test
    public void test_action() throws Throwable {

        final AtomicReference<String> result = new AtomicReference<String>();
        StackLine.stackLine("someMagicTestName", Throwable.class, new StackLine.UnderStackAction<Throwable>() {
            public void execute() throws Throwable {
                result.set(stackTrace());

            }
        });

        final String s = result.get();
        Assert.assertTrue(s, s.contains("someMagicTestName"));
    }

    @Test
    public void test_function() throws Throwable {

        final AtomicReference<String> result = new AtomicReference<String>();
        StackLine.stackLine("someMagicTestName", Throwable.class, new StackLine.UnderStackFunction<Object, Throwable>() {
            public Object execute() throws Throwable {
                result.set(stackTrace());
                return 42;
            }
        });

        final String s = result.get();
        Assert.assertTrue(s, s.contains("someMagicTestName"));
    }


    @NotNull
    private static String stackTrace() {
        try {
            throw new Exception();
        } catch (Exception e) {
            final StringWriter sw = new StringWriter();
            e.printStackTrace(new PrintWriter(sw));
            return sw.toString();
        }
    }
}

@@ -848,33 +848,32 @@
 ows Throwable %7B%0A
-%0A
         final At
@@ -1316,16 +1316,574 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void test_long_names_function() throws Throwable %7B%0A        final AtomicReference%3CString%3E result = new AtomicReference%3CString%3E();%0A        StackLine.stackLine(%22%D0%B2%D0%BE%D1%82 %D1%8D%D1%82%D0%BE %D0%B2%D0%BE%D1%82 %D1%82%D1%83%D1%82 %D1%82%D0%B0%D0%BA %D0%BF%D0%BE%D0%BB%D1%83%D1%87%D0%B8%D0%BB%D0%BE%D1%81%D1%8C%22, Throwable.class, new StackLine.UnderStackFunction%3CObject, Throwable%3E() %7B%0A            public Object execute() throws Throwable %7B%0A                result.set(stackTrace());%0A                return 42;%0A            %7D%0A        %7D);%0A%0A        final String s = result.get();%0A        Assert.assertTrue(s, s.contains(%22%D0%B2%D0%BE%D1%82 %D1%8D%D1%82%D0%BE %D0%B2%D0%BE%D1%82 %D1%82%D1%83%D1%82 %D1%82%D0%B0%D0%BA %D0%BF%D0%BE%D0%BB%D1%83%D1%87%D0%B8%D0%BB%D0%BE%D1%81%D1%8C%22));%0A    %7D%0A%0A
 %0A    @No
@@ -2062,24 +2062,24 @@
 ngWriter();%0A
-
             
@@ -2114,24 +2114,70 @@
 riter(sw));%0A
+            System.out.printf(sw.toString());%0A
             

test for localized names