Skip to main content

All Questions

Tagged with
Filter by
Sorted by
Tagged with
2 votes
1 answer
576 views

Basic Ticket booking code with Unit tests

I am going to run a session for a few other developers who are new to Junit, mocking, etc. I have designed a very simple application with classes and tests to demonstrate how to do unit testing. ...
HariHaravelan's user avatar
5 votes
2 answers
499 views

Hungarian algorithm for optimal assignment

The assignment problem is about assigning tasks to workers, where each pair (worker, task) has a cost. The Hungarian algorithm builds an optimal solution for this problem. It has two variants, ...
Anab's user avatar
  • 385
3 votes
1 answer
1k views

Testing DAO Delete User

I have several Dao classes, including a UserDao, below. The DAOs have many methods, but I'm focussing on deleteUser: ...
DozezQuest's user avatar
0 votes
2 answers
1k views

Need Feedback on JUnit test comparing two timestamps

I am writng a JUnit test case for the below methods : ...
user3254725's user avatar
3 votes
2 answers
500 views

Unit testing Roman-Arabic-Roman numeric converter

As you can see here, I wrote the methods public static int romanToArabic(String number) and ...
user avatar
5 votes
3 answers
3k views

Mars Rover technical Challenge in OOP

I am trying to practice OOP and TDD concepts, I have written this code for Mars rover challenge from marsrovertechchallenge . Can you please review my code from my GitHub repository? Or you can ...
Sara Elmenshawy's user avatar
1 vote
2 answers
71 views

Two BDD unit tests for an account repository with identical code

I am testing my repository class: interface AccountRepository{ void save(Account account); Optional<Account> findById(Long id); } And when writing ...
Sam's user avatar
  • 179
2 votes
1 answer
48 views

Testing a probabilistic prime-testing algorithm that may fail

I have implemented Pollard's Rho algorithm in Java. Due to the nature of it there is a small chance for it to fail (have not seen it happening yet). Since I do not ...
Navarro's user avatar
  • 165
3 votes
1 answer
273 views

Unit Testing for Spring Controller

This is my first attempt to do unit test for one of my controllers. ...
abiieez's user avatar
  • 133
0 votes
1 answer
1k views

Assert LinkedHashMap element in jUnit test [closed]

So I have some test, maybe the given side of that test is not so important to catch the point of my confusion. I wrote ...
shutdown -h now's user avatar
4 votes
1 answer
7k views

Unit test for class converting between DTOs and entities

Is this correctly written test? Tested class is responsible for converting from dto to entity class and i wanted to test it. Are these tests useful and well designed? I have a problem understanding ...
mmprogr's user avatar
  • 41
4 votes
3 answers
925 views

Fizz Buzz Test Driven Development

Task: Create the Fizz Buzz game using Test Driven Developoment. Print the correct word for range 1-100. The implementation: ...
Matthias Herrmann's user avatar
0 votes
1 answer
3k views

Espresso tests that check if Snackbar is displayed and if there is an internet connection

I have recently began writing tests for Android using the espresso library. Here I have three tests. The first test is to check if a snackbar appears when searching with blank text. The second is a ...
TheLearner's user avatar
4 votes
1 answer
16k views

Mock Entity or DTO for unit tests [closed]

Is this good approach, to mock some domain object, for example javax.persistence.Entity, or DTO (data transfer object)? Below is ...
Yaroslav Boichuk's user avatar
10 votes
3 answers
9k views

Table Driven Test in Java using Junit4

I was creating some solving algorithm and write test for it. this is the tests : ...
Gujarat Santana's user avatar
2 votes
1 answer
171 views

Testing the Dutch national flag task

I recently coded the Dutch national flag problem in Java and wrote some tests. The array in zero-indexed. Please take a look at how I verify that elements of the output array are in the right order. ...
Maksim Dmitriev's user avatar
3 votes
4 answers
695 views

Unit testing for concatenating two int arrays

Using Java 1.8, I created the following implementation to concat two int arrays: ...
PacificNW_Lover's user avatar
2 votes
1 answer
550 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. ...
Dlittle's user avatar
  • 55
6 votes
1 answer
1k views

Piece class as part of implementation for the Tetris game

Here is my Piece class as part of implementation for the Tetris game. If possible, I want my code to face the same level of scrutiny as actual production code. ...
Thor's user avatar
  • 607
3 votes
1 answer
4k 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 "...
Jack Wilsdon's user avatar
  • 1,641
3 votes
1 answer
158 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 ...
Thor's user avatar
  • 607
4 votes
2 answers
186 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 ...
Thor's user avatar
  • 607
7 votes
2 answers
11k 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 ...
Lucas T's user avatar
  • 185
3 votes
2 answers
17k 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 ...
DimaSan's user avatar
  • 185
7 votes
3 answers
310 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 ...
Daniela Morais's user avatar
6 votes
1 answer
210 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 ...
Pete's user avatar
  • 2,284
5 votes
3 answers
798 views

Random letter test

My first test (randomUpperCaseLetter) checks if the returned random letter is an uppercase ASCII one. The second one (...
Thom Thom Thom's user avatar
8 votes
2 answers
2k 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, ...
rmobis's user avatar
  • 181
4 votes
1 answer
127 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 If ...
tgkprog's user avatar
  • 223
12 votes
4 answers
13k 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 ...
tim's user avatar
  • 25.1k
5 votes
3 answers
14k 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 / ...
DiePartei's user avatar
  • 151
11 votes
1 answer
30k 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 ...
skiwi's user avatar
  • 10.6k
9 votes
2 answers
4k 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: ...
user avatar
30 votes
4 answers
3k 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 ...
200_success's user avatar
10 votes
3 answers
6k 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 ...
user38409's user avatar
  • 103
4 votes
2 answers
145 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 ...
letter Q's user avatar
  • 483
3 votes
2 answers
7k 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 ...
would_like_to_be_anon's user avatar
4 votes
2 answers
2k views

Printing a diamond-shaped figure

How can I optimize this code to have fewer loops and return values for unit testing? ...
Ajit's user avatar
  • 41
3 votes
1 answer
172 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:...
Syed Ali's user avatar
  • 195
2 votes
2 answers
8k 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. ...
Andrey Agibalov's user avatar