Create a testclass

Hi all,
I am trying to create a testclass which tests the methods of a notebook.
Everything but the testmethod testZeigeNotiz (show note) works.
Does anybody knows the reason ?
Here is my code :
* The test class NotizbuchTest.
* @author  (your name)
* @version (a version number or a date)
public class NotizbuchTest extends junit.framework.TestCase
    private Notizbuch _notiz;
     * Default constructor for test class NotizbuchTest
    public NotizbuchTest()
        _notiz = new Notizbuch();
     * Sets up the test fixture.
     * Called before every test case method.
    protected void setUp()
     * Tears down the test fixture.
     * Called after every test case method.
    protected void tearDown()
    public void testAssertTrue()
        Notizbuch notizbuc2 = new Notizbuch();
     * �berpr�ft ob der Initialwert zur�ckgegeben wird.
    public void testAnzahlNotizen()
        assertEquals(0, _notiz.anzahlNotizen());
    public void testSpeichereNotiz()
        _notiz.speichereNotiz("hallo");
        assertEquals("hallo", _notiz.gibNotiz(0));
    public void testGibNotiz(int position)
        _notiz.speichereNotiz("hallo");
        assertEquals("hallo", _notiz.gibNotiz(0));
    public void testZeigeNotiz();
        _notiz.speichereNotiz("java");
        assertEquals("java");
    public void testAssertSame()
}Here is the code of my notebook :
mport java.util.List;
import java.util.ArrayList;
import java.util.HashSet;
* Diese Klasse beschreibt beliebig lange Notizlisten.
* Ein Notizbuch ist wie ein Ringhefter organisiert: Eine Notiz
* kann an beliebiger Stelle in die Liste eingef�gt werden.
* Benutzer k�nnen auf Notizen anhand ihrer Position zugreifen.
* Die erste Notiz hat die Position 0.
* @author David J. Barnes, Michael K�lling, Axel Schmolitzky, Petra Becker-Pechau
* @version 2005-12
public class Notizbuch
    // Liste f�r eine beliebige Anzahl an Notizen.
    private List<String> _notizen;
     * Ein neues Notizbuch enth�lt keine Notizen.
    public Notizbuch()
        _notizen = new ArrayList<String>();
     * Speichere die gegebene Notiz, indem sie an das Ende der
     * Notizliste dieses Notizbuchs angeh�ngt wird.
     * @param notiz die zu speichernde Notiz.
    public void speichereNotiz(String notiz)
        _notizen.add(notiz);
     * Hefte die gegebene Notiz an der angegebenen Position ein.
     * @param position die Position der neuen Notiz.
     * @param notiz die zu speichernde Notiz.
    public void speichereNotizAnPosition(int position, String notiz)
        if (position < 0 || position > anzahlNotizen())
            // Keine g�ltige Position, nichts zu tun.
            System.out.println("Ung�ltige Position!");
        else
            // Die Position ist g�ltig, wir k�nnen die Notiz einf�gen.
            _notizen.add(position, notiz);
     * @return die Anzahl der Notizen in diesem Notizbuch.
    public int anzahlNotizen()
        return _notizen.size();
     * Gib eine Notiz auf die Konsole aus.
     * @param position die Position der Notiz, die gezeigt werden soll.
    public void zeigeNotiz(int position)
        if (position < 0 || position >= anzahlNotizen())
            // Keine g�ltige Position, nichts zu tun.
            System.out.println("Ung�ltige Position!");
        else
        {   // Die Position ist g�ltig, wir k�nnen die Notiz ausgeben.
            System.out.println(_notizen.get(position));
     * Gib die Notiz an der gegebenen Position zur�ck. Bei einer ung�ltigen
     * Position wird null geliefert.
     * @param position die Position der Notiz, die zur�ckgegeben werden soll.
    public String gibNotiz(int position)
        String notiz = null;
        if (position < 0 || position >= anzahlNotizen())
            // Keine g�ltige Position, nichts zu tun.
            System.out.println("Ung�ltige Position!");
        else
            // Die Position ist g�ltig, wir k�nnen die Notiz zur�ckgeben.
            notiz = _notizen.get(position);
        return notiz;
}Thank you very much.

