// This file is part of me.christopherdavis.beanstalkc
// Copyright: (c) 2014 Christopher Davis <http://christopherdavis.me>
// License: MIT http://opensource.org/licenses/MIT

package me.christopherdavis.beanstalkc.command;

import java.io.OutputStream;
import org.junit.Test;
import org.junit.Assert;
import me.christopherdavis.beanstalkc.BeanstalkcException;

public class AbstractYamlParserTest
{
    @Test
    public void testWithBeanstalkcThrowingParse()
    {
        final BeanstalkcException e = new BeanstalkcException("Test Exception");

        YamlParser<String> parser = new AbstractYamlParser<String>() {
            @Override
            protected String createOutput()
            {
                return new String();
            }

            @Override
            public void handleLine(String line, String out) throws Exception
            {
                throw e;
            }
        };

        try {
            parser.parse("test".getBytes());
        } catch (Exception caught) {
            Assert.assertSame(e, caught);
        }
    }

    @Test
    public void testWithNonBeanstalkcException()
    {
        final Exception e = new Exception("Test Exception");

        YamlParser<String> parser = new AbstractYamlParser<String>() {
            @Override
            protected String createOutput()
            {
                return new String();
            }

            @Override
            public void handleLine(String line, String out) throws Exception
            {
                throw e;
            }
        };

        try {
            parser.parse("test".getBytes());
        } catch (Exception caught) {
            Assert.assertTrue(caught instanceof BeanstalkcException);
            Assert.assertSame(e, caught.getCause());
        }
    }

    @Test
    public void testWithoutException() throws Exception
    {
        final String s = new String("test");

        YamlParser<String> parser = new AbstractYamlParser<String>() {
            @Override
            protected String createOutput()
            {
                return s;
            }

            @Override
            public void handleLine(String line, String out) throws Exception
            {
                // noop
            }
        };

        Assert.assertSame(s, parser.parse("test".getBytes()));
    }
}

@@ -223,37 +223,8 @@
 d;%0A%0A
-import java.io.OutputStream;%0A
 impo
@@ -325,16 +325,79 @@
 ception;
+%0Aimport me.christopherdavis.beanstalkc.exception.YamlException;
 %0A%0Apublic
@@ -1736,26 +1736,20 @@
 tanceof 
-Beanstalkc
+Yaml
 Exceptio

Test for YamlException