|
| 1 | +/* |
| 2 | + * Copyright 2023 Red Hat, Inc. and/or its affiliates |
| 3 | + * and other contributors as indicated by the @author tags. |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | + |
| 19 | +package com.redhat.exhort.api; |
| 20 | + |
| 21 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 22 | +import static org.junit.jupiter.api.Assertions.assertNull; |
| 23 | + |
| 24 | +import org.junit.jupiter.api.Test; |
| 25 | + |
| 26 | +public class PackageRefTest { |
| 27 | + |
| 28 | + @Test |
| 29 | + public void testNamespace() { |
| 30 | + PackageRef ref = |
| 31 | + new PackageRef("pkg:golang/google.golang.org/genproto#googleapis/api/annotations"); |
| 32 | + assertEquals("google.golang.org/genproto", ref.name()); |
| 33 | + |
| 34 | + ref = new PackageRef( "pkg:golang/[email protected]"); |
| 35 | + assertEquals("go.opencensus.io", ref.name()); |
| 36 | + |
| 37 | + ref = new PackageRef( "pkg:npm/[email protected]"); |
| 38 | + assertEquals("foobar", ref.name()); |
| 39 | + |
| 40 | + ref = new PackageRef( "pkg:maven/org.apache.xmlgraphics/[email protected]?packaging=sources"); |
| 41 | + assertEquals("org.apache.xmlgraphics:batik-anim", ref.name()); |
| 42 | + } |
| 43 | + |
| 44 | + @Test |
| 45 | + public void testVersion() { |
| 46 | + PackageRef ref = |
| 47 | + new PackageRef("pkg:golang/google.golang.org/genproto#googleapis/api/annotations"); |
| 48 | + assertNull(ref.version()); |
| 49 | + |
| 50 | + ref = new PackageRef( "pkg:golang/[email protected]"); |
| 51 | + assertEquals("v0.21.0", ref.version()); |
| 52 | + } |
| 53 | +} |
0 commit comments