2323import com .google .cloud .logging .Payload .StringPayload ;
2424import com .google .common .collect .ImmutableList ;
2525import com .google .common .collect .ImmutableMap ;
26-
2726import java .util .Collections ;
2827import java .util .logging .ErrorManager ;
2928import java .util .logging .Formatter ;
@@ -128,6 +127,8 @@ public class LoggingHandlerTest {
128127 .addLabel ("levelValue" , String .valueOf (LoggingLevel .EMERGENCY .intValue ()))
129128 .setTimestamp (123456789L )
130129 .build ();
130+ private static final WriteOption [] DEFAULT_OPTION =
131+ new WriteOption [] {WriteOption .logName (LOG_NAME ), WriteOption .resource (DEFAULT_RESOURCE )};
131132
132133 private Logging logging ;
133134 private LoggingOptions options ;
@@ -150,7 +151,7 @@ public void setUp() {
150151 public void afterClass () {
151152 EasyMock .verify (logging , options );
152153 }
153-
154+
154155
155156 private static LogRecord newLogRecord (Level level , String message ) {
156157 LogRecord record = new LogRecord (level , message );
@@ -162,44 +163,31 @@ private static LogRecord newLogRecord(Level level, String message) {
162163 public void testPublishLevels () {
163164 EasyMock .expect (options .getProjectId ()).andReturn (PROJECT ).anyTimes ();
164165 EasyMock .expect (options .getService ()).andReturn (logging );
165- logging .writeAsync (ImmutableList .of (FINEST_ENTRY ), WriteOption .logName (LOG_NAME ),
166- WriteOption .resource (DEFAULT_RESOURCE ));
166+ logging .writeAsync (ImmutableList .of (FINEST_ENTRY ), DEFAULT_OPTION );
167167 EasyMock .expectLastCall ().andReturn (ApiFutures .immediateFuture (null ));
168- logging .writeAsync (ImmutableList .of (FINER_ENTRY ), WriteOption .logName (LOG_NAME ),
169- WriteOption .resource (DEFAULT_RESOURCE ));
168+ logging .writeAsync (ImmutableList .of (FINER_ENTRY ), DEFAULT_OPTION );
170169 EasyMock .expectLastCall ().andReturn (ApiFutures .immediateFuture (null ));
171- logging .writeAsync (ImmutableList .of (FINE_ENTRY ), WriteOption .logName (LOG_NAME ),
172- WriteOption .resource (DEFAULT_RESOURCE ));
170+ logging .writeAsync (ImmutableList .of (FINE_ENTRY ), DEFAULT_OPTION );
173171 EasyMock .expectLastCall ().andReturn (ApiFutures .immediateFuture (null ));
174- logging .writeAsync (ImmutableList .of (CONFIG_ENTRY ), WriteOption .logName (LOG_NAME ),
175- WriteOption .resource (DEFAULT_RESOURCE ));
172+ logging .writeAsync (ImmutableList .of (CONFIG_ENTRY ), DEFAULT_OPTION );
176173 EasyMock .expectLastCall ().andReturn (ApiFutures .immediateFuture (null ));
177- logging .writeAsync (ImmutableList .of (INFO_ENTRY ), WriteOption .logName (LOG_NAME ),
178- WriteOption .resource (DEFAULT_RESOURCE ));
174+ logging .writeAsync (ImmutableList .of (INFO_ENTRY ), DEFAULT_OPTION );
179175 EasyMock .expectLastCall ().andReturn (ApiFutures .immediateFuture (null ));
180- logging .writeAsync (ImmutableList .of (WARNING_ENTRY ), WriteOption .logName (LOG_NAME ),
181- WriteOption .resource (DEFAULT_RESOURCE ));
176+ logging .writeAsync (ImmutableList .of (WARNING_ENTRY ), DEFAULT_OPTION );
182177 EasyMock .expectLastCall ().andReturn (ApiFutures .immediateFuture (null ));
183- logging .writeAsync (ImmutableList .of (SEVERE_ENTRY ), WriteOption .logName (LOG_NAME ),
184- WriteOption .resource (DEFAULT_RESOURCE ));
178+ logging .writeAsync (ImmutableList .of (SEVERE_ENTRY ), DEFAULT_OPTION );
185179 EasyMock .expectLastCall ().andReturn (ApiFutures .immediateFuture (null ));
186- logging .writeAsync (ImmutableList .of (DEBUG_ENTRY ), WriteOption .logName (LOG_NAME ),
187- WriteOption .resource (DEFAULT_RESOURCE ));
180+ logging .writeAsync (ImmutableList .of (DEBUG_ENTRY ), DEFAULT_OPTION );
188181 EasyMock .expectLastCall ().andReturn (ApiFutures .immediateFuture (null ));
189- logging .writeAsync (ImmutableList .of (NOTICE_ENTRY ), WriteOption .logName (LOG_NAME ),
190- WriteOption .resource (DEFAULT_RESOURCE ));
182+ logging .writeAsync (ImmutableList .of (NOTICE_ENTRY ), DEFAULT_OPTION );
191183 EasyMock .expectLastCall ().andReturn (ApiFutures .immediateFuture (null ));
192- logging .writeAsync (ImmutableList .of (ERROR_ENTRY ), WriteOption .logName (LOG_NAME ),
193- WriteOption .resource (DEFAULT_RESOURCE ));
184+ logging .writeAsync (ImmutableList .of (ERROR_ENTRY ), DEFAULT_OPTION );
194185 EasyMock .expectLastCall ().andReturn (ApiFutures .immediateFuture (null ));
195- logging .writeAsync (ImmutableList .of (CRITICAL_ENTRY ), WriteOption .logName (LOG_NAME ),
196- WriteOption .resource (DEFAULT_RESOURCE ));
186+ logging .writeAsync (ImmutableList .of (CRITICAL_ENTRY ), DEFAULT_OPTION );
197187 EasyMock .expectLastCall ().andReturn (ApiFutures .immediateFuture (null ));
198- logging .writeAsync (ImmutableList .of (ALERT_ENTRY ), WriteOption .logName (LOG_NAME ),
199- WriteOption .resource (DEFAULT_RESOURCE ));
188+ logging .writeAsync (ImmutableList .of (ALERT_ENTRY ), DEFAULT_OPTION );
200189 EasyMock .expectLastCall ().andReturn (ApiFutures .immediateFuture (null ));
201- logging .writeAsync (ImmutableList .of (EMERGENCY_ENTRY ), WriteOption .logName (LOG_NAME ),
202- WriteOption .resource (DEFAULT_RESOURCE ));
190+ logging .writeAsync (ImmutableList .of (EMERGENCY_ENTRY ), DEFAULT_OPTION );
203191 EasyMock .expectLastCall ().andReturn (ApiFutures .immediateFuture (null ));
204192 EasyMock .replay (options , logging );
205193 Handler handler = new LoggingHandler (LOG_NAME , options );
@@ -263,14 +251,13 @@ public void enhanceLogEntry(Builder builder, LogRecord record) {
263251 handler .setFormatter (new TestFormatter ());
264252 handler .publish (newLogRecord (Level .FINEST , MESSAGE ));
265253 }
266-
254+
267255 @ Test
268256 public void testReportFlushError () {
269257 EasyMock .expect (options .getProjectId ()).andReturn (PROJECT ).anyTimes ();
270258 EasyMock .expect (options .getService ()).andReturn (logging );
271259 RuntimeException ex = new RuntimeException ();
272- logging .writeAsync (ImmutableList .of (FINEST_ENTRY ), WriteOption .logName (LOG_NAME ),
273- WriteOption .resource (DEFAULT_RESOURCE ));
260+ logging .writeAsync (ImmutableList .of (FINEST_ENTRY ), DEFAULT_OPTION );
274261 EasyMock .expectLastCall ().andThrow (ex );
275262 EasyMock .replay (options , logging );
276263 ErrorManager errorManager = EasyMock .createStrictMock (ErrorManager .class );
@@ -309,8 +296,10 @@ public void testReportFormatError() {
309296 public void testFlushSize () {
310297 EasyMock .expect (options .getProjectId ()).andReturn (PROJECT ).anyTimes ();
311298 EasyMock .expect (options .getService ()).andReturn (logging );
312- logging .writeAsync (ImmutableList .of (FINEST_ENTRY , FINER_ENTRY , FINE_ENTRY , CONFIG_ENTRY , INFO_ENTRY ,
313- WARNING_ENTRY ), WriteOption .logName (LOG_NAME ), WriteOption .resource (DEFAULT_RESOURCE ));
299+ logging .writeAsync (
300+ ImmutableList .of (
301+ FINEST_ENTRY , FINER_ENTRY , FINE_ENTRY , CONFIG_ENTRY , INFO_ENTRY , WARNING_ENTRY ),
302+ DEFAULT_OPTION );
314303 EasyMock .expectLastCall ().andReturn (ApiFutures .immediateFuture (null ));
315304 EasyMock .replay (options , logging );
316305 LoggingHandler handler = new LoggingHandler (LOG_NAME , options );
@@ -329,9 +318,10 @@ public void testFlushSize() {
329318 public void testFlushLevel () {
330319 EasyMock .expect (options .getProjectId ()).andReturn (PROJECT ).anyTimes ();
331320 EasyMock .expect (options .getService ()).andReturn (logging );
332- logging .writeAsync (ImmutableList .of (FINEST_ENTRY , FINER_ENTRY , FINE_ENTRY , CONFIG_ENTRY , INFO_ENTRY ,
333- WARNING_ENTRY ), WriteOption .logName (LOG_NAME ),
334- WriteOption .resource (DEFAULT_RESOURCE ));
321+ logging .writeAsync (
322+ ImmutableList .of (
323+ FINEST_ENTRY , FINER_ENTRY , FINE_ENTRY , CONFIG_ENTRY , INFO_ENTRY , WARNING_ENTRY ),
324+ DEFAULT_OPTION );
335325 EasyMock .expectLastCall ().andReturn (ApiFutures .immediateFuture (null ));
336326 EasyMock .replay (options , logging );
337327 LoggingHandler handler = new LoggingHandler (LOG_NAME , options );
@@ -351,8 +341,7 @@ public void testFlushLevel() {
351341 public void testAddHandler () {
352342 EasyMock .expect (options .getProjectId ()).andReturn (PROJECT ).anyTimes ();
353343 EasyMock .expect (options .getService ()).andReturn (logging );
354- logging .writeAsync (ImmutableList .of (FINEST_ENTRY ), WriteOption .logName (LOG_NAME ),
355- WriteOption .resource (DEFAULT_RESOURCE ));
344+ logging .writeAsync (ImmutableList .of (FINEST_ENTRY ), DEFAULT_OPTION );
356345 EasyMock .expectLastCall ().andReturn (ApiFutures .immediateFuture (null ));
357346 EasyMock .replay (options , logging );
358347 LoggingHandler handler = new LoggingHandler (LOG_NAME , options ) {
@@ -373,8 +362,7 @@ public void close() {
373362 public void testClose () throws Exception {
374363 EasyMock .expect (options .getProjectId ()).andReturn (PROJECT ).anyTimes ();
375364 EasyMock .expect (options .getService ()).andReturn (logging );
376- logging .writeAsync (ImmutableList .of (FINEST_ENTRY ), WriteOption .logName (LOG_NAME ),
377- WriteOption .resource (DEFAULT_RESOURCE ));
365+ logging .writeAsync (ImmutableList .of (FINEST_ENTRY ), DEFAULT_OPTION );
378366 EasyMock .expectLastCall ().andReturn (ApiFutures .immediateFuture (null ));
379367 logging .close ();
380368 EasyMock .expectLastCall ().once ();
0 commit comments