package net.dean.jraw.test.auth;

import net.dean.jraw.ApiException;
import net.dean.jraw.OAuth2RedditClient;
import net.dean.jraw.http.Credentials;
import net.dean.jraw.http.NetworkException;
import org.testng.annotations.Test;

public class OAuth2Test extends AuthenticatedRedditTest {
    private OAuth2RedditClient redditOAuth;

    public OAuth2Test() {
        this.redditOAuth = new OAuth2RedditClient(getUserAgent(getClass()));
    }

    @Test
    public void testLoginScript() {
        Credentials creds = getCredentials();
        try {
            validateModel(redditOAuth.login(Credentials.oauth2Script(
                    creds.getUsername(),
                    creds.getPassword(),
                    creds.getClientId(),
                    creds.getClientSecret())));
        } catch (NetworkException | ApiException e) {
            handle(e);
        }
    }
}

@@ -107,47 +107,8 @@
 nt;%0A
-import net.dean.jraw.http.Credentials;%0A
 impo
@@ -398,85 +398,48 @@
     
-%7D%0A%0A
     
-@Test%0A    public void testLoginScript() %7B%0A        Credentials creds = 
+try %7B%0A            redditOAuth.login(
 getC
@@ -450,16 +450,17 @@
 ntials()
+)
 ;%0A      
@@ -465,124 +465,76 @@
     
-try %7B%0A            validateModel(redditOAuth.login(Credentials.oauth2Script(%0A                    creds.getUsername(),
+%7D catch (NetworkException %7C ApiException e) %7B%0A            handle(e);
 %0A   
@@ -542,40 +542,62 @@
     
+%7D%0A
     
+%7D%0A%0A
     
-    creds.getPassword(),
+@Test%0A    public void testLoginScript() %7B
 %0A   
@@ -593,33 +593,38 @@
 ipt() %7B%0A        
- 
+try %7B%0A
            creds
@@ -622,72 +622,90 @@
     
-creds.getClientId(),%0A                    creds.getClientSecret()
+ redditOAuth.logout();%0A            validateModel(redditOAuth.login(getCredentials(
 )));

Simplify OAuth2Test login