package org.camunda.bpm.extension.process_test_coverage.util;

import org.junit.Assert;
import org.junit.Test;

import java.io.File;
import java.net.URL;

/**
 * @author Martin Schimak <martin.schimak@plexiti.com>
 */
public class ClassLocationURLTest {

  @Test
  public void test_urlFromCodeSource_JavaLangStringClass() {
    URL url = ClassLocationURL.urlFromCodeSource(String.class);
    Assert.assertNull(url);
  }

  @Test
  public void test_urlFromCodeSource_OrgJunitTestClass() {
    URL url = ClassLocationURL.urlFromCodeSource(Test.class);
    Assert.assertNotNull(url);
    Assert.assertTrue(url.toExternalForm().startsWith("file:"));
    Assert.assertTrue(url.toExternalForm().endsWith(".jar"));
  }

  @Test
  public void test_urlFromCodeSource_ThisClass() {
    URL url = ClassLocationURL.urlFromCodeSource(ClassLocationURLTest.class);
    Assert.assertNotNull(url);
    Assert.assertTrue(url.toExternalForm().startsWith("file:"));
    Assert.assertFalse(url.toExternalForm().endsWith(".jar"));
    Assert.assertTrue(url.toExternalForm().endsWith("/"));
  }

  @Test
  public void test_urlFromResource_JavaLangStringClass() {
    URL url = ClassLocationURL.urlFromResource(String.class);
    Assert.assertNotNull(url);
    Assert.assertTrue(url.toExternalForm().startsWith("file:"));
    Assert.assertTrue(url.toExternalForm().endsWith(".jar"));
  }

  @Test
  public void test_urlFromResource_OrgJunitTestClass() {
    URL url = ClassLocationURL.urlFromResource(Test.class);
    Assert.assertNotNull(url);
    Assert.assertTrue(url.toExternalForm().startsWith("file:"));
    Assert.assertTrue(url.toExternalForm().endsWith(".jar"));
  }

  @Test
  public void test_urlFromResource_ThisClass() {
    URL url = ClassLocationURL.urlFromResource(ClassLocationURLTest.class);
    Assert.assertNotNull(url);
    Assert.assertTrue(url.toExternalForm().startsWith("file:"));
    Assert.assertFalse(url.toExternalForm().endsWith(".jar"));
    Assert.assertTrue(url.toExternalForm().endsWith("/"));
  }

  @Test
  public void test_locationFor_JavaLangStringClass() {
    URL url = ClassLocationURL.locationFor(String.class);
    Assert.assertNotNull(url);
    Assert.assertTrue(url.toExternalForm().startsWith("file:"));
    Assert.assertTrue(url.toExternalForm().endsWith(".jar"));
  }

  @Test
  public void test_locationFor_OrgJunitTestClass() {
    URL url = ClassLocationURL.locationFor(Test.class);
    Assert.assertNotNull(url);
    Assert.assertTrue(url.toExternalForm().startsWith("file:"));
    Assert.assertTrue(url.toExternalForm().endsWith(".jar"));
  }

  @Test
  public void test_locationFor_ThisClass() {
    URL url = ClassLocationURL.locationFor(ClassLocationURLTest.class);
    Assert.assertNotNull(url);
    Assert.assertTrue(url.toExternalForm().startsWith("file:"));
    Assert.assertFalse(url.toExternalForm().endsWith(".jar"));
    Assert.assertTrue(url.toExternalForm().endsWith("/"));
  }

  @Test
  public void test_fileFor_JavaLangStringClass() {
    File file  = ClassLocationURL.fileFor(String.class);
    Assert.assertNotNull(file);
    Assert.assertTrue(file.getAbsolutePath().endsWith(".jar"));
    Assert.assertTrue(file.isFile());
  }

  @Test
  public void test_fileFor_OrgJunitTestClass() {
    File file = ClassLocationURL.fileFor(Test.class);
    Assert.assertNotNull(file);
    Assert.assertTrue(file.getAbsolutePath().endsWith(".jar"));
    Assert.assertTrue(file.isFile());
  }

  @Test
  public void test_fileFor_ThisClass() {
    File file = ClassLocationURL.fileFor(ClassLocationURLTest.class);
    Assert.assertNotNull(file);
    Assert.assertFalse(file.getAbsolutePath().endsWith(".jar"));
    Assert.assertTrue(file.isDirectory());
  }

}

@@ -67,25 +67,43 @@
 ort 
-org.junit.Assert;
+java.io.File;%0Aimport java.net.URL;%0A
 %0Aimp
@@ -120,55 +120,62 @@
 nit.
-Tes
+Asser
 t;%0A
-%0A
 import 
-java.io.File;%0Aimport java.net.URL
+org.junit.Ignore;%0Aimport org.junit.Test
 ;%0A%0A/
@@ -1243,35 +1243,62 @@
 rtNotNull(url);%0A
+//
    
+ doesn't work in Java 11:
  Assert.assertTr
@@ -1335,35 +1335,62 @@
 With(%22file:%22));%0A
+//
    
+ doesn't work in Java 11:
  Assert.assertTr
@@ -2225,35 +2225,62 @@
 rtNotNull(url);%0A
+//
    
+ doesn't work in Java 11:
  Assert.assertTr
@@ -2317,35 +2317,62 @@
 With(%22file:%22));%0A
+//
    
+ doesn't work in Java 11:
  Assert.assertTr
@@ -3047,32 +3047,69 @@
 );%0A  %7D%0A%0A  @Test%0A
+  @Ignore // doesn't work in Java 11%0A
   public void te

Fix tests for Java 11