Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [junit]

JUnit is a unit testing framework for the Java language.

2
votes
0answers
22 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 ...
1
vote
2answers
60 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 ...
2
votes
1answer
33 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
1answer
56 views

Unit Testing for Spring Controller

This is my first attempt to do unit test for one of my controllers. ...
0
votes
1answer
89 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 ...
1
vote
1answer
114 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 ...
1
vote
0answers
173 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 ...
2
votes
1answer
264 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....
0
votes
1answer
67 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 ...
4
votes
3answers
575 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: ...
3
votes
1answer
204 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,...
4
votes
1answer
105 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, ...
1
vote
0answers
33 views

Generating a valid course object in my data provider

I have an education API and a simple data provider to get myself a basic course. How can I improve on this? I feel my approach is lackluster here regarding generating the data for the course and may ...
0
votes
1answer
1k 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 ...
1
vote
2answers
317 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, ...
2
votes
2answers
698 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 ...
4
votes
4answers
3k 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). ...
2
votes
1answer
4k 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 ...
5
votes
1answer
399 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 ...
3
votes
1answer
110 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 ...
5
votes
2answers
3k views

Table Driven Test in Java using Junit4

I was creating some solving algorithm and write test for it. this is the tests : ...
1
vote
0answers
110 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. ...
6
votes
1answer
5k 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
406 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: ...
10
votes
2answers
352 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
230 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
355 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
835 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. ...
4
votes
1answer
17k 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
1k 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
94 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
164 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
4k 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
551 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
385 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 ...
7
votes
2answers
6k 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
47 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
157 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
585 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
803 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 ...
7
votes
1answer
3k 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
11k 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
747 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
135 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
11k 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
301 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
173 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
612 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
1k 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
3k 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 ...