Skip to content

Commit

Permalink
fix (build): Re-enable tests after move
Browse files Browse the repository at this point in the history
  • Loading branch information
vorburger committed Apr 16, 2024
1 parent 6b44dce commit 39346c7
Show file tree
Hide file tree
Showing 45 changed files with 198 additions and 143 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ repos:
- --use-current-year
- id: insert-license
files: \.(bash|bazel|textproto|yaml)$
exclude: ^docs/use|core/impl/src/test/resources
exclude: ^docs/use|core/impl/src/test/resources|.*test_resources.*
args:
- --comment-style
- "#"
Expand All @@ -76,7 +76,7 @@ repos:
- --use-current-year
- id: insert-license
files: \.(md|html)$
exclude: ^.github|src/test/resources/|docs/blog/posts/|docs/use/execmd/demo.md
exclude: ^.github|src/test/resources/|docs/blog/posts/|docs/use/execmd/demo.md|.*test_resources.*
args:
- --comment-style
- "<!--| |-->"
Expand Down
36 changes: 0 additions & 36 deletions common/common/BUILD

This file was deleted.

2 changes: 0 additions & 2 deletions common/markdown/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ load("@rules_java//java:defs.bzl", "java_library", "java_test")
java_library(
name = "markdown",
srcs = glob(["src/main/java/**/*.java"]),
resources = glob(["src/main/resources/**/*"]),
visibility = ["//:__subpackages__"],
deps = [
"@maven//:ch_vorburger_exec_exec",
Expand All @@ -32,7 +31,6 @@ java_library(
name = name[:-len(".java")],
size = "small",
srcs = glob(["src/test/java/**/*.java"]),
resources = glob(["src/test/resources/**/*"]),
runtime_deps = [
"@maven//:org_slf4j_slf4j_simple",
],
Expand Down
17 changes: 16 additions & 1 deletion java/dev/enola/common/io/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@rules_java//java:defs.bzl", "java_library", "java_test")
load("@rules_java//java:defs.bzl", "java_library")
load("//tools/bazel:junit.bzl", "junit_tests")

java_library(
name = "io",
Expand All @@ -33,3 +34,17 @@ java_library(
"@maven//:org_slf4j_slf4j_api",
],
)

junit_tests(
name = "tests",
srcs = glob(["**/*Test.java"]),
plugins = ["//tools/bazel/java_plugin:autoservice"],
# TODO Add support for resources with resource_strip_prefix to junit_tests...
resource_strip_prefix = "java/dev/enola/common/io/test_resources",
resources = glob(["test_resources/*"]),
deps = [
":io",
"//java/dev/enola/common/protobuf",
"@maven//:com_google_auto_service_auto_service_annotations",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void testDetect() {

// Test that TestMediaTypes was correctly registered
assertThat(md.detect(null, null, URI.create("whatever:something.test")))
.isEqualTo(TestMediaTypes.TEST);
.isEqualTo(MediaTypesTest.TEST);

// TODO Assert.assertThrows() ?
md.detect(null, null, URI.create("bad-URI-without-scheme"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@

import com.google.common.net.MediaType;

import dev.enola.common.io.resource.TestAbstractResource;
import dev.enola.common.io.resource.AbstractResource;

import org.junit.Test;

import java.net.URI;

public class MediaTypeProviderTest {

TestMediaTypes tmt = new TestMediaTypes();
MediaTypesTest tmt = new MediaTypesTest();

@Test
public void nomatch() {
Expand All @@ -41,21 +41,24 @@ public void nomatch() {
@Test
public void match() {
var uri = URI.create("test:MediaTypeProviderTest");
var resource = new TestAbstractResource(uri, TestMediaTypes.TEST);
assertThat(tmt.detect(resource)).hasValue(TestMediaTypes.TEST);
var resource = new TestAbstractResource(uri, MediaTypesTest.TEST);
assertThat(tmt.detect(resource)).hasValue(MediaTypesTest.TEST);
}

@Test
public void alternative() {
var uri = URI.create("test:MediaTypeProviderTest");
var resource = new TestAbstractResource(uri, TestMediaTypes.TEST_ALTERNATIVE);
assertThat(tmt.detect(resource)).hasValue(TestMediaTypes.TEST);
var resource = new TestAbstractResource(uri, MediaTypesTest.TEST_ALTERNATIVE);
assertThat(tmt.detect(resource)).hasValue(MediaTypesTest.TEST);
}

@Test
public void extension() {
var uri = URI.create("test:MediaTypeProviderTest.test");
var resource = new TestAbstractResource(uri, MediaType.ANY_TYPE);
assertThat(tmt.detect(resource)).hasValue(TestMediaTypes.TEST);
assertThat(tmt.detect(resource)).hasValue(MediaTypesTest.TEST);
}

private static record TestAbstractResource(URI uri, MediaType mediaType)
implements AbstractResource {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,25 @@
import static com.google.common.collect.Sets.newHashSet;
import static com.google.common.truth.Truth.assertThat;

import static dev.enola.common.io.mediatype.TestMediaTypes.TEST;
import static dev.enola.common.io.mediatype.TestMediaTypes.TEST_ALTERNATIVE;

import org.junit.Test;

public class MediaTypeProvidersTest {

@Test
public void empty() {
var mtp = new MediaTypeProviders();
assertThat(mtp.normalize(TEST_ALTERNATIVE)).isEqualTo(TEST_ALTERNATIVE);
assertThat(mtp.normalize(MediaTypesTest.TEST_ALTERNATIVE))
.isEqualTo(MediaTypesTest.TEST_ALTERNATIVE);
assertThat(mtp.extensionsToTypes()).isEmpty();
assertThat(mtp.knownTypesWithAlternatives()).isEmpty();
}

@Test
public void testMediaType() {
var mtp = new MediaTypeProviders(new StandardMediaTypes(), new TestMediaTypes());
assertThat(mtp.normalize(TEST_ALTERNATIVE)).isEqualTo(TEST);
assertThat(mtp.extensionsToTypes()).containsEntry("test", TEST);
var mtp = new MediaTypeProviders(new StandardMediaTypes(), new MediaTypesTest());
assertThat(mtp.normalize(MediaTypesTest.TEST_ALTERNATIVE)).isEqualTo(MediaTypesTest.TEST);
assertThat(mtp.extensionsToTypes()).containsEntry("test", MediaTypesTest.TEST);
assertThat(mtp.knownTypesWithAlternatives())
.containsEntry(TEST, newHashSet(TEST_ALTERNATIVE));
.containsEntry(MediaTypesTest.TEST, newHashSet(MediaTypesTest.TEST_ALTERNATIVE));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,55 +19,62 @@

import static com.google.common.truth.Truth.assertThat;

import com.google.auto.service.AutoService;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Sets;
import com.google.common.net.MediaType;

import org.junit.Test;

public class MediaTypesTest {
import java.util.Map;
import java.util.Set;

@AutoService(MediaTypeProvider.class)
public class MediaTypesTest implements MediaTypeProvider {

@Test
public void testParse() {
assertThat(MediaTypes.parse("application/test")).isEqualTo(TestMediaTypes.TEST);
assertThat(MediaTypes.parse("application/test")).isEqualTo(TEST);
}

@Test
public void testNormalizeMediaTypesParse() {
assertThat(MediaTypes.parse("application/test-alternative")).isEqualTo(TestMediaTypes.TEST);
assertThat(MediaTypes.parse("application/test-alternative")).isEqualTo(TEST);
}

@Test
public void testNormalizeMediaTypeParse() {
assertThat(MediaTypes.normalize(MediaType.parse("application/test-alternative")))
.isEqualTo(TestMediaTypes.TEST);
.isEqualTo(TEST);
}

@Test
public void testNormalizeMediaTypesParseWithCharsetParameter() {
var alternative = MediaTypes.parse("application/test-alternative");
var alternativeWithCharset =
MediaTypes.normalize(alternative.withCharset(Charsets.UTF_16BE));
assertThat(alternativeWithCharset)
.isEqualTo(TestMediaTypes.TEST.withCharset(Charsets.UTF_16BE));
assertThat(alternativeWithCharset).isEqualTo(TEST.withCharset(Charsets.UTF_16BE));
}

@Test
public void testNormalizeMediaTypeParseWithCharsetParameter() {
var alternative = MediaType.parse("application/test-alternative");
assertThat(MediaTypes.normalize(alternative)).isEqualTo(TestMediaTypes.TEST);
assertThat(MediaTypes.normalize(alternative)).isEqualTo(TEST);
assertThat(MediaTypes.normalize(alternative.withCharset(Charsets.UTF_16BE)))
.isEqualTo(TestMediaTypes.TEST.withCharset(Charsets.UTF_16BE));
.isEqualTo(TEST.withCharset(Charsets.UTF_16BE));
}

@Test
public void testToString() {
var mediaType = TestMediaTypes.TEST.withCharset(Charsets.UTF_16BE);
var mediaType = TEST.withCharset(Charsets.UTF_16BE);
assertThat(mediaType.toString()).isEqualTo("application/test; charset=utf-16be");
}

@Test
public void testParseWithCharset() {
var expected = TestMediaTypes.TEST.withCharset(Charsets.UTF_16BE);
var expected = TEST.withCharset(Charsets.UTF_16BE);

// https://www.ietf.org/rfc/rfc2045.txt format:
assertThat(MediaTypes.parse("application/test-alternative; charset=utf-16be"))
Expand All @@ -77,4 +84,22 @@ public void testParseWithCharset() {
assertThat(MediaTypes.parse("application/test-alternative;charset=utf-16be"))
.isEqualTo(expected);
}

// TODO use example/test instead of application/test (and rename accordingly everywhere...)
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types#example

public static final MediaType TEST = MediaType.create("application", "test");

@VisibleForTesting
static final MediaType TEST_ALTERNATIVE = MediaType.create("application", "test-alternative");

@Override
public Map<MediaType, Set<MediaType>> knownTypesWithAlternatives() {
return ImmutableMap.of(TEST, Sets.newHashSet(TEST_ALTERNATIVE));
}

@Override
public Map<String, MediaType> extensionsToTypes() {
return ImmutableMap.of("test", TEST);
}
}
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
12 changes: 11 additions & 1 deletion java/dev/enola/common/protobuf/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@rules_java//java:defs.bzl", "java_library", "java_test")
load("@rules_java//java:defs.bzl", "java_library")
load("//tools/bazel:junit.bzl", "junit_tests")

java_library(
name = "protobuf",
Expand All @@ -32,3 +33,12 @@ java_library(
"@maven//:org_slf4j_slf4j_api",
],
)

junit_tests(
name = "tests",
srcs = glob(["**/*Test.java"]),
deps = [
":protobuf",
"//java/dev/enola/common/io",
],
)
12 changes: 11 additions & 1 deletion java/dev/enola/datatype/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@rules_java//java:defs.bzl", "java_library", "java_test")
load("@rules_java//java:defs.bzl", "java_library")
load("//tools/bazel:junit.bzl", "junit_tests")

java_library(
name = "datatype",
Expand All @@ -31,3 +32,12 @@ java_library(
"@maven//:org_slf4j_slf4j_api",
],
)

junit_tests(
name = "tests",
srcs = glob(["**/*Test.java"]),
deps = [
":datatype",
"//java/dev/enola/common/convert",
],
)
File renamed without changes.

This file was deleted.

Loading

0 comments on commit 39346c7

Please sign in to comment.