    @Test
    public void findingUserByUsername() throws Exception {

        EntityManager em = createMock(EntityManager.class);
        Query q = createMock(Query.class);
        User user = createDummyUser(username);

        expect(em.createNamedQuery("findUserByUsername"))
                .andReturn(q);
        expect(q.setParameter("username", username)).andReturn(q);
        expect(q.getSingleResult()).andReturn(user);

        replay(em, q);

        UserManagerBean bean = new UserManagerBean();
        Inject.bean(bean).with(em);
        Assert.assertEquals(user, bean.findByUsername(username));

        verify(em, q);
    }