UriParserTest testScheme: NullPointerException

Okay because I pushed my test cases for scheme and have this as result:

java.lang.NullPointerException: Cannot invoke “uri.UriParser.parse()” because the return value of “uri.UriParserFactory.create(String)” is null
Trace:
at prog2.tests.pub.UriParserTests.testScheme(UriParserTests.java:23)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
…(some other errorstoffs)

what is the meaning of that, because the error line isn’t implemented by me.

Thanks :slightly_smiling_face:

From the documentation of create in UriParserFactory.java:

	/**
	 * @param uri
	 *            The URI that will be parsed
	 * @return A parser object for the given uri or {@code null} if {@code uri}
	 *         is {@code null}
	 */

So assuming that the factory on the server adheres to the documentation (which it should, we are supposed to test their implementation, not their factory) this means that you somehow pass null into the create method in your tests.

This error is in the public test prog2.tests.pub.UriParserTests.testScheme(UriParserTests.java:23).
The test assures that your URI implementation can correctly parse the URL http:// and identifies the scheme http.

How to read the error message:
The error indicates that you have not yet implemented the URI factory.
To be precise, the error tells you that uri.UriParserFactory.create(String) in the test in line 23 did not create an UriParser but instead returned null.
And the error is then created because we can not invoke the parse method on null.

I’m very confused. So we need to edit UriParserFactory and create the method create? I thought that we only need to write tests.

The factory is important for the second part of the project.
To cite the project description:

Create an instance of this class in UriParserFactory and return it.

The two public tests in prog2.tests.pub test the basic functionality of the parser for the second part.

Okay. Just to be absolutely clear, for the first part, we are only supposed to write tests in the tests/ directory?

In the first part, you have to write tests in the uri.tests package.

1 Like

So, we can actually not check whether our tests are correct? Because for me, some of the daily tests throw these errors too :slight_smile:

The idea of the tests is to write them before you implement the parser (because otherwise you could simply write tests based on your implementation rather than the specification). Without a somewhat working parser you can not test your tests. You have to see the bright side: You will be able to test your parser using your tests :wink:

1 Like

But, the daily tests at some point pass for me, without an implementation. I thought, that they would give correct and wrong implementations to my tests and check the result? So in theory, the daily tests should indicate if my tests work or not? Or do I understand that in a wrong way?

Shouldn’t they all fail then? Also, why is it then possible that some people have already reached 100%?

Thanks! :slight_smile:

There are the following tests:

  • BrokenImplTestTests: Are your tests sufficient to identify bugs in broken implementations? => At least one of your tests should fail on an incorrect implementation
  • TestsCorrect::all: Are your tests correct / did you understand the specification correctly? => All of your tests should succeed on correct implementations.
  • Public parser: Very basic sanity check that you started with the parser.

Therefore, you have feedback if your tests are much too simple if a BrokenImplTestTests fails.
You also get feedback if you wrote wrong tests.

But there are nearly no tests regarding the implementation of the parser (part 2).
You have to write your own tests and use them to check if you write a correct parser.
This is also the reason for the earlier test deadline.

100% daily tests mean: You have a test suite that identifies the daily buggy implementations, you have no incorrect tests, and you have at least started with the parser.

Note: As always, correct daily tests do not guarantee a correct implementation / good test coverage.

3 Likes

2 posts were split to a new topic: Need to pass public tests for part 1