As an alternative you could do some manual dependency injection by:
1) create a constructor for A that takes parameter B
2) in your test create mock B and use it when instantiating A
You may find this easier than adding new framework components (eg RoboGuice) if you only have a few classes that match your A B example.
Steve