Search in sources :

Example 1 with Location

use of cn.taketoday.origin.TextResourceOrigin.Location in project today-infrastructure by TAKETODAY.

the class TextResourceOriginTests method locationToStringReturnsNiceString.

@Test
void locationToStringReturnsNiceString() {
    Location location = new Location(1, 2);
    assertThat(location.toString()).isEqualTo("2:3");
}
Also used : Location(cn.taketoday.origin.TextResourceOrigin.Location) Test(org.junit.jupiter.api.Test)

Example 2 with Location

use of cn.taketoday.origin.TextResourceOrigin.Location in project today-infrastructure by TAKETODAY.

the class TextResourceOriginTests method equalsAndHashCodeUsesResourceAndLocation.

@Test
void equalsAndHashCodeUsesResourceAndLocation() {
    TextResourceOrigin origin1 = new TextResourceOrigin(new ClassPathResource("foo.txt"), new Location(1, 2));
    TextResourceOrigin origin2 = new TextResourceOrigin(new ClassPathResource("foo.txt"), new Location(1, 2));
    TextResourceOrigin origin3 = new TextResourceOrigin(new ClassPathResource("foo.txt"), new Location(2, 2));
    TextResourceOrigin origin4 = new TextResourceOrigin(new ClassPathResource("foo2.txt"), new Location(1, 2));
    assertThat(origin1.hashCode()).isEqualTo(origin1.hashCode());
    assertThat(origin1.hashCode()).isEqualTo(origin2.hashCode());
    assertThat(origin1.hashCode()).isNotEqualTo(origin3.hashCode());
    assertThat(origin1.hashCode()).isNotEqualTo(origin4.hashCode());
    assertThat(origin1).isEqualTo(origin1);
    assertThat(origin1).isEqualTo(origin2);
    assertThat(origin1).isNotEqualTo(origin3);
    assertThat(origin1).isNotEqualTo(origin4);
}
Also used : ClassPathResource(cn.taketoday.core.io.ClassPathResource) Location(cn.taketoday.origin.TextResourceOrigin.Location) Test(org.junit.jupiter.api.Test)

Example 3 with Location

use of cn.taketoday.origin.TextResourceOrigin.Location in project today-infrastructure by TAKETODAY.

the class TextResourceOriginTests method toStringWhenResourceIsClasspathResourceReturnsToStringWithJar.

@Test
void toStringWhenResourceIsClasspathResourceReturnsToStringWithJar() {
    ClassPathResource resource = new ClassPathResource("foo.txt") {

        @Override
        public URI getURI() throws IOException {
            try {
                return new URI("jar:file:/home/user/project/target/project-0.0.1-SNAPSHOT.jar" + "!/BOOT-INF/classes!/foo.txt");
            } catch (URISyntaxException ex) {
                throw new IllegalStateException(ex);
            }
        }
    };
    Location location = new Location(1, 2);
    TextResourceOrigin origin = new TextResourceOrigin(resource, location);
    assertThat(origin.toString()).isEqualTo("class path resource [foo.txt] from project-0.0.1-SNAPSHOT.jar - 2:3");
}
Also used : URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) ClassPathResource(cn.taketoday.core.io.ClassPathResource) Location(cn.taketoday.origin.TextResourceOrigin.Location) Test(org.junit.jupiter.api.Test)

Example 4 with Location

use of cn.taketoday.origin.TextResourceOrigin.Location in project today-infrastructure by TAKETODAY.

the class OriginTrackedPropertiesLoader method loadValue.

private OriginTrackedValue loadValue(StringBuilder buffer, CharacterReader reader, boolean splitLists) throws IOException {
    buffer.setLength(0);
    while (reader.isWhiteSpace() && !reader.isEndOfLine()) {
        reader.read();
    }
    Location location = reader.getLocation();
    while (!reader.isEndOfLine() && !(splitLists && reader.isListDelimiter())) {
        buffer.append(reader.getCharacter());
        reader.read();
    }
    Origin origin = new TextResourceOrigin(this.resource, location);
    return OriginTrackedValue.of(buffer.toString(), origin);
}
Also used : Origin(cn.taketoday.origin.Origin) TextResourceOrigin(cn.taketoday.origin.TextResourceOrigin) TextResourceOrigin(cn.taketoday.origin.TextResourceOrigin) Location(cn.taketoday.origin.TextResourceOrigin.Location)

Example 5 with Location

use of cn.taketoday.origin.TextResourceOrigin.Location in project today-framework by TAKETODAY.

the class TextResourceOriginTests method toStringReturnsNiceString.

@Test
void toStringReturnsNiceString() {
    ClassPathResource resource = new ClassPathResource("foo.txt");
    Location location = new Location(1, 2);
    TextResourceOrigin origin = new TextResourceOrigin(resource, location);
    assertThat(origin.toString()).isEqualTo("class path resource [foo.txt] - 2:3");
}
Also used : ClassPathResource(cn.taketoday.core.io.ClassPathResource) Location(cn.taketoday.origin.TextResourceOrigin.Location) Test(org.junit.jupiter.api.Test)

Aggregations

Location (cn.taketoday.origin.TextResourceOrigin.Location)20 Test (org.junit.jupiter.api.Test)18 ClassPathResource (cn.taketoday.core.io.ClassPathResource)6 Origin (cn.taketoday.origin.Origin)2 TextResourceOrigin (cn.taketoday.origin.TextResourceOrigin)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2