• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to structure a project  RSS feed

 
Steven Greenbaum
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to create a class that is called EmployeeModule. This class is going to be my 'product'

This class is going to be used by another class called Platform that is not part of my product.

When I am done with EmployeeModule I am going to hand it off to Platform to use.

Platform will provide a set of data about  employees and provide this set to EmployeeModule.

EmployeeModule will process the data and provide an output.

So although Platform is not part of my product, I need it for test purposes.

So how to I structure my NetBeans project.

I would like Main to be in EmployeeModule. So how do I get inputs from Platform.

Hope this is clear
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steven Greenbaum wrote:I would like Main to be in EmployeeModule. So how do I get inputs from Platform.

Why? It seems that EmployeeModule is a library, not an executable application.

you should write test cases that pass input data to your EmployeeModule. Have you worked with JUnit before?
 
Steven Greenbaum
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Stephan,

Thank you for your input.

No-Employee module is an executable application.

It takes information about individual employee salary , start date and end date and platform time series and generates
headcount vs time and salary vs time for individual employees and aggregates employees.

I dont know what jUnit is.

Does NetBeans allow me to do testing?

So what may be the best way to go about this is to not write code for Platform and just devise tests for EmployeeModule where the test environment provides input.

Dows that make sense.


 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does the module ask the platform for input or does the platform call the module and pass input? The first doesn't really make sense, and that's why I wondered why your module was executable. However, if that's the case, then you should mock the platform in your unit tests.

Yes, NetBeans has support for unit testing with JUnit. Right-click your project and select New -> Other. Under Unit Tests, you can choose JUnit Test.
 
Steven Greenbaum
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Platform will call the module. I will check out jUnit. Thank you.
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, so if the platform calls the module, then why does the module have a main class?
 
Steven Greenbaum
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont have the platform.

this was the first attempt at java

the wy i did it i had a standalone program that generates the desired output.

I guess I have to modify it now to eliminate main and accept input from the test process.

oes that make sense?
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it does. If you're stuck with the unit tests, let us know. Good luck!
 
Steven Greenbaum
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just getting started
first code block is original OnPlanUserModule that still has main init.

2nd block is restuructured version without main.

My intent is to pass in 3 arguments from jUnit test: int periods, LocalDate timeSeriesDateStart, Employees employees

I would like to pass in an array list of employees as input and then consume them as in original main version.

As you can see I am getting mainy compile errors,- there were more errors-i didn't see point of including

F:\Users\User\Documents\NetBeansProjects\OnPlanUserModule\src\onplanusermodule\OnPlanUserModule.java:12: error: <identifier> expected
   public void class  OnPlanUserModule (int periods, LocalDate timeSeriesDateStart, Employees employees; ) {
F:\Users\User\Documents\NetBeansProjects\OnPlanUserModule\src\onplanusermodule\OnPlanUserModule.java:12: error: '(' expected
   public void class  OnPlanUserModule (int periods, LocalDate timeSeriesDateStart, Employees employees; ) {
F:\Users\User\Documents\NetBeansProjects\OnPlanUserModule\src\onplanusermodule\OnPlanUserModule.java:12: error: ')' expected


   public void class  OnPlanUserModule (int periods, LocalDate timeSeriesDateStart, Employees employees; ) {
F:\Users\User\Documents\NetBeansProjects\OnPlanUserModule\src\onplanusermodule\OnPlanUserModule.java:12: error: illegal start of type
   public void class  OnPlanUserModule (int periods, LocalDate timeSeriesDateStart, Employees employees; ) {
F:\Users\User\Documents\NetBeansProjects\OnPlanUserModule\src\onplanusermodule\OnPlanUserModule.java:12: error: ';' expected
   public void class  OnPlanUserModule (int periods, LocalDate timeSeriesDateStart, Employees employees; ) {
F:\Users\User\Documents\NetBeansProjects\OnPlanUserModule\src\onplanusermodule\OnPlanUserModule.java:25: error: illegal start of type
        for ( int t=0; t < periods; t++ ) {
F:\Users\User\Documents\NetBeansProjects\OnPlanUserModule\src\onplanusermodule\OnPlanUserModule.java:25: error: ')' expected
        for ( int t=0; t < periods; t++ ) {
F:\Users\User\Documents\NetBeansProjects\OnPlanUserModule\src\onplanusermodule\OnPlanUserModule.java:25: error: illegal start of type
        for ( int t=0; t < periods; t++ ) {
F:\Users\User\Documents\NetBeansProjects\OnPlanUserModule\src\onplanusermodule\OnPlanUserModule.java:25: error: <identifier> expected
        for ( int t=0; t < periods; t++ ) {
F:\Users\User\Documents\NetBeansProjects\OnPlanUserModule\src\onplanusermodule\OnPlanUserModule.java:25: error: ';' expected
        for ( int t=0; t < periods; t++ ) {
F:\Users\User\Documents\NetBeansProjects\OnPlanUserModule\src\onplanusermodule\OnPlanUserModule.java:25: error: > expected
        for ( int t=0; t < periods; t++ ) {
F:\Users\User\Documents\NetBeansProjects\OnPlanUserModule\src\onplanusermodule\OnPlanUserModule.java:25: error: '(' expected



ORIGINAL CODE WITH MAIN





NEW CODE BLOCK WITHOUT MAIN


 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why yes, you can't put statements just anywhere in a class, they need to be in a method.
 
Steven Greenbaum
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is revised code for OnPlanUserModule that doesn't have main.
My next step will be to attempt to drive it from JUnit.
This will be first time using JUnit. The biggest hurdle will be to figure out how JUnit will provide employees as an input.


 
Steven Greenbaum
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is beginning of JUnit implementation

In my old code with main I had hardcoded 3 employees as follows below. I am not sure how to fold that into JUnit:

Also I am not sure how to do the last step, verifying the output from the return of employees which includes headcount and salary series.




 
Dave Tolls
Ranch Foreman
Posts: 3068
37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You generate the Employees in the same way.
And pass it into the setEmployees method.

Since you don't have any getters (which is fine) the tests for the setXXX methods are pointless as you have no way to check them.

The only meaningful thing is the result returned by the ProcessEmployees method (which should be processEmployees, with a lowercase 'p'), so I would expect lots of tests around that method, with different values set via the other methods.
 
Steven Greenbaum
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This is my Junit test file
I coded setEmployees but was unsure how to code
I was unsure of how to code testProcessEmployees so didn't attempt that yet.

I ran the test and got 4 errors but there didn't seem to be any way to copy the errors to display them here

At line s 49,62, 102 and 115 of the test file I got a  dereferenced a null pointer error


 
Steven Greenbaum
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Made some progress on my own

not sure how to handle the results sections of the last two tests

 
Steven Greenbaum
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
now 2 tests pass and 2 fail

problem seems to be with my TimeSeries class
which is causing a null pointer exception at line 30

The first test that is failing is TestSetEmployees

I believe the second test failing is because of the same issue




This is my JUnit test File




And this is my OnPlanUserModule file

 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!