All Questions
Tagged with unit-testing java
195 questions
1
vote
2
answers
101
views
simple Text Table utility
A small utility to print data in an ascii table
TextTable
...
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. ...
0
votes
1
answer
95
views
First time writing tests (Service Layer)
Service class:
...
1
vote
1
answer
94
views
A simple Java integer integer hash set - follow-up 2
(See the previous version.)
Now I have this:
com.github.coderodde.util.IntHashSet:
...
6
votes
4
answers
1k
views
A simple Java integer hash set
(See the next version.)
The following data structure implements a hash table based set for int values:
...
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, ...
0
votes
1
answer
57
views
Faster, indexed, heuristic doubly-linked list data structure in Java: unit tests
Here I have the unit tests for the indexed doubly-linked list.
It goes like this:
...
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:
...
0
votes
1
answer
422
views
Unit tests for User class with JUnit 5
This is a follow-up question for Android app class serialization. Some problems have been mentioned in forsvarir's answer. Then, I am following JUnit 5 User Guide to redesign the test cases for ...
2
votes
1
answer
99
views
Android app class serialization
I am attempting to build an Android APP with the custom serializable class User. The public method Save is to save class ...
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 :
...
3
votes
2
answers
302
views
Replace words from a file with words from a dictionary based file
I'm working on a coding challenge that tasks me with taking a file with a dictionary, reading from it, and then replacing the matching words from the input file with what is found in the dictionary.
I ...
1
vote
1
answer
89
views
What to test on a rest API?
I created a rest controller with Spring Boot, I am trying to learn what I should write on my tests, right now I only check status codes and keys existence. I am planning to build an API to showcase at ...
1
vote
1
answer
174
views
Binary Search recursive & iterative solution
I have implemented binary search solution by using recursion and iterative approach.
I there any way to improve it?
Tests
...
4
votes
2
answers
241
views
Sanity check a simple RPG character
I'm writing an assistant for the tabletop RPG Pathfinder in Java. I intend to use the MVVM pattern using JavaFX, possibly through mvvmFX. Before I go into the V-VM phase, I have built a first ...
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 ...
-1
votes
1
answer
55
views
Possible Test Cases in Tester [closed]
I am trying to write a human-readable tester for a functioning program.
There are four methods in the class Polynomial: ...
14
votes
4
answers
3k
views
Unit testing Video Service class
I wrote my first unit testing code on a service class using Mockito. The code looks like this:
...
4
votes
4
answers
148
views
Statistics Library with Sample, SampleBuilder and Tests
Introduction
I'm working on a Statistics Library that can record observations and produce a Summary of the statistics when there's enough observations. Right now, it's at its early stages and is ...
9
votes
4
answers
4k
views
Building string with max length
I need to run a evaluation for large (1 Million) number of components and build a string with error which has comma separated error codes. As the final string is to be persisted in RDBMS TABLE.COLUMN ...
12
votes
4
answers
5k
views
Binary Search given sorted array Unit test
I have implemented Binary search code for a given sorted array, written unit test too, Please review my BST unit test code and let me know your comments for improvements.
...
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 ...
1
vote
2
answers
434
views
Unit Test BST in Java
I have written BST in Java for practice. How can I write better unit test cases. I am sure the way I have written them is not proper.
Code for BST
...
2
votes
3
answers
3k
views
Unit tests code for a Java class that that checks whether an array is sorted
I'm trying to write unit tests code for a java class. The class tests an array for sorted (either way) or not.
Here is the Unit Tests code:
...
2
votes
1
answer
822
views
A simple priority queue in Java via linked list sorted by priority keys
Now I have this very simple priority queue. add and changePriority both run in \$\mathcal{O}(n)\$ and ...
4
votes
2
answers
117
views
Ensure difference between sets
An endpoint that my application interacts with allows you to specify which fields are returned in the JSON result. My application will then map the JSON to a POJO using Jackson. Quite often I add more ...
3
votes
2
answers
893
views
Bowling Kata in Java
I am sharing my Bowling Game Score Kata made in Java, it is available for whoever wants to code review it.
I appreciate any comments.
...
3
votes
1
answer
170
views
Non-testable class wrapping Java Properties with basic logic
I have written a simple java.util.Properties wrapping class. Unfortunately, in my opinion, it isn't testable at the moment and I don't have any idea how to improve ...
1
vote
1
answer
154
views
Abstracting getter and setter method references for testing
Is the following code easy to understand? If not how should it be changed to be more understandable. The purpose of this is reducing similar code in unit tests. This avoids repeating lines for calling ...
2
votes
1
answer
812
views
Android Java Unit Testing model class
I'm trying to get familiar with unit testing. I never implement TDD previously, but I believe it's the best way to write software.
So, here I'm trying to test my ...
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 ...
4
votes
2
answers
4k
views
Calculate arithmetic expression represented by a string, in Java
I saw that interview question online and gave it a try:
Implement a function that gets a string which represents an arithmethic expression: contains only numbers or the the operators: '+', '-', '*', '/...
1
vote
1
answer
390
views
Testing a service that makes database calls, without a database
I'm working on a new service, for the past year I haven't needed to write tests from scratch. I've either been bug fixing, or adding features that require modification of tests, but not writing ...
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 ...
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.
...
4
votes
3
answers
86
views
Print the first, last, and in-between integers of a range
Given our spec from Code Golf:
Given two integers, output the two integers, and then the range between them.
The order of the range must be the same as the input.
Examples:
...
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
...
2
votes
1
answer
1k
views
Retry Class in Java
I have the following Java code used to retry a certain actions/methods
...
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 ...
6
votes
3
answers
3k
views
Reverse Polish Notation calculator with unit tests
I had an interview with a global company yesterday. They had given me a programming assignment. I shared my screen and I must have finished the task in 1.5 hours.
Task was programming Reverse Polish ...
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:
...
0
votes
1
answer
50
views
Unit Testing Android Studio
I am carrying out unit testing for my project but i am not sure i am doing it correctly. The example below calculates the difference between 2 time duration's.
...
2
votes
0
answers
348
views
Unit/Integration Tests for Maven plugin that creates Skipper packages
I am writing an extension to a maven mojo (spring-cloud-skipper-maven-plugin) and I am now writing tests that interact with a skipper server.
However, getting the ...
9
votes
2
answers
1k
views
Implementation of Viterbi algorithm along with unit tests
Introduction to the Algorithm
A system can be in N different, unobservable states, (i.e, we never know in which state the system actually is). The system also has a finite number of possible ...
3
votes
3
answers
450
views
A tiny Java library for generating Gray codes
This library is for generating Gray codes. A Gray code over \$n\$ bits is a list of \$2^n\$ different \$n\$-bit strings subject to the following constraint: two adjacent bit string differ in only one ...
1
vote
1
answer
85
views
Design of genetic algorithm which would allow TDD
I'm implementing genetic algorithm in Java and I want to learn TDD with this project.
Currently I have this code:
...
6
votes
1
answer
116
views
Benchmarking efficient inversion counting algorithms in Java
Given an array \$A = (a_1, a_2, \dots, a_n)\$, the number of inversions in \$A\$ is the number of index pairs \$i,j\$ (\$i < j\$) such that \$a_i > a_j\$. We can find the number of inversions in ...
2
votes
1
answer
1k
views
Bidirectional hash map in Java
I have this bidirectional hash map that allows not just accessing values via keys, but also accessing keys via values. You can find a figure explaining the data structure in this post: Bidirectional ...
2
votes
0
answers
676
views
A fast integer key map in Java via a van Emde Boas tree
Introduction
The following data structure is a dictionary mapping primitive int values to any value type. Basically, under the hood it is a hash table, where a ...
1
vote
1
answer
890
views
Generic trie implementation in Java
I implemented a Trie data structure in Java, to test my understanding of the concept. I tried (pun intended :) ) to follow TDD steps along the way (i.e., add first a failing test case, and implement ...