Skip to content

Commit c850b80

Browse files
committed
Move BridgeUtilTests.
Tests in org.elasticsearch.entitlement.bridge are going to be uniquely hard to test once we patch the bridge into java.base, due to Java's prohibition on split packages. Let's just move this guy to another package.
1 parent 4a8e676 commit c850b80

File tree

2 files changed

+55
-32
lines changed

2 files changed

+55
-32
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
package org.elasticsearch.entitlement;
11+
12+
import org.elasticsearch.entitlement.bridge.Util;
13+
import org.elasticsearch.test.ESTestCase;
14+
15+
import static org.elasticsearch.entitlement.BridgeUtilTests.MockSensitiveClass.mockSensitiveMethod;
16+
17+
/**
18+
* Note: this is not un the bridge package because that is a uniquely bad one to use for tests.
19+
* Since:
20+
* <ol>
21+
* <li>
22+
* we much patch the bridge module into {@code java.base} for it to be reachable
23+
* from JDK methods,
24+
* </li>
25+
* <li>
26+
* the bridge module exports {@code org.elasticsearch.entitlement.bridge}, and
27+
* </li>
28+
* <li>
29+
* Java forbids split packages
30+
* </li>
31+
* </ol>
32+
*
33+
* ...therefore, we'll be unable to load any tests in the {@code org.elasticsearch.entitlement.bridge}
34+
* package from the classpath.
35+
* <p>
36+
* Hence, we put this test in another package. It's still accessible during testing, though,
37+
* because we export the bridge to `ALL-UNNAMED` anyway.
38+
*/
39+
public class BridgeUtilTests extends ESTestCase {
40+
41+
public void testCallerClass() {
42+
assertEquals(BridgeUtilTests.class, mockSensitiveMethod());
43+
}
44+
45+
/**
46+
* A separate class so the stack walk can discern the sensitive method's own class
47+
* from that of its caller.
48+
*/
49+
static class MockSensitiveClass {
50+
public static Class<?> mockSensitiveMethod() {
51+
return Util.getCallerClass();
52+
}
53+
}
54+
55+
}

libs/entitlement/src/test/java/org/elasticsearch/entitlement/bridge/UtilTests.java

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)