# Fehlerbehebung JUnit 4.12



## Bodyburster (24. Jul 2015)

Guten Tag,
bin neu hier und bräuchte dringend Hilfe zu 3 Aufgaben aus den Praktomaten meiner Universität.
Der Code ist eigentlich vollständig nur meldet mir das JUnit(4.12)-Plugin im Praktomaten noch diverse Fehler, die ich nicht lösen kann. Ich hoffe ihr könnt mir helfen, dass JUnit endlich den Code annimmt. Ich schätze die Fehler kommen zustande, weil JUnit 4.12 mit einer anderen Fieldescription und Methoddescription arbeitet als im Lösungscode verwendet wurde. Ich habe diesbezüglich keine Ahnung und hoffe auf schnelle Hilfe.
Ich schreibe noch die Aufgabenstellung mit der Fehlermeldung dazu. Der fehlerbehaftete Code ist im Anhang.



*Aufgabe 1:  MyMatrix*

Take a look at the following interface of a data structure representing a matrix.

import java.util.*;

public interface Matrix<T> {
int getRowCount();
int getColumnCount();
int getObjectCount();
int getDistinctObjectCount();
Iterator<T> iterator();
T get(int row, int column);
T put (int row, int column, T value);
boolean contains(T value);
}

*Example*
To understand how the data structure is supposed to work, take a look at the following example.

Matrix<String> m = new MyMatrix<String>();
String a = "a";
String b = "b";

m.put(0,1,a);
m.put(1,3,b);
m.put(2,0,a);

The state of the matrix after executing that code looks like this:

* 0 1 2 3
0* null a null null
*1* null null null b
*2* a null null null

The following table shows the result of exemplary calls of methods of Matrix which should give you an impression of what these methods do.

*Method call* *Result / returns*
getRowCount() 3
getColumnCount() 4
getObjectCount() 3
getDistinctObjectCount() 2
iterator() an instance of MyMatrix.DepthFirstIterator
get(2, 0) a
get(1, 2) null
get(0, 4) IllegalArgumentException
put(2, 0, b) a
put(0, 0, b) null
contains(a) true
*Hints*

An entry of the matrix is defined as empty if it holds the value null or its row or column do not exist.
The row and column counts are non-negative integers.
The methods getRowCount() and getColumnCount() do not count empty rows at the bottom edge or empty columns at the right edge of the matrix.

The method getObjectCount() only counts the non-empty entries of the matrix.
The method getDistinctObjectCount() only counts the number of different objects in the matrix.
Implement the iterator (provided by MyMatrix.iterator()) with the iterator pattern.
Implement the iterator (DepthFirstIterator) as inner class of MyMatrix.
The iterator traverses the matrix first in depth, then in width, hence the name.
Implement the methods next() and hasNext() according to the specification of the Iterator interface. The method remove() is not supported by the iterator.
null objects are skipped by the iterator, so they are not provided by next().

The method get(int row, int column) returns the object at the given row and column.
The method put(int row, int column, T value) assigns the object value to the entry at position (row, column). The method returns the original object which was replaced by value. If nothing (null) was at the position previously, the method returns null.
The method contains(T value) checks if the matrix contains the given object value of type T.
Matrix should be generic and the type variable T determines the type of objects that can be put into the matrix. Save the entries in a java.util.Map.
Use the class java.util.HashMap<K,V> for the matrix and java.awt.Point for the positions.

*Design*
The UML class diagram shows the general design of the implementation.







*Task*
Implement the matrix class (MyMatrix) including its iterator (DepthFirstIterator) and the interface (Matrix)!

*Fehlermeldung:*

*java version "1.7.0_79"
JUnit version 4.12
*

1) testIterator(MyMatrixTest)
java.lang.AssertionError: DepthFirstIterator.next() should throw a NoSuchElementException if there is no next element!




*Aufgabe 2: Queue *

Given is the following analysis model for a queue.






A queue (Queue) consists of an ordered collection of objects (generic type T) and is based on the FIFO principle ("first in, first out"). The queue returns elements in the same order they were put into it. In consequence, the element which has been enqueued first will be returned first.

Queues usually provide the following operations:


