Questions tagged [junit]

JUnit is a unit testing framework for the Java language.

Filter by
Sorted by
Tagged with
3 votes
3 answers
135 views

IPv4 filter in Java

I have a simple class for representing IPv4-addresses via int values, and a simple IP-address filter that works like a set of IPv4-addresses. ...
coderodde's user avatar
  • 27k
2 votes
1 answer
438 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
1 vote
1 answer
99 views

Binary Search tree, leaves method [closed]

I have written a code of Binary Search tree that extends comparable and implements an interface. The code for leaves and the helper method countLeaves, makes sure that all of the test goes through ...
user17024023's user avatar
2 votes
1 answer
357 views

HashTable Implementation with JUNIT testing

I have written a hashtable that implements a set interface. With JUNIT all my test goes through, however I am unsure if they are written correctly based on what their description is. Down here I have ...
ee ss's user avatar
  • 21
5 votes
2 answers
341 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
  • 365
3 votes
1 answer
976 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
844 views

Need Feedback on JUnit test comparing two timestamps

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

Are these Unit tests OK or am I implementing an antipattern or not following best practices

I am testing a Spring boot service using JUnit 5 and Mockito. I haven't spent much time on unit testing in the past so I'm not sure if I'm accidentally implementing an anti-pattern or not following ...
user2094257's user avatar
3 votes
0 answers
167 views

Migrate customer and transaction data from CSV to MongoDB

I wrote a Java Spring Boot application with MongoDB that on every application start loads customer, account type and transaction details from CSV files to MongoDB. It has one end point that returns ...
user232946's user avatar
3 votes
2 answers
655 views

Palindrome Algorithm and JUnit 5 Tests

I have a "Palindrome" class that has some functions for verifying if certain things are Palindromes. For the verification, I have 2 different algorithms, one being recursive and the other ...
George R's user avatar
  • 221
4 votes
1 answer
692 views

Proper way to unit test MD5 Hashing of Zip Files from URL using JUnit 5?

Am using Java 1.8 and JUnit 5 to test a program which I wrote which grabs external zip files from a public url and then converts them into MD5 based hashes. This post / question serves as not only a ...
PacificNW_Lover's user avatar
3 votes
2 answers
451 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
13 votes
5 answers
2k views

Find most "academic" implementation of doubly linked list

Recently, a company has asked me to make an implementation of a doubly linked list with unity tests to test my skills. In the task description they specified that the solution should be as academic as ...
Raider's user avatar
  • 233
3 votes
0 answers
1k views

Android+Firebase testing using Mockito

I have an interactor/usecase class in my application. My application follows MVVM architecture with interactor/usecases responsible for logic (e.g. get data from api-service, store in local-database ...
CJR's user avatar
  • 151
1 vote
2 answers
70 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
47 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
239 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
1 vote
1 answer
1k views

Bowling kata solution in java

This is my first bowling kata solution in java. I would be very grateful if you say something about that. I want to learn from you to become a better programmer. I think the score method is quite ...
MAttti's user avatar
  • 35
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
2 votes
1 answer
1k views

Dropbox Java Spring Boot connector

I've created a service that connects to Dropbox and makes it possible to download and upload files, create and list folders and remove file or folder. Full code is available on GitHub: https://github....
Krzysztof Majewski's user avatar
0 votes
1 answer
393 views

Development Junit test notification

I'm in the development phase of a Test class to test send notifications : 1- SMS (send SMS using phone number ) 2- Email (send email ) 3- WebSocket (send websocket ) This is the first time I have ...
user1122's user avatar
4 votes
3 answers
904 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
3 votes
1 answer
840 views

HL7 message builder and unit tests

I had to code a project due to my final exams in April. It is an application which simulates a hospital. There are admissions, transfers and discharges of patients in this hospital. For each of those,...
Dominik Wolf's user avatar
4 votes
1 answer
191 views

Given a sorted (increasing order) array, write an algorithm to create a binary tree with minimal height

I'm trying to find the complexity of this code and some suggestions for improving the code quality. and handling the code gracefully, esp in the areas of exception handling, checking edge cases, ...
user2769790'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
1 vote
2 answers
2k views

Given a binary search tree and a level, calculate the number of nodes at that level

The problem statement is in the title. If the given tree is empty, -1 is returned. If the tree has k levels, and the given level is m, and m > k, -2 is returned. If neither of these conditions is met, ...
Maksim Dmitriev's user avatar
2 votes
2 answers
1k views

Custom Hamcrest matcher to compare maps

I am new to Java and have written a custom matcher to compare two maps because the error message from either JUnit or Hamcrest is not detailed enough. The code I ...
Hai Vu's user avatar
  • 650
4 votes
4 answers
5k views

Getting max and min values from Array

My code works; I am just seeing if there's an optimized way to write these methods or even better perhaps combine them (since majority of their contents look similar). ...
PacificNW_Lover's user avatar
4 votes
1 answer
15k 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
5 votes
1 answer
620 views

Quarantine implementation

I have an assignment to implemented a Quarantine project where I was left with the some unit tests and a skeleton of the implementation. I provided the solution below and get rejected from the ...
Arefe's user avatar
  • 217
3 votes
1 answer
150 views

Given a binary search tree determine if it's complete and if it's full

Here is the code of my binary search tree and a few unit tests. BinarySearchTree ...
Maksim Dmitriev'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
162 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
9 votes
1 answer
10k 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-...
user avatar
0 votes
1 answer
504 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: ...
Fabian Lurz's user avatar
10 votes
2 answers
438 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 ...
mdfst13's user avatar
  • 21.4k
3 votes
4 answers
661 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
547 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
5 votes
1 answer
35k 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 ...
Bilesh Ganguly's user avatar
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,651
3 votes
1 answer
153 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
183 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
5 votes
1 answer
6k 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 ...
Bilesh Ganguly's user avatar
6 votes
2 answers
887 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 ...
Thor's user avatar
  • 607
3 votes
2 answers
609 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 this ...
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
4 votes
2 answers
183 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 ...
T145's user avatar
  • 3,087