jdk

Форк
0
/
AbstractOrInnerClassServiceImplTest.java 
111 строк · 4.5 Кб
1
/*
2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
 *
5
 * This code is free software; you can redistribute it and/or modify it
6
 * under the terms of the GNU General Public License version 2 only, as
7
 * published by the Free Software Foundation.
8
 *
9
 * This code is distributed in the hope that it will be useful, but WITHOUT
10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12
 * version 2 for more details (a copy is included in the LICENSE file that
13
 * accompanied this code).
14
 *
15
 * You should have received a copy of the GNU General Public License version
16
 * 2 along with this work; if not, write to the Free Software Foundation,
17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
 *
19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
 * or visit www.oracle.com if you need additional information or have any
21
 * questions.
22
 */
23

24
/**
25
 * @test 8145016
26
 * @summary Javac doesn't report errors on service implementation which cannot be initialized
27
 * @library /tools/lib
28
 * @modules
29
 *      jdk.compiler/com.sun.tools.javac.api
30
 *      jdk.compiler/com.sun.tools.javac.main
31
 *      jdk.jdeps/com.sun.tools.javap
32
 * @build toolbox.ToolBox toolbox.JavacTask ModuleTestBase
33
 * @run main AbstractOrInnerClassServiceImplTest
34
 */
35

36
import java.nio.file.Files;
37
import java.nio.file.Path;
38

39
import toolbox.JavacTask;
40
import toolbox.Task;
41
import toolbox.ToolBox;
42

43
public class AbstractOrInnerClassServiceImplTest extends ModuleTestBase {
44
    public static void main(String... args) throws Exception {
45
        AbstractOrInnerClassServiceImplTest t = new AbstractOrInnerClassServiceImplTest();
46
        t.runTests();
47
    }
48

49
    @Test
50
    public void testAbstractServiceImpl(Path base) throws Exception {
51
        Path src = base.resolve("src");
52
        tb.writeJavaFiles(src,
53
                "module m { provides p1.Service with p2.Impl; }",
54
                "package p1; public interface Service { }",
55
                "package p2; public interface Impl extends p1.Service { }");
56
        Path classes = base.resolve("classes");
57
        Files.createDirectories(classes);
58

59
        String log = new JavacTask(tb)
60
                .options("-XDrawDiagnostics")
61
                .outdir(classes)
62
                .files(findJavaFiles(src))
63
                .run(Task.Expect.FAIL)
64
                .writeAll()
65
                .getOutput(Task.OutputKind.DIRECT);
66
        if (!log.contains("module-info.java:1:39: compiler.err.service.implementation.is.abstract: p2.Impl"))
67
            throw new Exception("expected output not found");
68
    }
69

70
    @Test
71
    public void testInnerClassServiceImpl(Path base) throws Exception {
72
        Path src = base.resolve("src");
73
        tb.writeJavaFiles(src,
74
                "module m { provides p1.Service with p2.Outer.Inner; }",
75
                "package p1; public interface Service { }",
76
                "package p2; public class Outer { public class Inner implements p1.Service {} }");
77
        Path classes = base.resolve("classes");
78
        Files.createDirectories(classes);
79

80
        String log = new JavacTask(tb)
81
                .options("-XDrawDiagnostics")
82
                .outdir(classes)
83
                .files(findJavaFiles(src))
84
                .run(Task.Expect.FAIL)
85
                .writeAll()
86
                .getOutput(Task.OutputKind.DIRECT);
87
        if (!log.contains("module-info.java:1:45: compiler.err.service.implementation.is.inner: p2.Outer.Inner"))
88
            throw new Exception("expected output not found");
89
    }
90

91
    @Test
92
    public void testInnerInterfaceServiceImpl(Path base) throws Exception {
93
        Path src = base.resolve("src");
94
        tb.writeJavaFiles(src,
95
                "module m { provides p1.Service with p2.Outer.Inner; }",
96
                "package p1; public interface Service { }",
97
                "package p2; public class Outer { public interface Inner extends p1.Service {} }");
98
        Path classes = base.resolve("classes");
99
        Files.createDirectories(classes);
100

101
        String log = new JavacTask(tb)
102
                .options("-XDrawDiagnostics")
103
                .outdir(classes)
104
                .files(findJavaFiles(src))
105
                .run(Task.Expect.FAIL)
106
                .writeAll()
107
                .getOutput(Task.OutputKind.DIRECT);
108
        if (!log.contains("module-info.java:1:45: compiler.err.service.implementation.is.abstract: p2.Outer.Inner"))
109
            throw new Exception("expected output not found");
110
    }
111
}
112

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.