@@ -159,6 +159,8 @@ public class LoggingHandlerTest {
159159 .append ("com.google.cloud.logging.LoggingHandler.synchronicity=SYNC" )
160160 .append (System .lineSeparator ())
161161 .toString ();
162+ private static final WriteOption [] DEFAULT_OPTIONS =
163+ new WriteOption [] {WriteOption .logName (LOG_NAME ), WriteOption .resource (DEFAULT_RESOURCE )};
162164
163165 private Logging logging ;
164166 private LoggingOptions options ;
@@ -200,7 +202,7 @@ public void setUp() {
200202 public void afterClass () {
201203 EasyMock .verify (logging , options );
202204 }
203-
205+
204206
205207 private static LogRecord newLogRecord (Level level , String message ) {
206208 LogRecord record = new LogRecord (level , message );
@@ -212,44 +214,31 @@ private static LogRecord newLogRecord(Level level, String message) {
212214 public void testPublishLevels () {
213215 EasyMock .expect (options .getProjectId ()).andReturn (PROJECT ).anyTimes ();
214216 EasyMock .expect (options .getService ()).andReturn (logging );
215- logging .writeAsync (ImmutableList .of (FINEST_ENTRY ), WriteOption .logName (LOG_NAME ),
216- WriteOption .resource (DEFAULT_RESOURCE ));
217+ logging .writeAsync (ImmutableList .of (FINEST_ENTRY ), DEFAULT_OPTIONS );
217218 EasyMock .expectLastCall ().andReturn (ApiFutures .immediateFuture (null ));
218- logging .writeAsync (ImmutableList .of (FINER_ENTRY ), WriteOption .logName (LOG_NAME ),
219- WriteOption .resource (DEFAULT_RESOURCE ));
219+ logging .writeAsync (ImmutableList .of (FINER_ENTRY ), DEFAULT_OPTIONS );
220220 EasyMock .expectLastCall ().andReturn (ApiFutures .immediateFuture (null ));
221- logging .writeAsync (ImmutableList .of (FINE_ENTRY ), WriteOption .logName (LOG_NAME ),
222- WriteOption .resource (DEFAULT_RESOURCE ));
221+ logging .writeAsync (ImmutableList .of (FINE_ENTRY ), DEFAULT_OPTIONS );
223222 EasyMock .expectLastCall ().andReturn (ApiFutures .immediateFuture (null ));
224- logging .writeAsync (ImmutableList .of (CONFIG_ENTRY ), WriteOption .logName (LOG_NAME ),
225- WriteOption .resource (DEFAULT_RESOURCE ));
223+ logging .writeAsync (ImmutableList .of (CONFIG_ENTRY ), DEFAULT_OPTIONS );
226224 EasyMock .expectLastCall ().andReturn (ApiFutures .immediateFuture (null ));
227- logging .writeAsync (ImmutableList .of (INFO_ENTRY ), WriteOption .logName (LOG_NAME ),
228- WriteOption .resource (DEFAULT_RESOURCE ));
225+ logging .writeAsync (ImmutableList .of (INFO_ENTRY ), DEFAULT_OPTIONS );
229226 EasyMock .expectLastCall ().andReturn (ApiFutures .immediateFuture (null ));
230- logging .writeAsync (ImmutableList .of (WARNING_ENTRY ), WriteOption .logName (LOG_NAME ),
231- WriteOption .resource (DEFAULT_RESOURCE ));
227+ logging .writeAsync (ImmutableList .of (WARNING_ENTRY ), DEFAULT_OPTIONS );
232228 EasyMock .expectLastCall ().andReturn (ApiFutures .immediateFuture (null ));
233- logging .writeAsync (ImmutableList .of (SEVERE_ENTRY ), WriteOption .logName (LOG_NAME ),
234- WriteOption .resource (DEFAULT_RESOURCE ));
229+ logging .writeAsync (ImmutableList .of (SEVERE_ENTRY ), DEFAULT_OPTIONS );
235230 EasyMock .expectLastCall ().andReturn (ApiFutures .immediateFuture (null ));
236- logging .writeAsync (ImmutableList .of (DEBUG_ENTRY ), WriteOption .logName (LOG_NAME ),
237- WriteOption .resource (DEFAULT_RESOURCE ));
231+ logging .writeAsync (ImmutableList .of (DEBUG_ENTRY ), DEFAULT_OPTIONS );
238232 EasyMock .expectLastCall ().andReturn (ApiFutures .immediateFuture (null ));
239- logging .writeAsync (ImmutableList .of (NOTICE_ENTRY ), WriteOption .logName (LOG_NAME ),
240- WriteOption .resource (DEFAULT_RESOURCE ));
233+ logging .writeAsync (ImmutableList .of (NOTICE_ENTRY ), DEFAULT_OPTIONS );
241234 EasyMock .expectLastCall ().andReturn (ApiFutures .immediateFuture (null ));
242- logging .writeAsync (ImmutableList .of (ERROR_ENTRY ), WriteOption .logName (LOG_NAME ),
243- WriteOption .resource (DEFAULT_RESOURCE ));
235+ logging .writeAsync (ImmutableList .of (ERROR_ENTRY ), DEFAULT_OPTIONS );
244236 EasyMock .expectLastCall ().andReturn (ApiFutures .immediateFuture (null ));
245- logging .writeAsync (ImmutableList .of (CRITICAL_ENTRY ), WriteOption .logName (LOG_NAME ),
246- WriteOption .resource (DEFAULT_RESOURCE ));
237+ logging .writeAsync (ImmutableList .of (CRITICAL_ENTRY ), DEFAULT_OPTIONS );
247238 EasyMock .expectLastCall ().andReturn (ApiFutures .immediateFuture (null ));
248- logging .writeAsync (ImmutableList .of (ALERT_ENTRY ), WriteOption .logName (LOG_NAME ),
249- WriteOption .resource (DEFAULT_RESOURCE ));
239+ logging .writeAsync (ImmutableList .of (ALERT_ENTRY ), DEFAULT_OPTIONS );
250240 EasyMock .expectLastCall ().andReturn (ApiFutures .immediateFuture (null ));
251- logging .writeAsync (ImmutableList .of (EMERGENCY_ENTRY ), WriteOption .logName (LOG_NAME ),
252- WriteOption .resource (DEFAULT_RESOURCE ));
241+ logging .writeAsync (ImmutableList .of (EMERGENCY_ENTRY ), DEFAULT_OPTIONS );
253242 EasyMock .expectLastCall ().andReturn (ApiFutures .immediateFuture (null ));
254243 EasyMock .replay (options , logging );
255244 Handler handler = new LoggingHandler (LOG_NAME , options );
@@ -313,14 +302,13 @@ public void enhanceLogEntry(Builder builder, LogRecord record) {
313302 handler .setFormatter (new TestFormatter ());
314303 handler .publish (newLogRecord (Level .FINEST , MESSAGE ));
315304 }
316-
305+
317306 @ Test
318307 public void testReportFlushError () {
319308 EasyMock .expect (options .getProjectId ()).andReturn (PROJECT ).anyTimes ();
320309 EasyMock .expect (options .getService ()).andReturn (logging );
321310 RuntimeException ex = new RuntimeException ();
322- logging .writeAsync (ImmutableList .of (FINEST_ENTRY ), WriteOption .logName (LOG_NAME ),
323- WriteOption .resource (DEFAULT_RESOURCE ));
311+ logging .writeAsync (ImmutableList .of (FINEST_ENTRY ), DEFAULT_OPTIONS );
324312 EasyMock .expectLastCall ().andThrow (ex );
325313 EasyMock .replay (options , logging );
326314 ErrorManager errorManager = EasyMock .createStrictMock (ErrorManager .class );
@@ -359,8 +347,10 @@ public void testReportFormatError() {
359347 public void testFlushSize () {
360348 EasyMock .expect (options .getProjectId ()).andReturn (PROJECT ).anyTimes ();
361349 EasyMock .expect (options .getService ()).andReturn (logging );
362- logging .writeAsync (ImmutableList .of (FINEST_ENTRY , FINER_ENTRY , FINE_ENTRY , CONFIG_ENTRY , INFO_ENTRY ,
363- WARNING_ENTRY ), WriteOption .logName (LOG_NAME ), WriteOption .resource (DEFAULT_RESOURCE ));
350+ logging .writeAsync (
351+ ImmutableList .of (
352+ FINEST_ENTRY , FINER_ENTRY , FINE_ENTRY , CONFIG_ENTRY , INFO_ENTRY , WARNING_ENTRY ),
353+ DEFAULT_OPTIONS );
364354 EasyMock .expectLastCall ().andReturn (ApiFutures .immediateFuture (null ));
365355 EasyMock .replay (options , logging );
366356 LoggingHandler handler = new LoggingHandler (LOG_NAME , options );
@@ -379,9 +369,10 @@ public void testFlushSize() {
379369 public void testFlushLevel () {
380370 EasyMock .expect (options .getProjectId ()).andReturn (PROJECT ).anyTimes ();
381371 EasyMock .expect (options .getService ()).andReturn (logging );
382- logging .writeAsync (ImmutableList .of (FINEST_ENTRY , FINER_ENTRY , FINE_ENTRY , CONFIG_ENTRY , INFO_ENTRY ,
383- WARNING_ENTRY ), WriteOption .logName (LOG_NAME ),
384- WriteOption .resource (DEFAULT_RESOURCE ));
372+ logging .writeAsync (
373+ ImmutableList .of (
374+ FINEST_ENTRY , FINER_ENTRY , FINE_ENTRY , CONFIG_ENTRY , INFO_ENTRY , WARNING_ENTRY ),
375+ DEFAULT_OPTIONS );
385376 EasyMock .expectLastCall ().andReturn (ApiFutures .immediateFuture (null ));
386377 EasyMock .replay (options , logging );
387378 LoggingHandler handler = new LoggingHandler (LOG_NAME , options );
@@ -426,8 +417,7 @@ public void testSyncWrite() {
426417 public void testAddHandler () {
427418 EasyMock .expect (options .getProjectId ()).andReturn (PROJECT ).anyTimes ();
428419 EasyMock .expect (options .getService ()).andReturn (logging );
429- logging .writeAsync (ImmutableList .of (FINEST_ENTRY ), WriteOption .logName (LOG_NAME ),
430- WriteOption .resource (DEFAULT_RESOURCE ));
420+ logging .writeAsync (ImmutableList .of (FINEST_ENTRY ), DEFAULT_OPTIONS );
431421 EasyMock .expectLastCall ().andReturn (ApiFutures .immediateFuture (null ));
432422 EasyMock .replay (options , logging );
433423 LoggingHandler handler = new LoggingHandler (LOG_NAME , options ) {
@@ -483,15 +473,14 @@ public void testPropertiesFile() throws IOException, InterruptedException {
483473 assertEquals (LoggingLevel .CRITICAL , handler .getFlushLevel ());
484474 assertEquals (Synchronicity .SYNC , handler .getSynchronicity ());
485475
486- LogManager .getLogManager ().readConfiguration ();
476+ LogManager .getLogManager ().reset ();
487477 }
488478
489479 @ Test
490480 public void testClose () throws Exception {
491481 EasyMock .expect (options .getProjectId ()).andReturn (PROJECT ).anyTimes ();
492482 EasyMock .expect (options .getService ()).andReturn (logging );
493- logging .writeAsync (ImmutableList .of (FINEST_ENTRY ), WriteOption .logName (LOG_NAME ),
494- WriteOption .resource (DEFAULT_RESOURCE ));
483+ logging .writeAsync (ImmutableList .of (FINEST_ENTRY ), DEFAULT_OPTIONS );
495484 EasyMock .expectLastCall ().andReturn (ApiFutures .immediateFuture (null ));
496485 logging .close ();
497486 EasyMock .expectLastCall ().once ();
0 commit comments