• Post Reply Bookmark Topic Watch Topic
  • New Topic

can i improve my code?  RSS feed

 
miguel lisboa
Ranch Hand
Posts: 1281
  • Mark post as helpful
  • send pies
  • 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
 
Indraneel A Das
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried using OutputStream.flush() method after writing into the outputstream?

Does that meets your expectation ?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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: 1281
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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: 1281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
in my ignorance i was programming to interfaces, like
Set myList = new HashSet();
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!