This week's book giveaway is in the Java in General forum.
We're giving away four copies of Helidon Revealed: A Practical Guide to Oracle’s Microservices Framework and have Michael Redlich on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

can i improve my code?

 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
inside this test i compare a redirected outputStream with these strings; the problem is that outputStream keeps previous input with it, so i'd like to clear it everytime i use it again.

in order to stop that behaviour, i write:
everytime before a new assertion.

Is there a better way of doing this?

TiA
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried using OutputStream.flush() method after writing into the outputstream?

Does that meets your expectation ?
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Indraneel A Das:
Have you tried using OutputStream.flush() method after writing into the outputstream?



No, that would not help.

Miguel, that's what you need to do if you're essentially running multiple independent tests in a single test method. You should instead consider putting each assertion into its own individual TestCase, and putting any duplicated setup into the setUp() method. Having separate test cases makes it easier to see what's failing and what's not.
 
miguel lisboa
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks, Ernest

that was my first thought too, but i must test it all togheter: if first atempt is smaller prints SMALLER, if second is bigger prints BIGGER and so on... as i also keep track of number of atempts (how could i do it otherwise?).

I could do it your way, but, just for curiosity, downcasting, in my concrete case, is the only solution?
[ June 24, 2005: Message edited by: miguel lisboa ]
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a variable created in your test code, right? So why not just declare it to be of the specific type ByteArrayOutputStream, so the cast isn't needed?
 
miguel lisboa
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in my ignorance i was programming to interfaces, like
Set myList = new HashSet();
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Programming to interfaces is generally a good thing -- unless, of course, you're writing code that knowingly works with a specific implementation's extra features.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic