Results 1 to 3 of 3
  1. #1
    tfitz666 is offline Member
    Join Date
    Jul 2009
    Posts
    21
    Rep Power
    0

    Question Help please! .class expected when compiling JUnit test?

    Hi,
    Im fairly new to java programming. I've been given an assignment to write a sorting algorithm and then test it using JUnit tests. The problem is when I try to compile the tester class I get a ".class expected" errors followed by three "; expected" errors for each test method I've written. Any help greatly appreciated!
    Here's my tester code:
    Java Code:
    import static org.junit.Assert.*;
    import org.junit.Test;
     
    public class SorterTester{
        
        // Create new sorter object.
        Sorter sort = new Sorter();
                  
        @Test(timeout=15)
        public void boundaryTest(){
            int[] boundaryInts = { 0, 1, -9999, -1, 9999, 10001, 10000, -10000 };
            int[] correctBoundarySort = { -10000, -9999, -1, 0, 1, 9999, 10000, 10001 };
            assertArrayEquals(int[] correctBoundarySort, int[] sort.sort(boundaryInts));
        }   
        
        /*
         * Test whether the method can sort correctly when multiple numbers are the 
         * same value
         */
        @Test(timeout=15)
        public void duplicateSort(){
            int[] duplicateInts = { 1, 1, -1, -1, -69, - 69, 0, 0, 0, 1000, 1000 };
            int[] correctDuplicateSort = { -69, -69, -1, -1, 0, 0, 0, 1, 1, 1000, 1000};
            assertArrayEquals(int[] correctDuplicateSort, int[] sort.sort(duplicateInts));
        }
        
        /*
         * Tests does the sorter work when an array of only one digit is passed.
         */
        @Test(timeout=15)
        public void singleSort(){
            int[] singleInt = { 8 };
            //Duplicate of singleInt needed because singleInt is always = singleInt
            int[] correctSingleSort = { 8 };
            assertArrayEquals( int[] correctSingleSort, int[] sort.sort( singleInt ));
        }
            
    }

    Here's my sorter code:
    Java Code:
    public class Sorter{
        public void sort( int[] arrayToSort ){
            for( int index = 0; index < arrayToSort.length; index++ ){
                for( int position = index; position < arrayToSort.length; 
                position++ ){
                    if( arrayToSort[ position ] < arrayToSort[ index ] ){
                        int temp = arrayToSort[ index ];
                        arrayToSort[ index ] = arrayToSort[ position ];
                        arrayToSort[ position ] = temp;
                    }    
                }         
            }
        }
    }
    And here's the error I get:
    Java Code:
    javac Sorter.java SorterTester.java 
    SorterTester.java:19: '.class' expected
            assertArrayEquals(int[] correctBoundarySort, int[] sort.sort(boundaryInts));
                                    ^
    SorterTester.java:19: ';' expected
            assertArrayEquals(int[] correctBoundarySort, int[] sort.sort(boundaryInts));
                                                       ^
    SorterTester.java:19: ';' expected
            assertArrayEquals(int[] correctBoundarySort, int[] sort.sort(boundaryInts));
                                                                   ^
    SorterTester.java:19: ';' expected
            assertArrayEquals(int[] correctBoundarySort, int[] sort.sort(boundaryInts));
                                                                                      ^
    SorterTester.java:30: '.class' expected
            assertArrayEquals(int[] correctDuplicateSort, int[] sort.sort(duplicateInts));
                                    ^
    SorterTester.java:30: ';' expected
            assertArrayEquals(int[] correctDuplicateSort, int[] sort.sort(duplicateInts));
                                                        ^
    SorterTester.java:30: ';' expected
            assertArrayEquals(int[] correctDuplicateSort, int[] sort.sort(duplicateInts));
                                                                    ^
    SorterTester.java:30: ';' expected
            assertArrayEquals(int[] correctDuplicateSort, int[] sort.sort(duplicateInts));
                                                                                        ^
    SorterTester.java:41: '.class' expected
            assertArrayEquals( int[] correctSingleSort, int[] sort.sort( singleInt ));
                                     ^
    SorterTester.java:41: ';' expected
            assertArrayEquals( int[] correctSingleSort, int[] sort.sort( singleInt ));
                                                      ^
    SorterTester.java:41: ';' expected
            assertArrayEquals( int[] correctSingleSort, int[] sort.sort( singleInt ));
                                                                  ^
    SorterTester.java:41: ';' expected
            assertArrayEquals( int[] correctSingleSort, int[] sort.sort( singleInt ));
                                                                                    ^
    12 errors
    Im sorry if this is somethign really obvious but im stumped, I posted this in another java forum a few days ago but it seems no one could help.
    Thanks in advance.
    Last edited by tfitz666; 12-31-2009 at 12:26 PM. Reason: mistake

  2. #2
    r035198x is offline Senior Member
    Join Date
    Aug 2009
    Posts
    2,388
    Rep Power
    7

    Default

    In assertArrayEquals(int[] correctBoundarySort, int[] sort.sort(boundaryInts));, you just want to pass the existing arrays not define new ones. You use the
    Java Code:
     int[] correctBoundarySort
    syntax to declare new arrays. To pass the arrays that you have just use

    Java Code:
    assertArrayEquals(correctBoundarySort, sort.sort(boundaryInts));

  3. #3
    tfitz666 is offline Member
    Join Date
    Jul 2009
    Posts
    21
    Rep Power
    0

    Default

    Thanks very much for the quick response. That fixed it! I have some new different errors now, but I think I can fix them myself. Thanks again!

Similar Threads

  1. Replies: 1
    Last Post: 08-03-2009, 05:31 PM
  2. how to use junit for a java class in netbeans
    By venkatakrishna.chaithanya in forum New To Java
    Replies: 0
    Last Post: 07-15-2009, 06:41 AM
  3. JUnit Test Help!
    By pharo in forum New To Java
    Replies: 0
    Last Post: 04-10-2009, 05:15 PM
  4. Junit test
    By alice in forum New To Java
    Replies: 1
    Last Post: 06-14-2008, 01:24 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •