JUnit is a unit testing framework for the Java language.

learn more… | top users | synonyms

5
votes
0answers
105 views

Percolation Model

Newbie here, presenting the code for close public scrutiny. Couple remarks regarding the context (taken from Princeton's COS 226 course): In this problem I model a percolation system using an N-by-...
0
votes
1answer
58 views

Does this unit test cover all edge cases? [closed]

I want to test a simple controller and I want to know if this unit test covers all cases: Controller: ...
8
votes
2answers
98 views

Rainfall challenge: how big are the basins?

August 2016 challenge The Rainfall Challenge Problem description is copied verbatim from the linked Code Review question: Problem Statement A group of farmers has some ...
3
votes
4answers
81 views

Unit testing for concatenating two int arrays

Using Java 1.8, I created the following implementation to concat two int arrays: ...
2
votes
1answer
70 views

Unit test code for a private median-of-three function, using reflection [closed]

A Junit test class is used to test the class LibraryCounter. Reflection was used to test the private methods. This made the code much more complicated. ...
6
votes
1answer
135 views

`Piece` class as part of implementation for the Tetris game

Here is my Piece class as part of implementation for the Tetris game. Critics of any kind and levels are very welcomed. If possible, I want my code to face the ...
2
votes
1answer
56 views

Standard Test methods for checking values in Lists, Maps etc

I needed to check the values in various Lists and Maps. In my case, the various types of Objects that needed checking were of four types: String ...
3
votes
1answer
52 views

Unit tests for custom Map wrapper

A while ago I asked for a code review of my automatically keyed map and I have recently had the time to get around to writing some unit tests for it using JUnit4. The test ensures that all of the "...
3
votes
1answer
53 views

class Taboo<T> — sort passed in List<T> according to 'rules'

I know as a matter of fact that there are many areas upon which my code could be improved. I was wondering if anyone can provide me with suggestions on how Taboo ...
4
votes
2answers
140 views

Find items that appear the same number of times in two collections

Here is a Java collection puzzle I found online. I was wondering if anyone can provide me with suggestions on how Appearance and tests can be improved. Suggestions ...
5
votes
1answer
101 views

Printing JUnit test results in file by changing and using the 'out' static variable of 'System' class

I'm building a framework for comparing files (in my own way) using JUnit. All test cases have been packaged in a JAR which is ran independently using a .bat file I ...
6
votes
2answers
111 views

Find number of plus in a 2d array

Problem CharGrid The CharGrid class encapsulates a 2-d char array with a couple operations. int countPlus() Look for a '+' pattern in the grid ...
3
votes
2answers
103 views

Determining if two Strings have common subtrings of a given length in Java

Problem: Given 2 strings, consider all the substrings within them of length len. Len will be 1 or more. Returns true if there are any such substrings which appear in both strings. Compute ...
4
votes
2answers
173 views

Unit testing Equals, hashcode and comparator - asserting contracts

After reading Joshua Blosh's Effective Java 2nd edition, I decided to implement equals, hashcode and comparable(where applicable) to every class I have been implementing. I have written a generic ...
1
vote
0answers
31 views

Testing a method which coordinates multiple objects

I have this class with one method, which uses three different objects to perform a task. ...
4
votes
2answers
92 views

DoublingQueue in Java

Inspired by this CR question, I decided to create my own queue! If you guys see anything taboo or have any improvements, please let me know. Ultimately I want it to be feature rich and bug free, with ...
11
votes
5answers
552 views

FiniteArrayQueue type with interface and unit tests

Doing some exercises on basic data structures, I learned about queues, and decided to roll my own to better understand how a basic queue can function. As the name indicates, this Queue is made from a ...
6
votes
1answer
136 views

Quadratic function solver + testing

I wrote a simple quadratic function solver with unit tests. Can anyone check if this is okay? Quadratic function class ...
5
votes
1answer
384 views

Serialization/Deserialization with Generics in Java

I've Implemented a Serialization Utility which Serializes/DeSerializes a class, along with writing JUnit Test Cases for the same. Please Review the code and Suggest me how to improve it. Particularly ...
5
votes
2answers
2k views

Unit testing private constructors and getter setters

I have a class Address, a class AddressTest and I am trying to write unit tests for its constructors and getter setters. ...
0
votes
1answer
233 views

JUnit test case to check that an exception of type javax.mail.MessagingException is not thrown

I have a method which will send a text mail using JavaMail API and I am trying to write a test case for this method which will check if an Exception of type ...
5
votes
2answers
77 views

BitSet wrapper to act as a sieve abstraction

This is a BitSet wrapper class to act as a Sieve abstraction for a prime calculator. Review for performance and Java/Java 8/Guava best practices. ...
3
votes
2answers
3k views

JUnit testing for Calculator in Java

I made a simple calculator. I would also like to write some simple unit tests for my CalculatorEngine class. I had to make some of my ...
7
votes
3answers
220 views

Understanding my permalink service tests

I started writing unit tests cases recently. For now, I created only "perfect case" where there is no error. However, the test seems to me difficult to maintain and difficult to understand. How can I ...
6
votes
1answer
132 views

Java 8 unit test for third-party data feeds

Use Case I have a service that does processing of records from multiple third-party feeds. The steps are generally identical for each feed, but each feed is populated in a different location on an ...
5
votes
3answers
266 views

Random letter test

My first test (randomUpperCaseLetter) checks if the returned random letter is an uppercase ASCII one. The second one (...
8
votes
2answers
532 views

Unit Tests for a Fraction Class

As my first Java homework, I wrote a class to handle fractions. This Fraction class implements basic operations for the fractions (addition, subtraction, ...
5
votes
4answers
1k views

Digital root recursive function

Haven't any experience writing recursive functions.(Generally tend to avoid them - not sure if that's a negative). What do you think about the following? This is also my first time using JUnit, I'd ...
4
votes
1answer
83 views

TDD and use case: cook dish with substitutions

This is code for a class that takes available ingredients and returns left over ingredients after making a dish. Cesars: 2 carrot 4 ice burg 1 chicken 1 beans Russian: 2 carrots 2 beans 2 chicken ...
2
votes
1answer
382 views

Generating HMAC

I had been working on several projects that required Header Message Authentication Codes to be generated when brokering files with 3rd parties like Netflix. Unfortunately on older systems like ...
2
votes
1answer
51 views

Tests for a POJO class ProgressableItem

I have tests for simple POJO class ProgressableItem (i.e. the one which has attributes total work and work done). I use JUnit 3 (it's from Android application). <...
1
vote
0answers
291 views

Testing with multiple input datasets and expectations

I wanted to make 3 test suites where each would run a test class with a specific input. I figured that in order to do this I could: Make an abstract test suite with all the variable parts (...
11
votes
4answers
4k views

Align Strings for Output

I wrote a class which can format input so that it is properly aligned. I'm interested in all suggestions (regarding structure, usability, style, naming, comments, etc). I'm especially wondering ...
5
votes
3answers
4k views

Unit testing a servlet in a meaningful way

I have to write a unit test for the method processRequest in the servlet below and I'm wondering if: It just shouldn't be done. The class should be rewritten / ...
4
votes
4answers
1k views

Using if else statements correctly

I have the following code, but I'm looking for a way to make the code read easier. ...
8
votes
1answer
8k views

JUnit extending abstract test class

I have been thinking quite some time and asked an StackOverflow question about extending abstract test classes, but I haven't been able to do it until now. I'll list my approach and then discuss some ...
2
votes
1answer
234 views

JUnit - Test whether object was persisted or not

I am using Hibernate 4 and Spring Framework 4. I wrote a simple test to check whether object was persisted or not. All set values in confirmationEntity are required. In this test I relly on that, ...
5
votes
1answer
93 views

JUnit Assert.assertSame

I am using JUnit, Hibernate and Spring Framework. I wrote a simple test to test whether entity was updated correctly or not. Is this correct way to test if entity was updated? Could it be done better?...
9
votes
2answers
3k views

Create better Unit test

Question: Is there anything you could do in order to improve the test? I am using Spring Framework 4, Hibernate 4, JUnit 4. All DAO unit tests inherit from TestDaoSetup class: ...
25
votes
4answers
2k views

Just a lowly counter that turned out to be surprisingly complicated

While writing this review, I saw a need for a Counter object similar to Python's. It seemed like it would be easy to write such a class, but it turned out to be ...
8
votes
3answers
3k views

Simple Hello World with unit tests

This is a simple hello world sample project used for instruction. I'm just looking for general comments on the approach and design. AdvancedHelloWorldTest.java ...
4
votes
2answers
109 views

Review of java interface for constructing brain model

I have built a partial human brain model and the following is an example of how I use all the classes. I was wondering if anyone could critique my implementation strategies because I feel like the ...
2
votes
2answers
4k views

Mocking utility class for database testing

I have these classes that have a boilerplate way of initialization. So, instead of writing it each time, I wrote a class called MockUtil.java, and I put the ...
4
votes
2answers
664 views

Printing a diamond-shaped figure

How can I optimize this code to have fewer loops and return values for unit testing? ...
3
votes
1answer
157 views

Designing a listener method and making it Testable

I have a java based server application that needs to support multiple clients. In the main class I have a method that runs in an infinite loop and waits for client connection. Following is this method:...
2
votes
2answers
5k views

Tesing a simple calculator class with JUnit/JMock

I'm playing around with JMock and trying to understand whether I understand the idea correctly. There's an interface Printer aimed to print integers somewhere. ...