Skip to content

Commit 6697160

Browse files
author
Eirik Bjørsnøs
committed
8320712: Rewrite BadFactoryTest in pure Java
Reviewed-by: jpai, sundar
1 parent 725314f commit 6697160

File tree

2 files changed

+26
-62
lines changed

2 files changed

+26
-62
lines changed

test/jdk/javax/script/JDK_8196959/BadFactoryTest.java

+26-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -21,10 +21,34 @@
2121
* questions.
2222
*/
2323

24+
import org.junit.jupiter.api.Test;
25+
26+
import javax.script.ScriptEngineFactory;
2427
import javax.script.ScriptEngineManager;
28+
import java.util.Optional;
29+
30+
import static org.junit.jupiter.api.Assertions.assertTrue;
2531

32+
/*
33+
* @test
34+
* @bug 8196959 8320712
35+
* @summary Verify that ScriptEngineManager can load BadFactory without throwing NPE
36+
* @build BadFactory BadFactoryTest
37+
* @run junit/othervm BadFactoryTest
38+
* @run junit/othervm -Djava.security.manager=allow BadFactoryTest
39+
*/
2640
public class BadFactoryTest {
27-
public static void main(String[] args) {
41+
42+
@Test
43+
public void scriptEngineManagerShouldLoadBadFactory() {
44+
// Check that ScriptEngineManager initializes even in the
45+
// presence of a ScriptEngineFactory returning nulls
2846
ScriptEngineManager m = new ScriptEngineManager();
47+
48+
// Sanity check that ScriptEngineManager actually found the BadFactory
49+
Optional<ScriptEngineFactory> badFactory = m.getEngineFactories().stream()
50+
.filter(fac -> fac.getClass() == BadFactory.class)
51+
.findAny();
52+
assertTrue(badFactory.isPresent(), "BadFactory not found");
2953
}
3054
}

test/jdk/javax/script/JDK_8196959/BadFactoryTest.sh

-60
This file was deleted.

0 commit comments

Comments
 (0)