package org.utplsql.api.outputBuffer;

import org.junit.jupiter.api.Test;
import org.utplsql.api.AbstractDatabaseTest;
import org.utplsql.api.Version;
import org.utplsql.api.compatibility.CompatibilityProxy;
import org.utplsql.api.reporter.CoreReporters;
import org.utplsql.api.reporter.Reporter;
import org.utplsql.api.reporter.ReporterFactory;

import java.sql.SQLException;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsInstanceOf.instanceOf;

public class OutputBufferProviderIT extends AbstractDatabaseTest {

    @Test
    void testGettingPre310Version() throws SQLException {

        CompatibilityProxy proxy = new CompatibilityProxy(getConnection(), Version.V3_0_4);
        ReporterFactory reporterFactory = ReporterFactory.createDefault(proxy);

        Reporter r = reporterFactory.createReporter(CoreReporters.UT_DOCUMENTATION_REPORTER.name());
        r.init(getConnection(), proxy, reporterFactory);

        OutputBuffer buffer = proxy.getOutputBuffer(r, getConnection());

        assertThat(buffer, instanceOf(CompatibilityOutputBufferPre310.class));
    }

    @Test
    void testGettingActualVersion() throws SQLException {
        CompatibilityProxy proxy = new CompatibilityProxy(getConnection(), Version.LATEST);
        ReporterFactory reporterFactory = ReporterFactory.createDefault(proxy);

        Reporter r = reporterFactory.createReporter(CoreReporters.UT_DOCUMENTATION_REPORTER.name());
        r.init(getConnection(), proxy, reporterFactory);

        OutputBuffer buffer = proxy.getOutputBuffer(r, getConnection());

        assertThat(buffer, instanceOf(DefaultOutputBuffer.class));
    }
}

@@ -201,16 +201,74 @@
 yProxy;%0A
+import org.utplsql.api.exception.InvalidVersionException;%0A
 import o
@@ -1234,16 +1234,41 @@
 xception
+, InvalidVersionException
  %7B%0A     
@@ -1354,16 +1354,171 @@
 ATEST);%0A
+%0A        // We can only test new behaviour with DB-Version %3E= 3.1.0%0A        if ( proxy.getRealDbPlsqlVersion().isGreaterOrEqualThan(Version.V3_1_0)) %7B%0A    
         
@@ -1582,32 +1582,36 @@
 efault(proxy);%0A%0A
+    
         Reporter
@@ -1695,32 +1695,36 @@
 ame());%0A        
+    
 r.init(getConnec
@@ -1749,32 +1749,36 @@
 orterFactory);%0A%0A
+    
         OutputBu
@@ -1835,32 +1835,36 @@
 on());%0A%0A        
+   
+ 
 assertThat(buffe
@@ -1902,20 +1902,30 @@
 er.class));%0A
+        %7D%0A
     %7D%0A%7D%0A

Fix test: We can only test new behavior in instances >= 3.1.0