/*
 * Copyright (c) 2008-2012 Tomas Varaneckas
 * http://www.varaneckas.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.googlecode.gmail4j.test.rss;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test;

import com.googlecode.gmail4j.GmailConnection;
import com.googlecode.gmail4j.GmailMessage;
import com.googlecode.gmail4j.auth.Credentials;
import com.googlecode.gmail4j.http.HttpGmailConnection;
import com.googlecode.gmail4j.http.ProxyAware;
import com.googlecode.gmail4j.rss.RssGmailClient;
import com.googlecode.gmail4j.test.TestConfigurer;

/**
 * {@link RssGmailClient} tests
 * 
 * @see RssGmailClient
 * @see Credentials
 * @see TestConfigurer
 * @author Tomas Varaneckas &lt;tomas.varaneckas@gmail.com&gt;
 */
public class RssGmailClientTest {

    /**
     * Logger
     */
    private static final Log log = LogFactory.getLog(RssGmailClientTest.class);

    /**
     * Tests retrieval of unread messages
     */
    @Test
    public void testGetUnreadMessages() {
        try {
            TestConfigurer conf = TestConfigurer.getInstance();            
            final RssGmailClient client = new RssGmailClient();
            final GmailConnection connection = new HttpGmailConnection();
            connection.setLoginCredentials(conf.getGmailCredentials());
            if (conf.useProxy()) {
                ((ProxyAware) connection).setProxy(conf.getProxyHost(), 
                        conf.getProxyPort());
                ((ProxyAware) connection).setProxyCredentials(
                        conf.getProxyCredentials());
            }
            log.debug("Getting unread messages");
            client.setConnection(connection);
            final List<GmailMessage> messages = client.getUnreadMessages();
            for (GmailMessage message : messages) {
                log.debug(message);
            }
            assertNotNull("Messages are not null", messages);
        } catch (final Exception e) {
            log.error("Test Failed", e);
            fail("Caught exception: " + e.getMessage());
        }
    }
    
}

@@ -866,16 +866,65 @@
 actory;%0A
+import org.junit.After;%0Aimport org.junit.Before;%0A
 import o
@@ -1605,76 +1605,63 @@
 s);%0A
-%0A
     
-/**%0A     * Tests retrieval of unread messages%0A 
+private RssGmailClient client;    %0A
     
-*/
 %0A    @
-Test
+Before
 %0A   
@@ -1677,52 +1677,20 @@
 oid 
-testGetUnreadMessages() %7B%0A        try %7B%0A    
+connect() %7B%0A
     
@@ -1769,33 +1769,8 @@
     
-    final RssGmailClient 
 clie
@@ -1800,28 +1800,24 @@
 ();%0A        
-   
- 
 final GmailC
@@ -1874,20 +1874,16 @@
         
-    
 connecti
@@ -1942,20 +1942,16 @@
         
-  
-  
 if (conf
@@ -1961,28 +1961,24 @@
 eProxy()) %7B%0A
-    
             
@@ -2046,36 +2046,32 @@
                 
- 
-   
 conf.getProxyPor
@@ -2072,28 +2072,24 @@
 oxyPort());%0A
-    
             
@@ -2147,36 +2147,32 @@
                 
-    
 conf.getProxyCre
@@ -2183,38 +2183,321 @@
 ials());%0A       
+ %7D%0A
      
-%7D
+   client.setConnection(connection);    %09%0A    %7D%0A    %0A    @After%0A    public void disconnect() %7B%0A    %09if (client != null)%0A    %09%09client.disconnect();%0A    %7D%0A    %0A    /**%0A     * Tests retrieval of unread messages%0A     */%0A    @Test%0A    public void testGetUnreadMessages() %7B%0A        try %7B
 %0A            log
@@ -2535,53 +2535,8 @@
 %22);%0A
-            client.setConnection(connection);
 %0A   

Use JUnit @before and @after in RssGmailClientTest