@@ -53,6 +53,7 @@ public class LoggingHandlerTest {
53
53
private static final String LOG_NAME = "java.log" ;
54
54
private static final String MESSAGE = "message" ;
55
55
private static final String PROJECT = "project" ;
56
+ private static final String PROJECT_ENV_NAME = "GOOGLE_CLOUD_PROJECT" ;
56
57
57
58
private static final MonitoredResource DEFAULT_RESOURCE =
58
59
MonitoredResource .of ("global" , ImmutableMap .of ("project_id" , PROJECT ));
@@ -224,15 +225,15 @@ private static LogRecord newLogRecord(Level level, String message) {
224
225
225
226
@ Test
226
227
public void testDefaultHandlerCreation () {
227
- // mocks behavior of MonitoredResourceUtil which is used by LoggingOptions.getDefaultInstance()
228
- // static method
229
- ResourceTypeEnvironmentGetter getterMock =
230
- EasyMock .createMock (ResourceTypeEnvironmentGetter .class );
231
- expect (getterMock .getAttribute ("project/project-id" )).andReturn (PROJECT );
232
- expect (getterMock .getAttribute ("" )).andStubReturn (null );
233
- MonitoredResourceUtil .setEnvironmentGetter (getterMock );
234
- replay (options , logging , getterMock );
228
+ String oldProject = System .getProperty (PROJECT_ENV_NAME );
229
+ System .setProperty (PROJECT_ENV_NAME , PROJECT );
230
+ replay (options , logging );
235
231
assertNotNull (new LoggingHandler ());
232
+ if (oldProject != null ) {
233
+ System .setProperty (PROJECT_ENV_NAME , oldProject );
234
+ } else {
235
+ System .clearProperty (PROJECT_ENV_NAME );
236
+ }
236
237
}
237
238
238
239
@ Test
0 commit comments