add(T t) enqueues t as last element of the queue if possible and returns true if the queue has been changed, otherwise it returns false.
remove() removes the first element of the queue and returns that element.
first() returns the first element without removing it from the queue.
isEmpty() returns true if the queue is empty, otherwise it returns false.
size() returns the number of objects within the queue.
In this task there are two kinds of queues (see the class diagram below):


Queues with duplicates (_it is possible_ that objects are queued up more than once at the same time, withDuplicates = true)
Queues without duplicates (_it is *not* possible_ that objects are queued up more than once at the same time, withDuplicates = false)
Thus, for the implementation you use either


a "common" list (use java.util.LinkedList) or
a list without duplicate objects where the elements are ordered, i.e. an OrderedSet, see below.






*Tasks*
Which design patterns are used in this design model? Think about them and their usage.

Write the code for the two interfaces Queue and OrderedSet and implement them with the classes QueueImpl and OrderedSetImpl! Make the implementation typesafe by using *generics*! Using Object as element type in lists and sets is not sufficient! You may need to enhance the given domain model.

*Hints*
To implement QueueImpl according to the instructions, you will need an ordered set. Because there is no such data structure in the Java collections framework (JCF), you have to write the interface OrderedSet and a concrete OrderedSet implementation (OrderedSetImpl) yourself. The interface OrderedSet along with the interface Queue is given as Javadoc documentation. The implementations of both interfaces must behave as specified in the Javadoc documentation!

*Fehlermeldung:*

*java version "1.7.0_79"
JUnit version 4.12
*

1) testFirst(QueueImplWithoutDuplicatesTest)
java.lang.NoSuchMethodError: Queue.first()Ljava/lang/Object;

2) testRemove(QueueImplWithoutDuplicatesTest)
java.lang.NoSuchMethodError: Queue.first()Ljava/lang/Object;

3) testAdd(QueueImplWithDuplicatesTest)
java.lang.AssertionError: Queue.add() should throw a NullPointerException if the specified element is null!

4) testFirst(QueueImplWithDuplicatesTest)
java.lang.NoSuchMethodError: Queue.first()Ljava/lang/Object;

5) testRemove(QueueImplWithDuplicatesTest)
java.lang.NoSuchMethodError: Queue.first()Ljava/lang/Object;



*Aufgabe 3: Predicate Iterator*

Given is the description of a design model which uses the iterator design pattern (see the class diagram below):

A PredicateIterator<T> iterates over the elements of an arbitrary data iterable structure and provides only those elements which satisfy a certain predicate (while skipping all of the other elements).
The constructor of PredicateIterator<T> expects the following arguments:


iter, a java.util.Iterator<T> for the actual data
a description of the predicate consisting of
pred, a Predicate<T> object that determines what kind of predicate to use
argument, an object of type T that serves as value for the predicate

The method predicate() of the generic interface Predicate<T> checks whether an object element satisfies the predicate with the value argument (both are of type T). It returns true or false accordingly.

The design model contains three classes which are implementations of the interface Predicate<T> for the application to String objects. Note that element and argument are of type T extends String.


PredicateStartsWith checks if element starts with the value argument.
PredicateEndsWith checks if element ends with the value argument.
PredicateLength checks if element has the length argument (since argument is of type T extends *String*, use Integer.parseInt() to get an int for the length check).
*Class diagram*





*Task*
Implement the given design model! Keep as close as possible to the class diagram!

*Fehlermeldung: *

*java version "1.7.0_79"
JUnit version 4.12
*

1) testPredicate(PredicateEndsWithTest)
java.lang.NoSuchMethodError: PredicateEndsWith.predicate(Ljava/lang/String;Ljava/lang/StringZ

2) testPredicate(PredicateStartsWithTest)
java.lang.NoSuchMethodError: PredicateStartsWith.predicate(Ljava/lang/String;Ljava/lang/StringZ

3) testPredicate(PredicateLengthTest)
java.lang.NoSuchMethodError: PredicateLength.predicate(Ljava/lang/String;Ljava/lang/StringZ


----------



## MWin123 (24. Jul 2015)

Die Fehlermeldungen sind doch eindeutig.

Ich habe ein paar Klassen überflogen und da fehlen die genannten Exceptions oder Methoden.


----------

