package infotool;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
public class InfoModelTest {
private InfoModel instance;
@Before
public void setUp() {
instance = new InfoModel();
}
/**
* Test of getMessage method, of class InfoModel.
*/
@Test
public void testGetMessage() {
assertEquals("welcome to mvc", instance.getMessage());
}
/**
* Test of getWeather method, of class InfoModel.
*/
@Test
public void testGetWeather() {
assertEquals("Sunny", instance.getWeather());
}
/**
* Test of setMessage method, of class InfoModel.
*/
@Test
public void testSetMessage() {
String wthString = "JUnit @Rules";
instance.setMessage(wthString);
assertEquals(wthString, instance.getMessage());
}
/**
* Test of setWeather method, of class InfoModel.
*/
@Test
public void testSetWeather() {
String wthString = "It's going to rain";
instance.setWeather(wthString);
assertEquals(wthString, instance.getWeather());
}
/**
* Test of addModelChangeListener method, of class InfoModel.
*/
@Test
public void testAddModelChangeListener() {
InfoModel instance = new InfoModel();
InfoView view = new InfoViewTestSupport(instance);
instance.addModelChangeListener(view);
instance.setMessage("From testAddModelChangeListener");
assertTrue(((InfoViewTestSupport) view).getNotification());
}
}
4 November 2013
A JUnit 4 Test class
1 November 2013
Java programming: extra labs
Lesson 3
Extra Practice 3-2, Task 3
Step e. Add a method addEmployees that adds multiple employeesLesson 4
Extra Practice 3-2: Equals method
- Add an equals method to the employee class
- Use employee id to test equality
- Make sure that it takes into account null values and references to other classes being passed in
- You can use ALT+INSERT in NetBeans to insert a sample equals method
- Test and correct until the code succeeds
- Modify the equality test to use the social security number
- Test and correct until the code runs correctly
Lesson 5
Extra Practice: Deck
- Start from the Deck lab from Java Funcamentals
- Replace the CardNames and CardValues arrays with enums Suit and Face
- Replace the decksize (52) with a number calculated from the available enums
- hint: using the values() method on your enum, returns an array of all values
- Test and correct the code until the program runs correctly
- Extend the Suit enums with the corresponding unicode characters
SPADES('\u2660'),CLUBS('\u2663'),DIAMONDS('\u2666'),HEARTS('\u2665'); - Extend the Face enum with numbers/names
ACE("Ace"), TWO("2"), THREE("3"), FOUR("4"), FIVE("5"), SIX("6"),SEVEN("7"), EIGHT("8"), NINE("9"), TEN("10"), JACK("Jack"), QUEEN("Queen"), KING("King"); - Modify the code to display the cards using the new data
- Test and correct the code until the program runs correctly
Lesson 7
Extra Practice: Couple
- Write a generic class Couple<S,T> that stores two values each with its own generic type
- Write a constructor without parameters and a constructor with two parameters
- Write getters and setters for each of the members
- Write a test, creating a Couple <Integer,String>
- Try to call getters and setters respecting the given types
- Try to call getters and setters that do not respect the given types
Extra practice: EmployeeDAOMapImpl
- Write an EmployeeDAOMapImpl for practice 6-2 using a Map as internal storage. Start from a copy of the EmployeeDAOMemoryImpl
- Have the factory return the EmployeeDAOMapImpl
- Test and correct until the program runs well
Lesson JUnit
practice DAO
- Add a reset() method to the EmployeeDAO from practice 6-2 that clears the employee storage
- Create a JUnit 4 testcase for the EmployeeDAO
- Right click on the class and select tools > create Tests
- The testcase is created in a dedicated test directory
- in which package does the testcase reside?
- Complete the generated testcase
- In the @BeforeClass method create the DAO object and store it in a static attribute
- In the @Before method, initialise the employee table with 3 records
- Hint: to make a Date object use Calendar cal = Calendar.getInstance();
// you can reuse the same cal object for multiple dates // set the date to januari 6th 2013
cal.set(2013, 0, 6);
Date d = cal.getTime(); - Write tests for all operations
- You may add a setter method to Employee for testing the update operation
- Right click the project and select Test (or press ALT+F6)
- Test until all tests succeed
Lesson 8
Extra practice: CSV changer
Write a unit test that replaces all blanks in a file by colons. Multiple blanks should be replaced by only one colon.30 October 2013
Flemish libraries to lend e-books
In april 2014 Flemish libraries will start a pilot project to extend their offer with e-books. The initial pilot will run for a year and the catalog wil contain 300 titles.
You will be able to read them for free in the library. For reading anywhere readers will be charged using the 345-model: maximum 3 ebooks fro maximum 4 weeks will cost €5.
The e-books will be readable using an app for Android and Apple. They will not be readable using an e-reader device, like Amazon Kindle, unless it can run Android apps. This limitation was needed to enforce the 345 lending model.
Here's a presentation for libraries that want to participate in the pilot project. Below is an infograph on ebooks ales evolution from 2011 => 2012, taken from the presentation:
25 September 2013
Java fundamentals: extra labs
Lesson 6
Extra practice: Extend Customer Info
- Modify lab 6.1 to ask the user to enter the attributes of the customer
- Use java.util.Scanner to read the attributes
- Take care: after reading an int, you also need to read the return (newline) to advance to the next line of input
Lesson 7
Practice 7.1:
Modify the exercise to:- Use a java.util.Scanner to read the time of the day from the user input.
- Allow the user to use the format hh:mm:
Extra practice: Seasons
- Create a class Meteo with a method public String getSeason(String month)
- Implement the method and let it return the meteorological season for the month
- (e.g. for december to february return winter)
- Create a class MeteoTest
- Write a main method that
- Creates a Meteo object
- Asks the user for the name of a month
- Uses the Meteo object to get the corresponding season
- Prints out the season
- Run the test program and correct errors until it succeeds
- Modify the program to make it work no matter which case the user uses when entering the month.
- Run the test program and correct errors until it succeeds
Lesson 8
Extra practice: Deck
- Create a class Deck
- Initialise a cardNames array with the value of all cards (ace, two, three..., jack, queen, king)
- Initilise a cardSuites array with the suites of all cards (hearts, spades, clubs, diamonds)
- Create a method called printSize, which
- prints the number of cardValues
- prints the number of cardSuites
- prints the number of cards
- Create a class DeckTest
- Write a main method that
- Creates a Deck object
- Calls printSize on it
- Run the test program and correct errors until it succeeds
- Write a method drawCard, which prints the name of a random card (e.g. jack of spades)
- Hint: use Math.random()
- Draw two cards from the main method
- Run the test program and correct errors until it succeeds
Lesson 9
Extra practice: Dice
- Create a class DiceStat with a method public void printStat ()
- The method should roll 2 dice 10.000 times (Hint: use Math.random()
- Print the number of times each number was rolled
- Create a class DiceTest
- Write a main method that
- Creates a DiceStat object
- Calls printStat
- Run the test program and correct errors until it succeeds
- For each result, express as a percentage, how often it is thrown
- Run the test program and correct errors until it succeeds
Extra practice: Factorials
A factorial (n!) is the product of all numbers less than or equal to n. Example:
3!= 3*2*1
Create an application, called factor that will print the factorial of the number given as an argument to the application:
$ java FactorTest 3
3! = 6
Lesson10
Extra practice: Quiz
- Create a class Quiz with keywords and definitions.You can find the keywords and definitions here.
- Create a method with signature public boolean askQuestion()
- The method asks the user to give the keyword that corresponds to a randomly chosen definition
- The method compares the answer with the keyword
- The method informs the user about the correctness of the result.
- If the answer was wrong, it shows the correct keyword
- The method returns if the respons is correct
- Create a class QuizTest
- Write a main method that
- Creates a Quiz object
- Calls askQuestion
- Run the test program and correct errors until it succeeds
- Add a method with this signature public int askQuestions(int number)
- The method asks multiple questions
- The method returns the number of correct answers
- Call the method from the main class
- Run the test program and correct errors until it succeeds
- Add a method with this signature
- The method prints out your score percentage.
- The method prints out whether you passed the certification or not.
- The method returns a boolean with the pass result.
- Call the certify method from the main class
- Run the test program and correct errors until it succeeds
-
public boolean certify (int numberOfQuestions, int passPercentage)
Extra practice: Hypothenuse
The hypotenuse is the longest side in a right angled triangle. Pythagore's theorem states that the length of the hyothenuse (h) relates to the two other sides (x and y) as:
Write a program, using that calculates the hypothenus, using java's Math class:
$ java HypothenuseTest 2 3
Hypothenuse = 3.6
Lesson 11
Extra practice: Unique object ID's
- Modify the Rectangle class to assign a unique ID to each object that is created.
- Start the ID's at 1 and increment for each new object
- Print the rectangle ID in the creation message from the constructor
- Run the test program and correct errors until it succeeds
Extra practice: Deck
- Add a Card class to the Deck project
- Add a suit and value attribute and methods to retrieve them
- Add a Constructor
- Add a method that returns the card name (e.g. queen of hearts) with signature
- Add a constructor to the Deck class that generates a Deck of 52 cards.
- Modify the drawCard method to return a Card
- After calling drawCard, print out the card name from the main method.
Extra practice: Dice constructor
- Add a constructor to the DiceStat class that accepts the number of dies, the number of sides each dice has and the number of throws.
- Make the Deck class generic to work with these variables.
- Run the test program and correct errors until it succeeds
Lesson 12
Extra practice: Rectangle class hierarchy
- Make a class Square, that is a subclass of the Rectangle class.
- Add a Constructor that takes the side as an aargument
- Draw a square from the RetcangleTest main method
- Run the test program and correct errors until it succeeds
- Make rectangle a subclass of Shape. Make a class Shape with an abstract draw method.
- In Rectangle you can also use Refactor => extract interface
- Make a Triangle class that extends Shape (In the interface, you can press ALT+ENTER to generate a class that implements the interface)
- This class is a right angled triangle, with equal width and height. Example: *
- Implement the necessary methods
- Draw a triangle from the RetcangleTest main method
- Run the test program and correct errors until it succeeds
- Make a Canvas class, with a method with signature public void draw (List shapes)
- In the draw method loop over the list
- Assign the objects from the list to a Shape variable
- Draw each Shape
- In the main method of TestRectangle, create a Canvas
- Add a number of rectangles, Squares and triangles to an Arraylist.
- Call the draw method on the canvas, and pass the arraylist to it.
- Run the test program and correct errors until it succeeds
- Make a Parallellogram class that extends Shape (you can make a copy of the Rectangle class and name it Parallellogram to start)
- This class draws a parallellogram with a slope that indents one character: ****
- Implement the necessary methods
- In the main method of TestRectangle, add some paralellograms to the ArrayList
- Run the test program and correct errors until it succeeds
**
***
****
****
****
22 September 2013
Firefox on windows 64 bit : use the 32 bit plugins
When installing the java plugin on windows 64 bit (I have windows 7), which Java plugin do I need?
64 bit seems the logical choice.
Here's what Oracle, steward of Java says at this time:
Allright, now do I have a 64 bit firefox, the page tells me how to checkJava for 64-bit browsers
Users should download 64-bit Java software, if they are running 64-bit browsers.
What can I find on this page?Verify if you are using 32-bit or 64-bit browser
Firefox
To determine whether you are running on a 64-bit version of Firefox, use either of these methods.
If you are running 64-bit Firefox, it may be indicated as 64-bit (e.g., Win64); otherwise it is a 32-bit version of Firefox.
- Check the About Firefox panel
- Type in the browser address about:support
User Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0
There's a number 64 in there, but take care: this indicates that windows is 64 bit. To really know more about your firefox you need to follow the about:buildconfig link. oracle should recommend to type that one directly. Look at the target entry:
target i686-pc-mingw32
This is a 32 bit build after all. As a matter of fact, Firefox does currrently not provides a production quality 64 bit build for Windows. On Windows, Firefox currently is a 32 bit application, hence you always take the 32 bit plugins.
2 September 2013
Excel 2010 Advanced Filtering
The official excel (advanced) filtering doc is a step by step guide for some common cases, but does not explain well how it actually works.
The common case is not what i commonly need, so I lose time and patience looking this up.
So I'd better keep a good excel advanced filtering resource around in case I ever need this again.
Remark: every time you change your filter (or sorting) criteria, you have to point the advanced filter to the filtering criteria again. The only way to avoid this is to add a macro to your spreadsheet.
Adidias NEO window dressing
My colleague Eytan pointed me to this Video on Adidas window shopping.
Adidas mounted a giant touch screen in front of the shopping window,
on which you can by goods using a tablet interface.
Looks great!

