package com.blogspot.aptgetmoo.dhjclient.test.company;

import java.net.MalformedURLException;

import junit.framework.TestCase;

import com.blogspot.aptgetmoo.dhjclient.company.CompanyPage;
import com.blogspot.aptgetmoo.dhjclient.parser.Webpage;

public class CompanyPageTest extends TestCase {

    private static final String COMP_CODE_1 = "COMP-CODE-1234";

    public void testConstructor() {
        Webpage page = new CompanyPage(COMP_CODE_1);

        assertNotNull(page);
    }

    public void testConstructorWithValidUrl() {
        final String validUrl = "http://www.google.com";
        Webpage page;

        try {
            page = new CompanyPage(validUrl, COMP_CODE_1);
            assertNotNull(page);
        } catch (MalformedURLException e) {
            fail("Unexpected MalformedURLException");
        }
    }

    public void testConstructorWithInvalidUrl() {
        final String invalidUrl = "invalidUrl";

        try {
            new CompanyPage(invalidUrl, COMP_CODE_1);
            fail("Expected MalformedURLException");
        } catch (MalformedURLException e) {}
    }

    public void testGetBaseUrlDefault() {
        Webpage page = new CompanyPage(COMP_CODE_1);

        assertNotNull(page.getBaseUrl());
    }

    public void testGetBaseUrlCustom() {
        final String validUrl = "http://www.google.com";
        Webpage page;

        try {
            page = new CompanyPage(validUrl, COMP_CODE_1);
            assertEquals(validUrl, page.getBaseUrl());
        } catch (MalformedURLException e) {
            fail("Unexpected MalformedURLException");
        }
    }

    public void testGetUrlDefault() {
        Webpage page = new CompanyPage(COMP_CODE_1);
        final String baseUrl = page.getBaseUrl();
        final String url = page.getUrl();

        assertFalse(baseUrl.compareTo(url) == 0);
        assertTrue(url.startsWith(baseUrl));
    }

    public void testGetUrlDefaultCustom() {
        final String validUrl = "http://www.google.com";
        Webpage page;

        try {
            page = new CompanyPage(validUrl, COMP_CODE_1);
            final String baseUrl = page.getBaseUrl();
            final String url = page.getUrl();

            assertEquals(validUrl, baseUrl);
            assertFalse(baseUrl.compareTo(url) == 0);
            assertTrue(url.startsWith(baseUrl));
        } catch (MalformedURLException e) {
            fail("Unexpected MalformedURLException");
        }
    }

    public void testGetCompanyCode() {
        Webpage page = new CompanyPage(COMP_CODE_1);

        assertEquals(COMP_CODE_1, ((CompanyPage) page).getCompanyCode());
    }

    public void testGetCompanyCodeCustome() {
        final String validUrl = "http://www.google.com";

        Webpage page;
        try {
            page = new CompanyPage(validUrl, COMP_CODE_1);
            assertEquals(COMP_CODE_1, ((CompanyPage) page).getCompanyCode());
        } catch (MalformedURLException e) {
            fail("Unexpected MalformedURLException");
        }
    }

}

@@ -49,16 +49,232 @@
 mpany;%0A%0A
+import static org.junit.Assert.assertEquals;%0Aimport static org.junit.Assert.assertFalse;%0Aimport static org.junit.Assert.assertNotNull;%0Aimport static org.junit.Assert.assertTrue;%0Aimport static org.junit.Assert.fail;%0A%0A
 import j
@@ -316,32 +316,22 @@
 ort 
+org.
 junit.
-framework.TestCase
+Test
 ;%0A%0Ai
@@ -480,25 +480,8 @@
 est 
-extends TestCase 
 %7B%0A%0A 
@@ -544,24 +544,30 @@
 1234%22;%0A%0A    
+@Test 
 public void 
@@ -672,32 +672,38 @@
 ge);%0A    %7D%0A%0A    
+@Test 
 public void test
@@ -1027,32 +1027,38 @@
    %7D%0A    %7D%0A%0A    
+@Test 
 public void test
@@ -1304,32 +1304,38 @@
 ) %7B%7D%0A    %7D%0A%0A    
+@Test 
 public void test
@@ -1455,32 +1455,38 @@
 ());%0A    %7D%0A%0A    
+@Test 
 public void test
@@ -1825,32 +1825,38 @@
    %7D%0A    %7D%0A%0A    
+@Test 
 public void test
@@ -2117,32 +2117,38 @@
 l));%0A    %7D%0A%0A    
+@Test 
 public void test
@@ -2684,32 +2684,38 @@
    %7D%0A    %7D%0A%0A    
+@Test 
 public void test
@@ -2872,16 +2872,22 @@
  %7D%0A%0A    
+@Test 
 public v

Update CompanyPageTest to use junit 4.10