3636import org .apache .gravitino .NameIdentifier ;
3737import org .apache .gravitino .UserPrincipal ;
3838import org .apache .gravitino .authorization .AuthorizationRequestContext ;
39+ import org .apache .gravitino .authorization .AuthorizationUtils ;
3940import org .apache .gravitino .authorization .GravitinoAuthorizer ;
4041import org .apache .gravitino .authorization .Privilege ;
4142import org .apache .gravitino .dto .responses .ErrorResponse ;
@@ -147,14 +148,12 @@ public void testSystemInternalErrorHandling() throws Throwable {
147148 }
148149
149150 @ Test
150- public void testMetalakeNotExistOrNotInUse () throws Throwable {
151+ public void testMetalakeNotExist () throws Throwable {
151152 try (MockedStatic <PrincipalUtils > principalUtilsMocked = mockStatic (PrincipalUtils .class );
152153 MockedStatic <GravitinoAuthorizerProvider > authorizerMocked =
153154 mockStatic (GravitinoAuthorizerProvider .class );
154- MockedStatic <org .apache .gravitino .GravitinoEnv > envMocked =
155- mockStatic (org .apache .gravitino .GravitinoEnv .class );
156- MockedStatic <org .apache .gravitino .metalake .MetalakeManager > metalakeManagerMocked =
157- mockStatic (org .apache .gravitino .metalake .MetalakeManager .class )) {
155+ MockedStatic <AuthorizationUtils > authorizationUtilsMocked =
156+ mockStatic (AuthorizationUtils .class )) {
158157
159158 principalUtilsMocked
160159 .when (PrincipalUtils ::getCurrentPrincipal )
@@ -166,14 +165,12 @@ public void testMetalakeNotExistOrNotInUse() throws Throwable {
166165 authorizerMocked .when (GravitinoAuthorizerProvider ::getInstance ).thenReturn (mockedProvider );
167166 when (mockedProvider .getGravitinoAuthorizer ()).thenReturn (new MockGravitinoAuthorizer ());
168167
169- GravitinoEnv mockEnv = mock (GravitinoEnv .class );
170- EntityStore mockStore = mock (EntityStore .class );
171- envMocked .when (GravitinoEnv ::getInstance ).thenReturn (mockEnv );
172- when (mockEnv .entityStore ()).thenReturn (mockStore );
173-
174- // Mock MetalakeManager.checkMetalake to throw NoSuchMetalakeException
175- metalakeManagerMocked
176- .when (() -> MetalakeManager .checkMetalake (ArgumentMatchers .any (), ArgumentMatchers .any ()))
168+ // Mock AuthorizationUtils.checkCurrentUser to throw NoSuchMetalakeException
169+ authorizationUtilsMocked
170+ .when (
171+ () ->
172+ AuthorizationUtils .checkCurrentUser (
173+ ArgumentMatchers .any (), ArgumentMatchers .any ()))
177174 .thenThrow (new NoSuchMetalakeException ("Metalake nonExistentMetalake does not exist" ));
178175
179176 GravitinoInterceptionService gravitinoInterceptionService =
0 commit comments