Yes, look carefully at your code:
public void testZeigeNotiz();Remove that semi-colon from the end of the line.
"Works"? I don't believe this will even compile. Why did you misstate the problem?
%

Similar Messages

  • JPA - cascade update

    Hello,
    Let's say I have these 2 classes:
    public Class Pessoa {
    @Id
    @Column(name = "ID_PESSOA", nullable = false)
    private Long idPessoa;
    private String nmPessoa;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "pessoa", fetch=FetchType.EAGER)
    private Collection<Telefone> fones;
    public Class Telefone {
    @Id
    @Column(name = "ID_FONE", nullable = false)
    private int idFone
    private String nrFone;
    private int tpFone;
    @JoinColumn(name = "ID_PESSOA", referencedColumnName = "ID_PESSOA")
    @ManyToOne
    private Pessoa pessoa;
    And then I try tu update the Pessoa object:
    Pessoa p = pessoaDAO.getPessoa(cdPessoa);
    p.setNmPessoa("Maria");
    p.getFones().removeAll(p.getFones());
    p.setFones(newFoneCollection);
    pessoaDAO.atualizar(p); // merge(p)
    After this I can see the change on the nmPessoa, but it does not happen on fones.
    I can have some changes if I add new fones, but the ones I already have stay in DB.
    Could someone tell me how I can do it?
    tks!

    Hi Mike,
    thanks for the reply!
    I did a test using the Derby DB (from netbeans 5.5) which has some tables. I took 2 tables ORDERS and CUSTOMER that has the same relation as PESSOA and TELEFONE.
    In this test netbeans generated the entities automatically and I just created the TestClass like this:
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("testaCascadePU");
    Persistencia persis = new Persistencia(emf); // has EntityManager, persist/merge/remove/find
    Customer c = (Customer)persis.find(entity.Customer.class, new Integer(1));
    Customer cTemp = new Customer(c.getCustomerId());
    Orders o = new Orders();
    o.setQuantity(new Short("30"));
    o.setShippingDate(new Date());
    o.setCustomerId(cTemp);
    o.setOrderNum(new Integer(10398011));
    o.setProductId(new Product(new Integer(980001)));
    Collection<Orders> ordersL = new ArrayList();
    ordersL.add(o);
    c.setName("Robert Plant Test");
    for (Orders os: c.getOrdersCollection()) {
    os.setCustomerId(null);
    os.setProductId(null);
    c.getOrdersCollection().removeAll(c.getOrdersCollection());
    c.setOrdersCollection(ordersL);
    persis.update(c);
    And this test still have the same problem that I had before.
    Even when I "unset" the orders, I keep getting the same orders in the DB plus the new order instead of getting just the new order as I wish.
    Am I doing something wrong?
    This scenario is quite common but I really don't know how to deal with it.
    Thanks again!

  • How do I make a static reference to a method?  Sample Code Included

    Why doesn't this work? How do I use the method add(int a, int b)?
    ERROR - "Can't make static reference to method int add(int, int) in testClass"
    interface testInterface{
        static String sString = "TESTING";
        int add(int a, int b);
    class testClass implements testInterface{
        public int add(int a, int b){
            return a+b;  
        public static void main(String argv[]){
            int sum = add(3,4);    // here's the error
            System.out.println("test");
            System.out.println( sum );
    }

    Why doesn't this work?Because you can't call a non-static method like add (which operates on the object called this) from a static method like main (for which there is no this).
    There are two ways to fix this:
    (1) In main, create a TestClass object, and call add() for that object:
    class TestClass implements TestInterface {
       public int add(int a, int b) {
          return a+b;
       public static void main(String[] args) {
          TestClass testObject = new TestClass();
          int sum = testObject.add(3, 4);
          System.out.println("test");
          System.out.println(sum);
    }(2) Make add() static. This is the preferred approach, because add() doesn't really need a TestClass object.
    class TestClass implements TestInterface {
       public static int add(int a, int b) {
          return a+b;
       // main is same as the original
    }

  • How can you create an instance of a class using ClassLoader given only

    the class name as a String. I have the code below in the try block.
    Class myTest = this.getClass().getClassLoader().loadClass("Testclass");
    Object obj = myTest.newInstance();
    String className = obj.getClass().getName();I don't want to typecast the class like
    Testclass obj = (TestClass) myTest.newInstance();I want to be able to create the classs at runtime and then get the methods in the class and execute those methods. Can it be done without having to code the typecasting in before compile time?

    I read on the web of people creating objects from interfacesDoesn't sound like the thing to do... Theoretically you could create dummy classes on the fly that implement some interface, but that's not very useful.
    Sounds like you are trying to load classes and execute them via interfaces. Like this:
         Class clazz = Class.forName("java.util.LinkedList");
         Collection c = (Collection) clazz.newInstance();
         c.add("hello");
         c.add("world");
         System.out.println(Arrays.toString(c.toArray()));LinkedList is the class, Collection is the interface which LinkedList implements. You can then call the methods declared in the interface. The interface gets "compiled in" into the program and the classes that implement it get loaded whenever and from wherever you load them.
    You could also use reflection to call methods without an interface, but that is type-unsafe, inelegant, hackish, and just plain ugly.

  • Create File with Folder

    Dear sir,
    i wrote small Generic API for create a file*(test.txt)* or folder*(..\folder\test.txt)* with a file......
    1. The Generic API successfully executed when i passed a file...
    2. when i pass folder with file name it throws Exception in thread "main" java.io.IOException: The system cannot find the path specified
         at java.io.WinNTFileSystem.createFileExclusively(Native Method)
         at java.io.File.createNewFile(Unknown Source)
         at com.vs.accr.xmlObjects.TestClass.main(TestClass.java:11)please help me out.....
    Thank you
    Boss134

          * strFileWithPath may handle 2 type of input . those are
          * 1. file Name (test.txt)
          * 2. folder Name with file Name   (..\sample\test.txt)
          * @param strFileWithPath
         final public void createFile(String strFileWithPath)
              File file = new File(strFileWithPath);
                    file.createNewFile();
         }i tried mkdirs() API - it generates 2 folder (sample and test.xml)
    Thank you
    Boss134

  • Create folder and copy files problem

    Hello all indesign script Members
    where I work we use a permanent folder structure for an example
    a jobnumber called "123123"
    I have wrote a little interface called interface.jsx, this file is saved and located in
    123123/scripts/interface
    I want my interface to navigate two folders up
    to 123123/source/ creates  a folder called "hej" so result is "123123/source/hej"
    then I can pick from a little dialog box the folder 123123/source/a/ copy all .indd files to the folder hej (or any other folder I choose from the dialog box)
    I want the script to know the active path instead of whole locations because, we have different project numbers all the time.
    then run an extern script called hej.jsx
    the best should be also if the script could chose 123123 as default jobnumber too.
    Please could  someone help me to script this?
    /get started I am very newbie
    Thank you so much in advance
    All Adobe Members

    Hi tjacobs01,
    Thanks for reply. I didnt include main method since i dont want to make the problem looks too complicated. I called both of the methods in main. The following is the simplified class code including main method.
    import java.io.File;
    import java.io.IOException;
    public class TestClass{
    public void buildFolder(){
    File f=new File("/documents/hospital_backup");
    if(f.exists()==false){
    f.mkdirs();
    public void copyFile(String file){
    String form_cmd="cp /job_holding/hospital/" + file + " /documents/hospital_backup/"+file;
    String[] command = new String[]{"sh", "-c", form_cmd};
    try{
    Runtime r=Runtime.getRuntime();
    Process p =r.exec(command);
    BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String line = null;
    while ((line = in.readLine()) != null) {
    System.out.println(line);}
    int exitVal=p.waitFor();
    System.out.println("Process exitValue:"+exitVal);
    }catch(Exception e){System.out.println(e);}
    public static void main(String[] args) {
    String dir_root="/job_holding/hospital/";
    File f=new File(dir_root);
    File[] fList = f.listFiles();
    for (int i=0; i<fList.length; i++)
    String file=dir_root+fList.getName();
    TestClass test = new TestClass();     
    test.buildFolder();
    test.CopyFile(file);

  • How to create an array using reflection.

    How to create an array using reflection.
    I want to achive something like this,Object o;
    o = (Object)(new TestClass[10]);but by use of reflection.
    To create a single object is simple:Object o;
    o = Class.forName("TestClass").newInstance();But how do I create an array of objects, when the class of objects is known only by name? (Can't use Object[] because even though an Object[] array can be filled with "TestClass" elements only, it Cannot be casted to a TestClass[] array)
    Anybody knows?":-)
    Ragnvald Barth
    Software enigneer

    Found it!
    the java.lang.reflect.Array class solves it!
    Yes !!!

  • Creating java bean

    Hi all,
    I am stuck with my first java bean, can anyone please help!? I've serahed the net and this forum, but the closest one to my problem that I can find is this one, http://forum.java.sun.com/thread.jspa?threadID=571292&messageID=2850205. However, it does not help me much. The following are the steps that I took.
    Thanks,
    Welles
    1. Create a class
    package testBeans;
    public class TestClass
         public static void main(String[] args)
              System.out.println("Hello World!");
         public void runTest(){
    2. Complie the java file to the testBeans folder under the current folder
    c:\work>javac -d . TestClass.java
    3. Create the jar file
    c:\work>jar cvf testBeans.jar testBeans/*.*
    added manifest
    adding: testBeans/TestClass.class(in = 483) (out= 315)(deflated 34%)
    4. Put the testBeans.jar in C:\Program Files\Java\jdk1.5.0_01\jre\lib\ext
    5. Create a driver class
    import testBeans.*;
    public class BeanDriver
         public static void main(String[] args)
              TestClass.runTest();
    6. Complie the BeanDriver.java file, but I get the following error message :(
    ---------- javac ----------
    C:\test\BeanDriver.java:7: cannot access TestClass
    bad class file: .\TestClass.java
    file does not contain class TestClass
    Please remove or make sure it appears in the correct subdirectory of the classpath.
              TestClass.runTest();
    ^
    1 error
    Output completed (0 sec consumed) - Normal Termination

    Crossposted, so don't anyone waste their time answering it here. Answer over here instead:
    http://forum.java.sun.com/thread.jspa?threadID=624016
    @OP: Crossposting is rude.

  • Creating event dispatching in custom class

    I have been trying to create an event dispatcher in a custom
    data transfer object class. It's a simple class and I don't know
    how to make it dispatch an event. I tried extending the
    EventDispatcher class but that doesn't appear to work either. Any
    help would be greatly appreciated.

    I have attached the code for the application and the custom
    class. This should work from what I have read, but I can not get
    the application to catch the event.
    APPLICATION
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="
    http://www.adobe.com/2006/mxml"
    creationComplete="initThis()" layout="absolute">
    <mx:Script>
    <![CDATA[
    import mx.controls.Alert;
    private var _tester:TestClass = new TestClass();
    private function initThis():void{
    addEventListener(TestClass.TEST_ACTION, onTestHandler);
    private function onTestHandler(event:Event):void{
    Alert.show("Event Dispatched");
    ]]>
    </mx:Script>
    <mx:Button x="312" y="150" label="Button"
    click="{_tester.testEvents()}"/>
    </mx:Application>
    CLASS
    package
    import flash.events.EventDispatcher;
    import flash.events.Event;
    public class TestClass extends EventDispatcher
    public static const TEST_ACTION:String = "test";
    public function testEvents():void{
    dispatchEvent(new Event(TestClass.TEST_ACTION));
    }

  • Create class with script

    Is there any way to dynamically create a class in a Flex application with a script?  Basically what I want to do is loop over data from a database that defines the classes I need, and create them on-the-fly instead of creating them in .as files and recompiling.

    Class I doubt, but its attributes indeed u can create dynamically by making
    public dynamic class TestClass
         public function TestClass()
                this.attribute_1 = value...

  • Error while Creating Presentation variable

    Hi,I am new to OBIEE
    I am facing this error:
    "A numeric value was expected (received "max("Sales Measures".Dollars)").
    Error Details
    Error Codes: EHWH2A7E"
    1.I am using paint rpd.I want to use presentation variable.
    2.So i took two column in criteria 1.Region 2. Dollars
    3.In Dollars edit formula ,I created presentation variable i.e. @{Doller_presentation}{max("Sales Measures".Dollars)} in the column formula.
    4.And In the same column i use filter
    Add ->presentation variable->variable exp =Doller_presentation and default =max("Sales Measures".Dollars)
    5.I have added this request on dashboard page,but error is coming.
    6.Also i have created dashboard prompt,
    Set presentation variable to "Doller_presentation"
    and in column formula :@{Doller_presentation}{max("Sales Measures".Dollars)}
    and took that prompt on the same dashboard page.
    so promt with 2 values are coming.1.All choces 2.13087528..may be ths is max value of dollar but on click its showing error as
    "Odbc driver returned an error (SQLExecDirectW).
    Error Details
    Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 42021] The query does not reference any tables. (HY000)
    SQL Issued: SELECT 13087529 FROM Paint ORDER BY 1"
    I am confuse abt use of presentation variable
    Please Help,
    Thanks
    Kapil
    [email protected]
    Edited by: user13098263 on May 9, 2010 10:58 PM
    Edited by: user13098263 on May 9, 2010 11:01 PM
    Edited by: user13098263 on May 9, 2010 11:02 PM
    Edited by: user13098263 on May 9, 2010 11:04 PM

    Hi Rachit
    You answered my doubt.This one really works . Thanks a lot !
    But i have one more doubt i.e if have created the Presentation variable in the dashboard prompt and I want to use it in a report
    i.e the scenario is If I have created a new column i.e " Revised Salary " in the Presentation Services and want the values to be entered there dynamically upon end users choice. For ex the end user selecrts value of 1 then the report would display an increament of 500 to all the employees in the " Revised Salary " column and if the end user select value of 2 .. the report would display a decrement of 500 in the " Revised salary column".
    I am getting the following error :
    ========================================================================
    Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
    State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 59001] Binary Logical operation is not permitted on VARBINARY, INTEGER operand(s). (HY000)
    SQL Issued: SELECT "D0 Time"."T05 Per Name Year" saw_0, "D2 Market"."M04 Region" saw_1, "D4 Product"."P01 Product" saw_2, "D1 Customer"."C1 Cust Name" saw_3, "F1 Revenue"."1-01 Revenue (Sum All)" saw_4, CASE WHEN 0='1' then "F1 Revenue"."1-01 Revenue (Sum All)" +500 else "F1 Revenue"."1-01 Revenue (Sum All)" - 500 end saw_5 FROM "Sample Sales" ORDER BY saw_0, saw_1, saw_2, saw_3
    ========================================================================
    Please NOTE : The column on which I want to do an increament is : "F1 Revenue"."1-01 Revenue (Sum All)"
    Thanks

  • Error while creating a Characteristic Variable with Replacement Path

    Hi all,
        I am trying to create the Characteristic Variable ZVLOWDT (Low Date') with Replacement Path on characteristic ZSTARTDT (Start Date) and it gives the error 'Source to replace 'Low Date' is not defined.
       I have created a User Entry Variable VAR_DATE (Start Date) with interval like '01/01/2009 - 01/15/2009'  and  Customer Exit variable ZVCPDAY (does some calculation based on the input of VAR_DATE) on the same ZSTARTDT characteristic. I want to get the 01/01/2009 (lower range date of the selection) into this Characteristic Variable ZVLOWDT. We are in BI 7.0 and the following are it's properties:
    General Tab:
    Description: Low Date
    Technical Name: ZVLOWDT
    Type of Variable: Characteristic Value
    Processing by: Replacement Path
    Reference Characteristic: ZSTARTDT Start Date
    Details Tab:
    Variable Represents : Single value
    Variable is: Mandatory
    Variable is Ready for Input : unchecked
    Replacement Path Tab: Replacement Rule
    Replace Variable with : Variable
    Variable : VAR_DATE
    Replace with : KEY
    Why I am getting this error, PLEASE ?
    Thanks,
    Venkat.

    Hi Khaja,
       We could derive a Variable value from another Variable with out Customer Exit. There is a white paper.
    First have the User Entry Variable (ZV_X) and it accepts the date range like '01/01/2009 - 01/31/2009'. Next create the Characteristic variable (ZV_Y) of Replacement Path for which source variable will be ZV_X and we could get the 'FROM Date' (01/01/2009) from the selection (ZV_X) into it (ZV_Y).
    While creating the Characteristic variable (ZV_Y) of Replacement Path, I didn't find my newly created ZV_X variable in the list of available variables under 'Variable' header in 'Replacement Path' tab and it is causing the error  'Source to replace variable ZV_Y is not defined'. How could I create the Characteristic variable of Replacement Path, PLEASE ?
    Thanks,
    Venkat.

  • I create a birthday calendar in iCal and then click on it in iphoto at the begining of the calendar project each year.  Some how the birthday did not populate the photo calendar.  Is there a way to add the birthday iCal calendar into the calendar project?

    I created a birthday calendar to use in iphoto for calendar.  When a new calendar project is started each year, I click on it in.  Some how the birthday did not populate the photo calendar this year.  The photo calendar is almost complete.  Is there a way to add the birthday iCal calendar into the calendar project? I would prefer not to start over.

    Hi,
    If you first select the calendar on the left, so that its background is highlighted blue/grey, when you make a new events they should be added to that calendar.
    Best wishes
    John M

  • Is there a way to create a year at a glance with detail and print?

    Is there a way to create a year at a glance with detail and print?

    To do what Dave indicated you need to do, it depends on what version of Acrobat you have:
    Acrobat 8: Advanced > Enable Usage Rights in Adobe Reader
    Acrobat 9: Advanced > Extend Features in Adobe Reader
    Acrobat 10: File > Save As > Reader Extended PDF > Enable Additional Features
    Acrobat 11: File > Save as Other > Reader Extended PDF > Enable More Tools (includes form fill-in & save)
    I wonder what it will be next time?

  • How can I create a new iCloud account for a familiy member having a new iDevice and reuse one of my aliases for it

    Hi there,
    I moved into iCloud from the very beginning and started with one iCloud account for me and my family, making use of email aliases for family members. Now the number of personal iDevices grows and I want to create a new and separate iCloud Account for my son. The pity is, that I reserved his full name already as alias address on my initial iCloud account. If I now delete this alias, can I create a new account with the former alias as new primary email address?
    Or is there at least any transfer procedure supported for aliases between different accounts?
    Thanks for your help, lauterbachj

    Couldn't agree more... the folks who are getting penalized for this are the early adopters of .Mac/iCloud dating from the days when the only way to implement a "family" account was to use aliases. Now all my kids' / my wife's name aliases sit in my account, unable to move. I guess the good news is that if I delete them nobody else will get them, but this seems a pretty poor consolation.
    Would it really be so difficult to implement a "move this alias to another iCloud account" option that requires the "sender" and "receiver" to exchange some sort of code to implement the transation in order to prevent fraud?

Maybe you are looking for

  • Vendor Invoice unblock tracking.

    Hi all, Is there any standard report where I can track the Vendor Invoice unblocking done through MRBR? Thanks, sandeep.

  • Input for Mobile Devices: GeoLocation/Google Maps | ADC Presents | Adobe TV

    Geolocation is a top feature on mobile devices. In this video Paul Trani explains how to use the GPS coordinates of a device and plot the coordinates on a Google Map. http://adobe.ly/wq4jdr

  • How much training.

    Hello all, As a manager: How much training would I expect to provide to an Oracle DBA? Let's assume we are on Oracle 9i. 2nd question is if we are upgrading to 10g how much training would be necessary to send a DBA to? As a DBA: How much training wou

  • Re: Question on Apple Care

    Could somone answer the question concerning Apple & Apple Care if you live in Florida? There is an odd Florida state law that prohibits the purchase or use of Apple Care if Florida is your legal residence. How does Apple work around that one or do th

  • Error in personal data Webdynpros

    Hello, when I launch any of the personal data iViews (adresses, bank) I get an error: com.sap.dictionary.runtime.DdException: Type com.sap.xss.per.model.mac.types.Hrxss_Per_Subtype_Allowed does not exist Any solutions on this?