package com.tngtech.archunit.core.domain;

import java.util.ArrayList;

import com.tngtech.archunit.testutil.ArchConfigurationRule;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import static com.tngtech.archunit.core.domain.Formatters.formatLocation;
import static com.tngtech.archunit.core.domain.TestUtils.importClassWithContext;
import static com.tngtech.archunit.testutil.Assertions.assertThat;

public class FormattersTest {
    @Rule
    public final ArchConfigurationRule configuration = new ArchConfigurationRule();

    @Before
    public void setUp() {
        // We need this to create a JavaClass without source, i.e. a stub because the class is missing and cannot be resolved
        configuration.resolveAdditionalDependenciesFromClassPath(false);
    }

    @Test
    public void format_location() {
        JavaClass classWithSource = importClassWithContext(Object.class);

        assertThat(classWithSource.getSource()).as("source").isPresent();
        assertThat(formatLocation(classWithSource, 7)).isEqualTo("(Object.java:7)");

        JavaClass classWithoutSource = getClassWithoutSource();

        assertThat(classWithoutSource.getSource()).as("source").isAbsent();
        assertThat(formatLocation(classWithoutSource, 7)).isEqualTo(String.format("(%s.java:7)", classWithoutSource.getSimpleName()));
    }

    private JavaClass getClassWithoutSource() {
        for (JavaAccess<?> javaAccess : importClassWithContext(SomeClass.class).getAccessesFromSelf()) {
            if (javaAccess.getTargetOwner().isEquivalentTo(ArrayList.class)) {
                return javaAccess.getTargetOwner();
            }
        }
        throw new RuntimeException("Could not create any java class without source");
    }

    private static class SomeClass {
        public SomeClass() {
            new ArrayList<>();
        }
    }
}
@@ -121,24 +121,49 @@
 rationRule;%0A
+import org.junit.Assert;%0A
 import org.j
@@ -1771,32 +1771,1479 @@
 ource%22);%0A    %7D%0A%0A
+    @Test%0A    public void ensureSimpleName_withNullString() %7B%0A        try %7B%0A            Formatters.ensureSimpleName(null);%0A            Assert.fail(%22NullPointerException expected, but not thrown%22);%0A        %7D catch (NullPointerException expected) %7B%0A        %7D%0A    %7D%0A%0A    @Test%0A    public void ensureSimpleName_withEmptyString() %7B%0A        assertThat(Formatters.ensureSimpleName(%22%22)).isEqualTo(%22%22);%0A    %7D%0A%0A    @Test%0A    public void ensureSimpleName_withClassInDefaultPackage() %7B%0A        assertThat(Formatters.ensureSimpleName(%22Dummy%22)).isEqualTo(%22Dummy%22);%0A    %7D%0A%0A    @Test%0A    public void ensureSimpleName_withClassInPackage() %7B%0A        assertThat(Formatters.ensureSimpleName(%22org.example.Dummy%22)).isEqualTo(%22Dummy%22);%0A    %7D%0A%0A    @Test%0A    public void ensureSimpleName_withAnonymousClass() %7B%0A        assertThat(Formatters.ensureSimpleName(%22org.example.Dummy$123%22)).isEqualTo(%22%22);%0A    %7D%0A%0A    @Test%0A    public void ensureSimpleName_withNestedClass() %7B%0A        assertThat(Formatters.ensureSimpleName(%22org.example.Dummy$NestedClass%22)).isEqualTo(%22NestedClass%22);%0A    %7D%0A%0A    @Test%0A    public void ensureSimpleName_withAnonymousClassInNestedClass() %7B%0A        assertThat(Formatters.ensureSimpleName(%22org.example.Dummy$NestedClass$123%22)).isEqualTo(%22%22);%0A    %7D%0A%0A    @Test%0A    public void ensureSimpleName_withDeeplyNestedClass() %7B%0A        assertThat(Formatters.ensureSimpleName(%22org.example.Dummy$NestedClass$MoreNestedClass%22)).isEqualTo(%22MoreNestedClass%22);%0A    %7D%0A%0A
     private stat

Add tests for Formatters.ensureSimpleName(...)