Write Unit Tests When Some Other Classes Are Involved And Abstraction Is Much Higher?
Mar 5, 2015
I have two classes Person and Group. Group object is suppose to contain many Persons, How can I write unit tests when some other classes are involved and abstraction is much higher?
public Unit(String code, String name) { enrolStudent(student); this.unitCode = code; this.unitName = name; } public void enrolStudent(Student newStudent){ students = new ArrayList<Student>(); newStudent = new Student(24662496, "Kingsley", " Iwunze"); students.add(newStudent); }
how can I call this enrolStudent() method on this Unit constructor in another class when I create a new Unit. all I need is to enroll students in units when units are created. below is my create unit method.
find a way to make all my clases in one single tab and not like this: URL....
because at the end of the exam, we have to paste the whole code (as one) in a specified web page, which instantly shows us the result. We need the whole code to be in just one page (like back in C++).
I am working on a class project and I have to write the JUnit test for the GUI class ... what I did wrong ... Here is the code for the GUILauncher:
package edu.oakland.production; import java.awt.*; import javax.swing.*; public class GUILauncher{ public static void main(String[] args){ RetrieveWindow gui = new RetrieveWindow();
Since the Paint methods are being executed anytime a frame is being moved or resized, how much overhead could an application incur if the application
- has many frames - doing a lot of moving - doing a lot of resizing - has a lot of background processes running.
As a rule, I try to only keep the most essential code in these types of methods and wondering if that type of thinking is "old school".
How much overhead is actually involved? If you needed to monitor the size of a given frame anytime the user resizes it, would you be concerned that using these methods would incur too much overhead?
I'm working on this weeks assignment and I've gotten stuck on passing information from one class to another. We are working with abstract classes this week, and the BankAccount class is the Abstract class that is extended by the CheckingAccount and the SavingsAccount classes. The Bank class is where the user inputs his/her information to process the commands. How can I work this to where the instructions are passed from the main in the Bank class to the different Account classes to actually perform the instructions?
BankAccount:
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */
package bankaccount; abstract class BankAccount { private final BankAccount acctID; private int acctBalance = 0; public BankAccount checking; public BankAccount savings;
[Code] ....
I can attach a PDF of the instructions if that will provide additional insight to this. I'm sure I'll ask additional questions as we go, but I'm trying to get this to work right and figure out what I'm doing wrong.
I am working on project "Abstraction of UML diagrams from java code". I am searching for a at least few codes to create class, object, sequence, activity, usecase diagrams.
First I was using this way how to get connection and all was fine.
con = DriverManager.getConnection("jdbc:derby:memory:datab;create=true");
But now I have to change it to DataSource and how I find out derby had class ClientDataSource for this but for the hell I can't find out how to setup that virtual DB.
ClientDataSource ds = new ClientDataSource(); con = ds.getConnection();
I have to organize the rows from the lower to the higher number, the problem is, what I have only organizes the first 3 rows even If I insert 3,4,5...or 10 rows.
for (int i = arg[0].length - 1; i >= 0; i--) { for (int j = 0; j < i ; j++) { for (int k = 0; k < i ; k++) { if (arg[k][j] > arg[k][j + 1]) { int temp = arg[k][j];
How to start and structure my program because i am fairly new to the program but want to try to make a game. My idea of the game is it generates random numbers between 1-100 for two people and the program compares the two random numbers and declares the player with the higher value the winner like the card game war. Then it would give you an option to try again.
In my application, users select the year and manage data for that year (for example, they can choose 2014 for managing invoices for 2014, then switch to 2015 and work with that year). Each year as his own database.
I'am able to change persistence unit connection at runtime with Persistence.createEntityManagerFactory(PU_NAME,map_with_connection_info) This procedure build a non-jta environment.
It is possible to create entityManager / entityManagerFactory with JTA ?
I don't want to create new persistence unit each year or each time a new database is required.
So I have this 2D array that contains some Object foo.
[f] [f] [f][f]
[3][3][3][3]
[b][b][b][b]
[x][x][x][x]
[ ][ ][ ][ ]
[ ][ ][ ][ ]
[ ][ ][ ][ ]
I want to shift all the rows down one unit, starting for the rows containing x. So the x row is first shifted to row 4. then the b row shifted to where the x row was, row 3 and so on. My question is:
1. How can I check if the next row is empty
2. How do I shift a row down
Here's my attempt:
Java Code:
//board is the 2D array defined elsewhere public void shiftRowDown(){ int counter = 0; int rowCounter = 0; for (int i = 0; i < this.board.length; i++) {
I am having a difficult time trying to get results from the code below. The purpose is for my program to insert the DHL tracking number in the tracking text box, and then for the program to "click" the search button and get the tracking results.
This is the code:
import com.gargoylesoftware.htmlunit.WebClient; import java.io.*; import com.gargoylesoftware.htmlunit.html.HtmlPage; import com.gargoylesoftware.htmlunit.html.HtmlInput; import com.gargoylesoftware.htmlunit.html.HtmlSubmitInput; import java.net.*; public class DHL {
[Code]...
These are the results I am getting in the console (in red), which look like an error:
Apr 23, 2015 7:55:49 PM com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement addbehavior WARNING: Unimplemented behavior: #default#userdata Exception in thread "main" com.gargoylesoftware.htmlunit.ElementNotFoundException: elementName=[*] attributeName=[name] attributeValue=[sbtc] at com.gargoylesoftware.htmlunit.html.HtmlPage.getElementByName(HtmlPage.java:1747) at htmlTest.main(htmlTest.java:17)
I just cannot figure it out for the life of me. Also, is there a community that focuses on HTML Unit?
I have a bean that represents data been collected from a form on a jsp page. Currently I would like to validate my fields and write some test cases for them. As you can see from my test case example I test a string in the hope that it fails because it contains only one letter. My problem is my unit test is passing. The reason this is from what I can tell is that at runtime it fails when I try to persist my object using my entity manager. During my unit test I just I don’t call my entity manager I just try and set the field.
What I thought would happen was that when I use my bean fields set method the annotations would be checked and fail at that point. Hence why I expected my unit test in this case to fail.
What I would like to know is
1.Are annotations specifically designed to validate when I persist my object and am I using them incorrectly at this point?
2.Is this the best method to use to validate fields, is there a better way, should I write my own code to validate for me when I set my value?
a. Should I throw an exception from the set method of each bean field?
Unit Test:
@Test public void testName(){ Human h=new Human(); try { h.setFname("a"); } catch (Exception e) { // TODO Auto-generated catch block fail("failed"); e.printStackTrace();
So, here is the question I have been working on: Write a java class named Time that prompts the user to input the elapsed time for an event in seconds. The program then outputs the elapsed time in hours, minutes, and seconds. (For example the elapsed time is 9630 seconds, and then the output is 2:40:30 ).Hint: an hour has 3600 seconds and a minute has 60 seconds. Use Scanner class for reading the input.
Here is my code:
import java.util.Scanner; public class Time { public static void main(String[] args) { Scanner scan= new Scanner(System.in); System.out.println("Enter the elapsed time in seconds:"); int totalseconds= scan.nextInt();
[Code] .....
Now, I know I am supposed to use the remainder operator to figure out the time in minutes and seconds, but the hours has be a little confused. Right now this code compiles but gives me an exception.
When creating VRML, there is a convention that one unit corresponds to 1 metre in the real world. This makes sharing models easier. Is there any similar convention for JavaFX 3D?
One of the random number generators in Java extract the higher-order bits of the random number in order to get a longer period.
I'm not sure if I understand how this is done. Suppose that the random number r = 0000 1100 1000 1101. If we extract the 16 most significant bits from r; is the new number r = 0000 1100 or r = 0000 1100 0000 0000?
Alright, so I'm having problems with lines 11 - 55. I'm trying to calculate the possible tiles the clicked unit can be moved on and display it to the player.
The field is a 9 (columns) by 5 (rows) grid. A unit with can move tiles horizontally or vertically based on its movement.
Example: (unit = o; possible tiles = x) (assuming movement of 2).
I tried to calculate movement by finding out what column the unit is in, subtracting the column it wants to go to, multiplying the difference by *-1 if the difference is less than 0. Then, doing the same with rows and adding the difference of columns to the difference of rows and comparing it to the unit's movement. Unfortunately, with my code, it seems to move in any directions.
@Override public void mouseClicked(MouseEvent e) { if (Main.cards.size() > 0) { mainloop: for (int i = 0; i < Main.cards.size(); i++) { Card c = (Card) Main.cards.get(i); int startingColumn = 0;
I have the following unit test that gives me a null pointer exception. The debugger goes to the finally block right after the line that creates a connection factory. Here's the test:
I'm doing an aggregation exercise that's suppose to find the volume and surface area of a cylinder. What I'm trying to do is pass values from one class, to a second class, and that second class passes values to a third class.
This may be a clearer explanation: The first class is the main program which sends values to the second and third class. The second class is used do calculations for a circle (a pre-existing class from another assignment). The third class grabs the values that the second class calculated and calculates those values with the one that was passed from the first class to the third class. The first class then prints the outcome.
Problem is when the program gets to the third class, it just calculates the value from the first class with the default constructor from the second class. It's like the second class never received the values from the first class. I think I'm missing a step, but I don't what it is.
First Class:
package circle; import java.util.Scanner; public class CylinderInput { static Scanner in = new Scanner(System.in); public static void main(String[] args) { //user defined variable
I'm quite new to Java. I have some trouble with understanding how to get two classes to get objects from each other (if that is the correct term).
Lets say I have a login class, in which I have a method checking what the user has entered into the console (I have not displayed the whole code, but this class works as it should and give the user an option to enter username and password and return it true if entered correct).
public static boolean validateUserPass(String userName, String password) { String[] user = {"admin"}; String[] passwords = {"firkanten"}; boolean check = false; for (int i = 0; i < user.length; i++) { if (userName.equals(user[i])) { if (password.equals(passwords[i])) { check = true;
Now, in another class I want a display box to appear on the screen and give the user three options: Click yes, no or cancel. I get this to run perfectly alone, this is not the hard part for me. I want the display box only to appear when the correct username and password is given, but I can't seem to figure out how to do this probably.