Question: I have start to learning how to test properly on controller and encounter this following script.

<http://www.yearofmoo.com/2013/01/full-spectrum-testing-with-angularjs-and-karma.html>

```
it('should have a properly working VideosCtrl controller', inject(function($rootScope, $controller, $httpBackend) {
    var searchTestAtr = 'cars';
    var response = $httpBackend.expectJSONP(
      'https://gdata.youtube.com/feeds/api/videos?q=' + searchTestAtr + '&v=2&alt=json&callback=JSON_CALLBACK');
    response.respond(null);

    var $scope = $rootScope.$new();
    var ctrl = $controller('VideosCtrl', {
      $scope : $scope,
      $routeParams : {
        q : searchTestAtr
      }
    });
  }));

```

I am a bit confused... expectedJSON is in the following API page:

<https://docs.angularjs.org/api/ngMock/service/$httpBackend>

I am confused Just wondering what's testing in here, i can see the describe there but still lost... what's expected here?

Answer: 
I would implement it with a [`StringBuilder`](http://docs.oracle.com/javase/7/docs/api/java/lang/StringBuilder.html). Start with the longest line, and in a loop subtract one character until the `StringBuilder` is empty. Something like

```
StringBuilder sb = new StringBuilder("*******");
while (sb.length() > 0) {
    System.out.println(sb);
    sb.setLength(sb.length() - 1);
}

```
```
for(int c = r ; c > 0 ; c--)
    System.out.print("*");

```