package org.scribe.model; import static org.junit.Assert.*; import org.junit.Test; public class TestToken { @Test public void testValidConstructor() { String token = "Hallo"; String secret = "Hallo2"; Token tok = new Token(token, secret); assertTrue(tok.getToken().equals(token)); assertTrue(tok.getSecret().equals(secret)); } @Test public void testValidConstructorWithRaw() { String token = "Hallo"; String secret = "Hallo2"; String rawResponse = "Hallo3"; Token tok = new Token(token, secret, rawResponse); assertTrue(tok.getToken().equals(token)); assertTrue(tok.getSecret().equals(secret)); assertTrue(tok.getRawResponse().equals(rawResponse)); } @Test public void testEmptyConstructor() { String token = null; String secret = "Hallo"; try { new Token(token, secret); fail("Must not allow instances with empty string in constructor call."); } catch (IllegalArgumentException e) { // this is expected behavior } } @Test public void testEmptyConstructor2() { String token = "Hallo"; String secret = null; try { new Token(token, secret); fail("Must not allow instances with empty string in constructor call."); } catch (IllegalArgumentException e) { // this is expected behavior } } @Test public void testEmptyRawResponse() { String token = "Hallo"; String secret = "Hallo2"; Token tok = new Token(token, secret); try { tok.getRawResponse(); fail("Must not allow calls to this method with null-value provided."); } catch (IllegalStateException e) { // this is expected behavior } } @Test public void testEquals() { String token = "Hallo"; String secret = "Hallo2"; Token tok = new Token(token, secret); assertTrue(tok.equals(tok)); } @Test public void testEquals2() { String token = "Hallo"; String secret = "Hallo2"; Token tok = new Token(token, secret); assertFalse(tok.equals("WhatEver")); } @Test public void testEquals6() { String token = "Hallo"; String secret = "Hallo2"; Token tok = new Token(token, secret); assertFalse(tok.equals(null)); } @Test public void testEquals3() { String token = "Hallo"; String secret = "Hallo2"; Token tok = new Token(token, secret); Token tok2 = new Token(token, secret); assertTrue(tok.equals(tok2)); } @Test public void testEquals4() { String token = "Hallo"; String secret = "Hallo2"; Token tok = new Token(token, secret); Token tok2 = Token.empty(); assertFalse(tok.equals(tok2)); } @Test public void testEquals5() { String token = "Hallo"; String secret = "Hallo2"; Token tok = new Token(token, secret); String token2 = "Other"; String secret2 = "Text"; Token tok2 = new Token(token2, secret2); assertFalse(tok.equals(tok2)); } @Test public void testEmptyToken() { Token tok = Token.empty(); assertTrue(tok.isEmpty()); } @Test public void testEmptyToken2() { String token = "Hallo"; String secret = "Hallo2"; Token tok = new Token(token, secret); assertFalse(tok.isEmpty()); } }