Fix Resource condition and add tests