Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6474949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:38:52+00:00 2026-05-25T06:38:52+00:00

I want to test in junit via jdepend whether my package tree is on

  • 0

I want to test in junit via jdepend whether my package tree is on a package cycle (i.e. has a direct cyclic dependency). Currently, it isn’t (see output below, and jdepend’s Eclipse plugin does not find a cycle for tree). But the assertion below, suggested in jdepend’s manual, fails:

// setup....
JavaPackage p = jdepend.getPackage("tree");
System.out.println(p.getName() + "'s efferent packages: ");
for (Object jp : p.getEfferents()) {
    System.out.println(((JavaPackage) jp).getName());            
}
assertThat(p.containsCycle(), is(false));

The output is:

tree's efferent packages: 
java.util
java.lang
java.lang.reflect
java.util.logging
java.io
org.hamcrest

The reason that the assertion fails is that containsCycle() recursively calls getEfferents(), puts the resulting packages in a list and returns true if some package is already in it. So containsCycle() checks whether there is a reachable package cycle (i.e. whether tree has an indirect cyclic dependency).

But how can I test only direct cyclic dependencies, i.e. whether tree is on a package cycle (and not, that it leads to some other package cycle, e.g. in org.hamcrest)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:38:52+00:00Added an answer on May 25, 2026 at 6:38 am

    The following solution doesn’t work in general, but as a workaround:

    Instead of checking whether tree has a direct package dependency, you do check indirect package dependency (i.e. whether tree leads to a package cycle) via p.containsCycle(), but only after the following code:

        final PackageFilter filter = new PackageFilter();
        jdepend.setFilter(filter);
        filter.addPackage("org.hamcrest");
    

    That way, the packages that tree depends upon (see output listed in the question), but that have cycles themselves, are filtered out beforehand.

    The downside is that you might have to add packages to the filter if you import new ones. And you have to do different setups for different jdepend-tests, because you do not want to use that filter to compute other metrics, such as the distance from the main sequence, D. Last but not least, if tree -> yourFilteredPackage is part of the direct cycle, it won’t get detected 🙁

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to test my class MyTypeDAO implemented with Hibernate 4.1 using JUnit 4.9.
I want to test whether a certain string is contained in a short list
I want to test whether two languages have a string in common. Both of
I'm writing a JUnit test using JUnitPerf. Here, I want to generate some entries
I want to write a Robotium/Junit test for an android app. At certain steps,
I'm writing a JUnit test and also using Mockito, and I want to call
I have a simple Action class which I want to unit test: package com.gam.action.test;
I want to run Junit test suites that contain various test classes. Of all
I want to test shut down and switch on information in junit. public void
I want to do some logging while executing my JUnit test. In JUnit 3.x

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.